I need to make a code to backtest pairs of Entry & Exit in a specific way, and I cannot find a solution for it.
Namely:
* enter at bar close (if the price reaches P), then
* exit at P+2pts, but intrabar, at whatever tick the price reaches P+2pts
I am using two bar series of the same data, a time series of 1-minute, and a tick-by-tick one. The second is used to Enter/Exit at any tick of the bar forming, not just at the close of the bar.
While in State.Historical, the entry at the close of the bar can be achieved by setting
Calculate=Calculate.OnBarClose
and
EnterLong(1/*2nd bar series*/,quantity,name) when BarsInProgress == 0 , i.e. time series of 1-minute
Then, I switch to
Calculate=Calculate.OnEachTick
to check at every subsequent tick if price becomes P+2pts, to ExitLong(...)
The thing is, it may happen that at those ticks forming the bar, the price to reach again P and an EnterLong(...) to be triggered, before the close of the bar.
I need all EnterLong(...) to be submitted at the close of the bar only. Again, I am in State.Historical at all times.
Any suggestion will be much appreciated, thank you.
Comment