In order to minimize this OCO-Orders Risk (see https://www.multicharts.com/trading-sof ... rders_Risk) I'm testing some codes - without
success up to now.
Situation: 1 Symbol, 1 Chart, Tick-based, SA-Mode.
Code: Select all
auto = getappinfo(aiStrategyAuto);
if auto = 1 then begin
MisQty = MarketPosition_at_Broker - MarketPosition_at_Broker_for_The_Strategy;
StrAlarm = "";
if (MisQty <> 0) and (MisQty <> PrevMisQty) then begin
if MisQty < 0 then begin
StrAlarm = "--> Unwished Short-Positionen=";
PlaceMarketOrder(true, true, AbsValue(MisQty));
end else begin
StrAlarm = "--> Unwished Long-Positionen=";
PlaceMarketOrder(false, true, AbsValue(MisQty));
end;
Print(StrDateTime + StrAlarm + NumToStr(MisQty,0) + " Broker=" + NumToStr(MarketPosition_at_Broker,0)
+ " Strategy=" + NumToStr(MarketPosition_at_Broker_for_The_Strategy,0)
+ " MP*Contracts=" + NumToStr(marketposition * currentcontracts,0));
Alert(StrDateTime + StrAlarm);
end;
PrevMisQty = MisQty;
end;
orders correctly. However: when the strategy is closing a position, the value of "MarketPosition_at_Broker"
is changing earlier as the value of "MarketPosition_at_Broker_for_The_Strategy" - and the
above code will be triggered wrongly.
How can I make it work? Thanks in advance.
Regards,
Fredi