- ago
Hello.
I'm trying to develop code that shows in WL panel the performance of different assets from a specific date.
The code that I used in WL6 so far and that has worked correctly has been:

CODE:
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; namespace WealthLab.Strategies {    public class MyStrategy0 : WealthScript    {       // Plots the percent change of the charted symbol and the benchmark symbols in a new pane       public void PlotBenchMarkPct(string[] bmSymbols, Color[] colors, DateTime fromDate)       {          int bar = Bars.ConvertDateToBar(fromDate, false);          //SetBackgroundColor(bar, Color.Black);          ChartPane cp = CreatePane(1000, false, true);          DrawLine( cp, bar, 500, bar, -500, Color.Black, WealthLab.LineStyle.Dotted, 1 );          DrawHorzLine( cp, 0, Color.Black, WealthLab.LineStyle.Dotted, 2 );          DrawLabel(cp, "Performance from " + fromDate.ToShortDateString(), Color.Navy);          int c = 0;          foreach (string sym in bmSymbols)          {                Bars bmBars = GetExternalSymbol(sym, true);                         double refPrice = bmBars.Close[bar-1];             DataSeries dsPctChange = 100 * (bmBars.Close/refPrice - 1);             dsPctChange.Description = sym;             PlotSeries(cp, dsPctChange, colors[c], WealthLab.LineStyle.Solid, 2);             c++;          }                 }       protected override void Execute()       {          HideVolume();          // Show the percent change from a list of symbols from a specified date (1/1/2006)          string[] benchMarkSymbols = {Bars.Symbol, "^STOXX50E", "EEM"/*, "SDS_D"*/};          Color[] colors = {Color.Blue, Color.Red, Color.Orange/*, Color.Green*/};          PlotBenchMarkPct(benchMarkSymbols, colors, new DateTime(2020,03,23));       }    } }


The code that I am trying to get to work on WL7 is as follows:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase {       // Plots the percent change of the charted symbol and the benchmark symbols in a new pane       public void PlotBenchMarkPct(string[] bmSymbols, Color[] colors, DateTime fromDate, BarHistory bars)       {          int bar = bars.IndexOf(fromDate);          int c = 0;          foreach (string sym in bmSymbols)          {             BarHistory bmBars = GetHistory (bars, sym);             double refPrice = bmBars.Close[bar -1];             TimeSeries dsPctChange = 100 * (bmBars.Close /refPrice - 1);             dsPctChange.Description = sym;             PlotTimeSeries(dsPctChange, "% Change", "cp", colors[c], PlotStyles.Line);             DrawHorzLine(0, Color.Gray, 1, LineStyles.Solid, "cp");             c++;          }                 } public override void Execute(BarHistory bars, int idx) {          // Show the percent change from a list of symbols from a specified date          string[] benchMarkSymbols = { bars.Symbol, "^GSPC", "EEM"};          Color[] colors = { Color.Blue, Color.Red, Color.Orange};          PlotBenchMarkPct(benchMarkSymbols, colors, new DateTime(2020, 03, 23));              }    } }

I have two questions:
1.- In line 15, of the WL7 code "bars.IndexOf (fromDate);" it would be the equivalent of "Bars.ConvertDateToBar (fromDate, false);" of WL6?
If not, any suggestions?
2.- What is the reason for the error on line 36? Shouldn't it work the same as the WL6?

Thanks in advance
0
1,134
2 Replies

Reply

Bookmark

Sort
- ago
#1
QUOTE:
1.- In line 15, of the WL7 code "bars.IndexOf (fromDate);" it would be the equivalent of "Bars.ConvertDateToBar (fromDate, false);" of WL6?

As per the updated QuickRef, bars.IndexOf is the equivalent of DateTimeToBar.
1
- ago
#2
Thanks for your help and patience.
In quickref it also shows that Indexof is the equivalence for ConertDateToBar



Can you help me, What is the reason for the error on line 36? Shouldn't it work the same as the WL6?
0

Reply

Bookmark

Sort