i came up with this code but it dosent seem to work
the logic:
buy on the first 1 minute bar
then check if 59 bars have passed (BarsSinceEntry) if yes then exit on the 59th 1 minute bar. thus we have entered at open of the 1 hour bar (not exactly at the open but close ) and exited at close as 59 minutes is a hour.
theoreticaly when i run this code on the 1 hour candle it should show a buy close to Open and exit close to Close
but its not working
how do i fix it
here is the code
protected override void Initialize() { CalculateOnBarClose = true; // primary bar is 60 minute Add(PeriodType.Minute,1 ); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if ( BarsInProgress == 1 && Position.MarketPosition == MarketPosition.Flat ) { EnterLong(1,100,"buy"); } if (BarsSinceEntry(1,"buy",0)== 59) { ExitLong(); } }
Comment