To make the strategy to work on a live bar, you should:
1) Subscribe for tick prices;
2) When a new tick comes and ExtUpdate is called, convert the period and use the converted period;
3) Add checking for multiple operations within the same bar.
Let's take a closer look at each of the steps.
1) You can subscribe for ticks using the command:
- Code: Select all
ExtSubscribe(2, nil, "t1", true, "tick");
2) In ExtUpdate(id, source, period), the period variable will be valid for ticks but not for indicators created on bars.
You can get the bar index when tick update in the following way:
- Code: Select all
barPeriod = barSource:size() - 1;
By the way, the bar collection in the midhero strategy is called "source = ExtSubscribe...". It should be renamed because ExtUpdate has own source.
3) Keep the number of the bar for which the strategy has already generated a signal. If the number of the current bar is equal to the kept number, exit the function:
- Code: Select all
if barSource:serial(barPeriods) == lastSerial then
return;
end
When the strategy makes a trade operation (e.g. open a trade), save the number of the bar:
- Code: Select all
lastSerial = barSource:serial(barPeriods)
I hope this helps.