My main chart is RANGE, upon which I have loaded the strategy. I added 5 MIN and 1200 TICK. I only want to execute the trade on the close of the RANGE bar.
I would like the last completed MIN bar and the last completed TICK bar to be green (higher close than open) before the RANGE bar closes--and when the RANGE bar closes higher than open (green), execute the trade.
What is happening in the code below is the trade is executing on the close of the RANGE bar regardless of the MIN and TICK bars. When I compile I have no errors but obviously something is wrong. Below is the complete code, void of any // remarks.
Can someone please point me in the right direction.
public class SampleDataSeriesC : Strategy { #region Variables private DataSeries primarySeries; private DataSeries secondarySeries; private DataSeries thirdSeries; private bool second = false; private bool third = false; #endregion protected override void Initialize() { Add(PeriodType.Minute, 5); Add(PeriodType.Tick, 1200); primarySeries = new DataSeries(this); secondarySeries = new DataSeries(this); thirdSeries = new DataSeries (this); SetStopLoss(CalculationMode.Ticks, 5); SetProfitTarget(CalculationMode.Ticks, 10); CalculateOnBarClose = true; } protected override void OnBarUpdate() { if (secondarySeries == null) {secondarySeries = new DataSeries(this);} if (thirdSeries == null) {thirdSeries = new DataSeries (this);} if (BarsInProgress == 1) { secondarySeries.Set(Close[1] - Open[1]); if (secondarySeries[1] > 0) second = true; } if (BarsInProgress ==1) { thirdSeries.Set(Close[1]- Open[1]); if (thirdSeries[1] >0) third = true; } if (Close[0] > Open[0] && second == true && third == true) EnterLong(); } #region Properties #endregion } }
Comment