With the optimize order flow setting turned on, both buy and sell stops are not submitted (only the buy order). With optimize order flow turned off, both buy and sell orders are submitted, but only once per bar.
Data
MultiCharts Version 8.5 Release (Build 6743)
MB Trading demo account
No errors in Order and Position Tracker log
60-minute chart
These settings:
Code example
Code: Select all
[IntrabarOrderGeneration = True];
Inputs:
TickOffSet(20),
PosSize(1000);
Variables:
IntraBarPersist TradeEntryTime(0),
IntraBarPersist TradeExitTime(0),
IntraBarPersist PrevMP(0),
IntraBarPersist CalcPrices(True),
IntraBarPersist LongStopPrice(0),
IntraBarPersist ShortStopPrice(0),
OneMinute(ELTimeToDateTime(1)),
TwoMinutes(ELTimeToDateTime(2)),
currentDT(0);
if (GetAppInfo(aiStrategyAuto) = 0) or (LastBarOnChart_s = False) then
#return;
currentDT = ComputerDateTime;
// Submit orders for opening a position
if (MarketPosition(0) = 0) and (currentDT < TradeExitTime + TwoMinutes) then begin
// Calculate order prices
if (CalcPrices = True) then begin
LongStopPrice = Close + (TickOffSet * (MinMove / PriceScale));
ShortStopPrice = Close - (TickOffSet * (MinMove / PriceScale));
CalcPrices = False;
end;
Buy ("EL STP") PosSize contracts next bar at LongStopPrice stop;
SellShort ("ES STP") PosSize contracts next bar at ShortStopPrice stop;
end;
// Open market positions
if (MarketPosition(0) <> 0) then begin
// Time stop
if (currentDT > TradeEntryTime + OneMinute) then begin
Sell ("XL Time") all contracts next bar at market;
BuyToCover ("XS Time") all contracts next bar at market;
end;
end;
// Workaround for trade entry time
if (GetAppInfo(aiStrategyAuto) = 1) and (MarketPosition(0) = 0) then
TradeEntryTime = ComputerDateTime;
// Reset variables
if (PrevMP <> MarketPosition(0)) or (currentDT > TradeExitTime + TwoMinutes) then begin
LongStopPrice = 0;
ShortStopPrice = 0;
CalcPrices = True;
TradeExitTime = currentDT;
end;
PrevMP = MarketPosition(0);
With the setting turned on, the following happens:
In other words, only the long stop orders are submitted. If a position is opened, the long time stop is triggered after the time interval, closing the position. Subsequently a new buy stop is submitted. Short sell stop are never submitted.
With optimize order flow turned OFF
With the option turned off, the following happens:
Here both orders are submitted, like the code says it should, but after a position is closed here with the time stop, new buy and sell stops are not submitted.
Summary
Optimize order flow turned on: only long orders are submitted, multiple times per bar as the code specifies.
Optimize order flow turned off: both long and short orders are submitted (as the code specifies), but only once.
Conclusion: In both cases, optimize order flow on or off, the code is not followed as programmed.
What am I doing wrong? Or, in other words, what is happening here?
******************************
Edit: Testing with the LMAX demo shows similar behaviour:
* Optimize order flow turned ON: only buy stops are submitted (and resubmitted intra-bar),
* Optimize order flow turned OFF: both buy and sell stops are submitted and, in contradiction with MB Trading, are resubmitted intra-bar.
--> If the behaviour described above with MB Trading only happens with that broker, then this is not an issue for me and then, as far as I'm concerned, no further research is needed.
If someone can confirm that this behaviour (i.e., the not resubmitting of buy and sell stops intrabar) is limited to MB Trading, that would be great.