What would happen with IOG enabled with following code:
Code: Select all
if Close > Averge(Close, 200) then begin
Buy("LE") this bar at close;
end;
wouldn't it be also executed as soon as the condition = true without waiting that the daily bar is closed?
That's correct, that code will be executed as soon as the condition is true without waiting for the bar to close.
By the way, if your strategy settings allow it, this code..
Code: Select all
if Close > Averge(Close, 200) then begin
Buy("LE") this bar at close;
end;
.. can buy additional stocks/contracts each time the condition is true. If you only want to enter a position once, you can use the following code:
Code: Select all
// Only open a position when flat
if (MarketPosition = 0) then begin
if Close > Average(Close, 200) then begin
Buy("LE") this bar at close;
end;
end;
Do I need the RecalcLastBarAfter in the script to get the IOG condition checked in realtime?
Yes, that's because IOG does allow intra-bar order generation, but only when the script actually calculates intra-bar. So when there's no new tick coming in, the script will not calculate again with IOG, and so the condition won't be checked.
You can structure the code as follows to always have it calculate at least once per second:
Code: Select all
if (Close > Average(Close, 200)) and (MarketPosition = 0) then begin
if useTimeEntryClosePosition and (currenttime_s >= timeClosePosition) then begin
Buy("LE " + NumToStr(timeClosePosition, 0)) next bar at market;
end
else begin
Buy("LE") this bar at close;
end;
end;
RecalcLastBarAfter(1);