RightEdge Forums
Main     Home          Members     Calendar     Who's On

Welcome Guest
        



Finding Stocks with 3-Month High Volume Expand / Collapse
Message
Posted 10/10/2007 23:12:02 Post #3768
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
I have a bunch of Wealth-lab scripts which finds stocks with particular criteria and stores them in watchlists. I am trying to port them to RE. Here is one of the scripts which finds all stocks with 3-Month High Volume:

  1 var symbolCounter, counter2, bar: integer;
2 var is3MHigh : boolean;
3
4 WatchListClear( '3-M High Volume' );
5
6 EnableSynch( false );
7 counter2 := 0;
8 for symbolCounter := 0 to WatchListCount - 1 do
9 begin
10 PrintStatus('Running: ' + IntToStr(symbolCounter+1) + '/' + IntToStr(WatchListCount));
11 SetPrimarySeries( WatchListSymbol( symbolCounter ));
12 if( BarCount < 66 ) then
13 continue;
14
15 is3MHigh := true;
16 for bar := BarCount - 66 to BarCount - 2 do
17 if( @#Volume[bar] >= @#Volume[BarCount-1] ) then
18 is3MHigh := false;
19
20 if( is3MHigh ) then
21 begin
22 WatchListAddSymbol( '3-M High Volume', '', GetSymbol );
23 counter2 := counter2 + 1;
24 end;
25 end;
26 RestorePrimarySeries();
27
28 Print( 'Number of 3-M High Volume stocks = ' + IntToStr( counter2 ));
29



Can anybody help me in writing the equivalent RE script ?

How do we post code here? I tried "code" IFCode, but that didn't work. I had to use some tricks to post the above code.
Posted 10/11/2007 07:31:04 Post #3770
 

Lead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead Developer
You can iterate over all of your symbols within a system but we don't provide a way to programmatically add them to the Watchlist.  This is on tap immediately after 1.1 is released.

sarah (10/10/2007)
I have a bunch of Wealth-lab scripts which finds stocks with particular criteria and stores them in watchlists. I am trying to port them to RE. Here is one of the scripts which finds all stocks with 3-Month High Volume:

  1 var symbolCounter, counter2, bar: integer;
2 var is3MHigh : boolean;
3
4 WatchListClear( '3-M High Volume' );
5
6 EnableSynch( false );
7 counter2 := 0;
8 for symbolCounter := 0 to WatchListCount - 1 do
9 begin
10 PrintStatus('Running: ' + IntToStr(symbolCounter+1) + '/' + IntToStr(WatchListCount));
11 SetPrimarySeries( WatchListSymbol( symbolCounter ));
12 if( BarCount < 66 ) then
13 continue;
14
15 is3MHigh := true;
16 for bar := BarCount - 66 to BarCount - 2 do
17 if( @#Volume[bar] >= @#Volume[BarCount-1] ) then
18 is3MHigh := false;
19
20 if( is3MHigh ) then
21 begin
22 WatchListAddSymbol( '3-M High Volume', '', GetSymbol );
23 counter2 := counter2 + 1;
24 end;
25 end;
26 RestorePrimarySeries();
27
28 Print( 'Number of 3-M High Volume stocks = ' + IntToStr( counter2 ));
29



Can anybody help me in writing the equivalent RE script ?

How do we post code here? I tried "code" IFCode, but that didn't work. I had to use some tricks to post the above code.
Posted 10/11/2007 11:30:17 Post #3772
 

DeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloper
billb (10/11/2007)
You can iterate over all of your symbols within a system but we don't provide a way to programmatically add them to the Watchlist.  This is on tap immediately after 1.1 is released.

So basically, what you would do now is run your system with all the symbols, and then only trade on a subset of them which you selected.

Daniel

Posted 10/11/2007 16:58:02 Post #3774
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
I generally generate many watchlists on different criterias. And then take intersection of few of the watchlists to get stocks which satisfy particular set of criterias. And at the end you have a set of stocks which have been selected on a set of objective rules. For example, find all stocks which
1. were 2-year high in last 6 months,
2. were 52-week low in last 2 weeks, and
3. SMA(Volume,5) has been increasing for last 2 days

I will like to know how I can implement this kind of stuff. Now instead of creating a new watchlist (for the time being) if I put all symbols in a file, then how do I write the above script. Can anybody give some kind of code to start with (even if it is not running)? I didn't find anything similar in the samples and am not able to even start. Should I write code in NewSymbolBar() or Startup()? How do I loop over symbols ?
Posted 10/11/2007 17:28:37 Post #3775
 

DeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloper
You shouldn't do it in StartUp, because at that point you won't have any data.  You can do it in NewBar() or NewSymbolBar().  SystemData.Symbols will be a list of the symbols that the system is run for (ie the symbols that were checked in the watchlist).  You can access the bar data for symbols using the SystemData.SymbolBars or SystemData.SystemBars properties.  Each of these is a dictionary which contains a list of bars for each symbol.  The SystemBars lists are synched up so that the indices of all symbols match by inserting "empty bars."  The SymbolBars don't have any empty bars.

If you just want to run this calculation once, at the "end" of the data, then you might want to do it in the Shutdown method.  I wrote a Bar Aggregator System which you can check out to see how to do this.

Let us know if you need further guidance.

Thanks,
Daniel

Posted 10/11/2007 17:33:40 Post #3776
 

DeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloperDeveloper
Also, you do not need to loop through bars.  RE loops for you can calls NewSymbolBar for each symbol on each bar.
Posted 10/11/2007 23:57:52 Post #3778
 

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member
Great!! Now it's much more clear. This "Shutdown()" method is the savior. I wrote the following script which should work. ( I am not able to compile since I think SystemData.SybolBars will be available in a future version ).


1 using System;
2 using System.Drawing;
3 using System.Collections.Generic;
4 using RightEdge.Common;
5 using RightEdge.Indicators;
6 using System.IO;
7
8 public class SystemMain : SystemBase
9 {
10 public override void Startup()
11 {
12 // Nothing
13
14 }
15
16 public override void NewSymbolBar(Symbol symbol, BarData bar)
17 {
18 // Nothing
19 }
20
21 public override void Shutdown()
22 {
23 base.Shutdown();
24
25 int symbolCounter, counter2;
26 string filename = "C:\\Watchlists\\3-M High Volume.txt";
27
28 StreamWriter writer = new StreamWriter(filename);
29 symbolCounter = 0;
30 counter2 = 0;
31 foreach ( string symbol in Symbols )
32 {
33 //Application.PrintStatus ( String.Format ( "Running: {0}/{1}", symbolCounter+1, Symbols.Count ));
34
35 List<BarData> bars = SystemData.SymbolBars[symbol];
36
37 if ( bars.Count < 66 )
38 continue;
39
40 bool is3MHigh = true;
41 for ( int barCount = bars.Count - 66; barCount < bars.Count - 2; barCount ++ )
42 if ( bars[barCount].Volume < bars[bars.Count-1].Volume )

43 is3MHigh = false;
44
45 if ( is3MHigh )
46 {
47 writer.WriteLine ( symbol );
48 counter2 = counter2 + 1;
49 }
50 symbolCounter++;
51 }
52 writer.Close();
53 Console.WriteLine ( "Number of 3-M High Volume stocks = " + counter2 );
54 }
55 }
56
57
58



I think this script should work just fine. Let me know if there is any obvious error.

I am little bothered about the performance. If I run this script on all stocks (~7000) each symbol with 1000 bars, NewSymbolBar() will be called 7 Million times unnecessarily. Is there a way to avoid this?

Posted 10/12/2007 00:17:22 Post #3779
 

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being
FYI: The actual watch list is just an XML file so you should be able add/edit the XML file to update the RE watch list.


Posted 10/12/2007 09:26:41 Post #3784
 

Lead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead Developer
Not that I can think of.  Since you're not doing anything in this method, it shouldn't be a huge problem.  You can use BarCollections for now to get around your compiler error.

sarah (10/11/2007)
Great!! Now it's much more clear. This "Shutdown()" method is the savior. I wrote the following script which should work. ( I am not able to compile since I think SystemData.SybolBars will be available in a future version ).


1 using System;
2 using System.Drawing;
3 using System.Collections.Generic;
4 using RightEdge.Common;
5 using RightEdge.Indicators;
6 using System.IO;
7
8 public class SystemMain : SystemBase
9 {
10 public override void Startup()
11 {
12 // Nothing
13
14 }
15
16 public override void NewSymbolBar(Symbol symbol, BarData bar)
17 {
18 // Nothing
19 }
20
21 public override void Shutdown()
22 {
23 base.Shutdown();
24
25 int symbolCounter, counter2;
26 string filename = "C:\\Watchlists\\3-M High Volume.txt";
27
28 StreamWriter writer = new StreamWriter(filename);
29 symbolCounter = 0;
30 counter2 = 0;
31 foreach ( string symbol in Symbols )
32 {
33 //Application.PrintStatus ( String.Format ( "Running: {0}/{1}", symbolCounter+1, Symbols.Count ));
34
35 List<BarData> bars = SystemData.SymbolBars[symbol];
36
37 if ( bars.Count < 66 )
38 continue;
39
40 bool is3MHigh = true;
41 for ( int barCount = bars.Count - 66; barCount < bars.Count - 2; barCount ++ )
42 if ( bars[barCount].Volume < bars[bars.Count-1].Volume )

43 is3MHigh = false;
44
45 if ( is3MHigh )
46 {
47 writer.WriteLine ( symbol );
48 counter2 = counter2 + 1;
49 }
50 symbolCounter++;
51 }
52 writer.Close();
53 Console.WriteLine ( "Number of 3-M High Volume stocks = " + counter2 );
54 }
55 }
56
57
58



I think this script should work just fine. Let me know if there is any obvious error.

I am little bothered about the performance. If I run this script on all stocks (~7000) each symbol with 1000 bars, NewSymbolBar() will be called 7 Million times unnecessarily. Is there a way to avoid this?

Posted 10/12/2007 09:27:39 Post #3785
 

Lead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead DeveloperLead Developer
Clever!  Forgot about that suggestion.  Although highly not recommended or supported, will work in a pinch.

kaizen (10/12/2007)
FYI: The actual watch list is just an XML file so you should be able add/edit the XML file to update the RE watch list.
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: billb, young, dplaisted

Permissions Expand / Collapse

All times are GMT -5:00, Time now is 2:37pm

2005-2007 © RightEdge Systems