edwkelly8
 ( 0.09% )
- ago
I need to create a strategy, overview below, and not sure how to start or the steps to complete it. Please let me know how to proceed. Thanks

Overview: I need to create a custom dataset of symbols, then run (I assume) a UserStrategyBase derived strategy against each constituent of the dataset, bar by bar, then display the results against a compare symbol (bar by bar) that is not in the custom dataset. I only want to display the compare symbol's annotated result bars and not any symbol of the dataset.

Example
DataSet symbols (S):

Symbol S1 S2 S3 S4 Result
Date1 S1D1 S2D1 S3D1 S4D1 R1
Date2 S2D1 S2D2 S3D2 S4D2 R2
...

Compare symbol (C):

Symbol C
Date1 R1
Date2 R2
...
0
870
Solved
13 Replies

Reply

Bookmark

Sort
edwkelly8
 ( 0.09% )
- ago
#1
To be clear, the Compare symbol's OCHL bars are not modified, they are just annotated with data from the result calculation.
0
Cone8
 ( 5.88% )
- ago
#2
It's not clear to me. Let's start here - "create a custom dataset"
1. Is this creating a DataSet part of the strategy?
2. If so, what's the symbol source of this DataSet? and do you really mean "DataSet" or just a list of symbols?

Assuming you're actually running the script on a DataSet you've already created, you said, "display the results". Where do you want to display them?

Please elaborate what S1D1 and R1 mean.
Date1 S1D1 S2D1 S3D1 S4D1 R1
0
edwkelly8
 ( 0.09% )
- ago
#3
I actually thought I was being clear, sorry!

QUOTE:
It's not clear to me. Let's start here - "create a custom dataset"
1. Is this creating a DataSet part of the strategy?


All I meant here was to create a symbol list using your term DataSet like this named AAA


QUOTE:
Assuming you're actually running the script on a DataSet you've already created, you said, "display the results". Where do you want to display them?


I want to display the results in the Price pane.

QUOTE:
Please elaborate what S1D1 and R1 mean.
Date1 S1D1 S2D1 S3D1 S4D1 R1


S1 S2 S3 S4 stand for Symbols 1-4
S1D1 thru S4D2 stand for Symbol1Date1 thru Symbol4Date2 - two dates and four symbols
R1 and R2 are Result 1 and Result 2 - for the two Dates


For example, from WL6 this is a partial chart for AAPL


The numbers would be the Result calculation from the DataSet.
0
edwkelly8
 ( 0.09% )
- ago
#4
AAPL is a bad choice for the Compare symbol since it is in the DataSet.
0
Cone8
 ( 5.88% )
- ago
#5
I really don't know what result you're shooting for, but you can use this template of sorts to compare symbols in a DataSet to another symbol's data.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Text; using System.Collections.Generic; namespace WealthScript12 { public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars) {          //get the bar history of the symbol to compare everything to          _compareBars = GetHistory(bars, "QQQ"); } public override void PreExecute(DateTime dt, List<BarHistory> participants) {          int bar = GetCurrentIndex(_compareBars);                    foreach (BarHistory bh in participants)          {                                        int idx = GetCurrentIndex(bh);             // do some comparing on the DateTime 'dt'             if (_compareBars.Close[bar] > bh.Close[idx])             {                // do something here                WriteToDebugLog(_compareBars.Symbol + " is greater than " + bh.Symbol + " on " + dt.ToShortDateString() );             }                       } } public override void Execute(BarHistory bars, int idx) {          // leave this blank unless you want to use it for something else          }       //declare private variables below       BarHistory _compareBars;    } }
0
edwkelly8
 ( 0.09% )
- ago
#6
This is helpful, thank you.

Couple questions:
Is there any way to get the "QQQ" data only once other with every participant in Initialize?

The Chart is still rendering the first symbol it retrieved from the DataSet but I really need it to display the "QQQ" bars annotated with my calculations? How can I do accomplish that?
0
- ago
#7
QUOTE:
Is there any way to get the "QQQ" data only once other with every participant in Initialize?

The fundamental problem is that you need to align (synchronize) the DateTimes of each stock in the dataset with the DateTimes of QQQ separately. That's being done in Initialize here. I think you also need to cache each aligned version as well, and them recall it in the comparison step (not shown).

Why are we using PreExecute in the first place? The goal here is to draw an individual comparison between each stock and QQQ alone--not between the stocks themselves. I think we are trying to answer two different questions. (Or maybe I don't understand the original question. I'm confused.)
0
edwkelly8
 ( 0.09% )
- ago
#8
The computation isn't important here. If I could annotate and display QQQ bars with Cone's WriteToDebugLog above would be all that I need now. This template is helpful putting me on track. As it is now, I would only be able to annotate bars from the first symbol in the dataset, not QQQ, and this is not what i require.
0
- ago
#9
QUOTE:
I would only be able to annotate bars from the first symbol in the dataset, not QQQ, and this is not what i require.

Are we talking about annotations on the Chart itself, or just in the WriteToDebugLog?

If you want to annotate the Chart, that needs to be done one stock at a time. But you can step through the list of stocks in the dataset to see those annotations for each stock on the Chart.

You can batch all the annotations for the dataset if you're writing them to the DebugLog.
0
Cone8
 ( 5.88% )
- ago
#10
To load it just once, make it a static variable. Then in Initialize() test for null and/or choose a symbol in the DataSet to synchronize to. If you do, you should make sure you pick a symbol that covers the entire test range.

CODE:
//declare private variables below static BarHistory _compareBars; public override void Initialize(BarHistory bars) {          //get the bar history of the symbol to compare and synchronize with MSFT     if (_compareBars == null && bars.Symbol == "MSFT")             _compareBars = GetHistory(bars, "QQQ"); }


0
edwkelly8
 ( 0.09% )
- ago
#11
From #9
QUOTE:
Are we talking about annotations on the Chart itself, or just in the WriteToDebugLog?

The chart itself, but I just don't know how to be more clear. The chart I need to annotate is QQQ in this example, not any of the symbols in the DataSet on which the strategy is ran.

How do I annotate QQQ? Thanks
0
Cone8
 ( 5.88% )
- ago
#12
Then, maybe something like this. Just run on "QQQ" or the compare-to symbol. Name your DataSet in the code.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data;      /******** REQUIRED for DataSetFactory ********/ using WealthLab.Indicators; using System.Drawing; using System.Text; using System.Collections.Generic; namespace WealthScript6 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          // access the symbols in a named DataSet and sync with the current bars (e.g., QQQ)          String myDataSet = "Dow 30";              DataSet ds = DataSetFactory.FindDataSet(myDataSet);          foreach (string sym in ds.Symbols)          {             BarHistory bh = GetHistory(bars, sym, myDataSet);             if (bh != null)                _barHistories.Add(bh);          } } public override void Execute(BarHistory bars, int idx) {          // you do your compare thing here.          // Since the histories are already synched, you can use idx for both          StringBuilder sb = new StringBuilder(bars.DateTimes[idx].ToShortDateString());          sb.Append(": ");          foreach (BarHistory bh in _barHistories)          {                         if (bh.Close[idx] > bars.Close[idx])                sb.Append(bh.Symbol).Append(", ");          }          WriteToDebugLog(sb.ToString()); }       //declare private variables below       List<BarHistory> _barHistories = new List<BarHistory>(); } }
2
Best Answer
edwkelly8
 ( 0.09% )
- ago
#13
Thanks a whole lot!!
2

Reply

Bookmark

Sort