- ago
I am trying to refer to the dataseries member two intervals back. Specifically the value of Consecup [bar - 2] ?
0
808
4 Replies

Reply

Bookmark

Sort
Cone8
 ( 28.25% )
- ago
#1
Refer to this image -



idx is the bar number variable assigned by default. You can change it here if you like to bar and then use bar in the Execute method. For more hints for converting strategies, see the [current] "sticky" topic for WL 6.9 Translations.
0
- ago
#2
Thanks for the response.

I am trying to reference the ConsecUp n bars back, and want to plot it

CODE:
public override void Initialize(BarHistory bars)       {          indicator = new ConsecUp(bars.Close, 1);          Plot(indicator, Color.Black);          indicator2 = new ConsecDown(bars.Close, 1);          //Plot(indicator2, Color.Blue);          indicator3 = indicator(bars.Close[bars.Count - n], 1);          //Plot(indicator3, Color.Red);
0
- ago
#3
CODE:
TimeSeries minus2;           //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          minus2 = bars.Close >> 2;          PlotIndicator(minus2 as IndicatorBase, Color.Red); }
0
Cone8
 ( 28.25% )
- ago
#4
The Plot() methods was deprecated. You need to convert those to PlotIndicator or PlotTimeSeries (or PlotIndicatorLine / PlotTimeSeriesLine).

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript2 { 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) {          indicator = new ConsecUp(bars.Close, 1);          PlotIndicator(indicator, Color.Black, PlotStyles.Histogram);          indicator2 = new ConsecDown(bars.Close, 1);          PlotIndicator(indicator2, Color.Blue, PlotStyles.Histogram, false, "cdPane");          indicator3 = bars.Close >> 2;          PlotTimeSeriesLine(indicator3, "Close Delay (2)", "Price", Color.Red);       } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) {          //use your indicators here -->           if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } }       //declare private variables below       IndicatorBase indicator;       IndicatorBase indicator2;       TimeSeries indicator3; } }
0

Reply

Bookmark

Sort