Iam quite desperate. For days, I created like four completely different versions for managing one simple order and it just not even remotely works correctly

Strategy selects some closed candle by some conditions. So far so good.
Now we calculate Ticks and set LimitBuy, StopLoss and ProfitTarget. Still good.
Order_Long_Limit_A1 = EnterLongLimit(0, true, 1, Ticks_Long_Limit_A1, "Buy_A1");
Order_Long_Stop_A1 = ExitLongStop (0, true, 1, Ticks_Long_Stop_A1, "Stop_A1", "Buy_A1");
Order_Long_Target_A1 = ExitLongLimit(0, true, 1, Ticks_Long_Target_A1, "Target_A1", "Buy_A1");
Now I want to be able to monitor the LimitBuy order:
If it reaches TargetProfit or StopLoss BEFORE it gets filled, I want to cancel/kill/destroy everything and start over. Not working at all.
// REACHED TARGET OR STOP BEFORE FILLED LIMIT BUY
if ( Order_Long_Limit_A1 != null && Order_Long_Stop_A1 != null && Order_Long_Target_A1 != null && Order_Long_Target_A1.OrderState != OrderState.Filled && Order_Long_Stop_A1.OrderState != OrderState.Filled)
{
// HIGH of current bar is higher than TARGET PROFIT
if ( High[0] >= Ticks_Long_Target_A1 )
{
Reset_Long_A1();
}
// LOW of current bar is lower than STOP LOSS
else if ( Low[0] <= Ticks_Long_Stop_A1 )
{
Reset_Long_A1();
}
}
if (CurrentBar >= (Order_Bar_Number + 10) && Order_Long_Limit_A1 != null)
So lets recap:
1) I need to submit Limit Buy, StopLoss and Target profit.
2) I need it to cancel itself when not filled and reached either Stop or Target and clean everything else remaining, that can mess with new order.
3) I need it to actually work correctly on StopLoss and target, when order IS filled.
4) there is more buggy behaviourin the attached picture, I need to correct.
So please, please, please is there some SIMPLE way to manage the order?? I couldnt get it work in 650 lines of code... I read the help from top to bottom and back again. Really not helped much :-/ I appreciate every hint of help. Code is attached as well.


Any ideas? Looking forward to your reply
Comment