I am trying to backtest a strategy using 1 min bars for signals and ticks for precise entries and exits. I have IOG and Bar Magnifier enabled with 1 tick resolution. The code is below, the chart snapshot is attached.
I am trying to enter on "next bar market" implying next tick market. It enters correctly but then it enters second time on next 1-min bar opening. Why does it enter second time and how to fix that?
Code: Select all
[IntrabarOrderGeneration = true]
//inputs:
variables: Stop1(50), Target1(50), BuyAllowed(true), BuyCondition(false);
SetStopContract;
//Entry
BuyCondition =
Time >= 1251 and Time < 1257
and BuyAllowed = true
and date = 1150123
and L <= 2045.5
;
if MarketPosition = 0 and BuyCondition then begin
Buy 1 contract next bar on market;
BuyAllowed = false;
end;
//Exit
if MarketPosition <> 0 then begin
SetStopLoss(Stop1);
SetProfitTarget(Target1);
end;
if time = 1301 then begin
BuyAllowed = true;
end;