In my strategy I used stoploss in price when I open position. And after that I use the supertrend indicator to be used as a trailing stop. In the supertrend indicator there is a direction value that indicate that the supertrend indicator going uptrend or downtrend. ince supertrend indicator can be the same value as the previous bar the result of the OrderModify can be an error 1. I want to use if(OrderStopLoss == trailingStop) then skip doing order modify, how can I achieve that since break statement only works in loop?
This is my code for the trailing stoploss for buy position if needed:
if(OrderSelect(orderId,SELECT_BY_TICKET)) { if(OrderSymbol() == Symbol() && OrderType()==OP_BUY) { if( OrderStopLoss() < SupertrendUpTrend() && SupertrendDirection() == 1.0000 && (NormalizeDouble(SupertrendUpTrend(),MarketInfo(OrderSymbol(),Digits))!= NormalizeDouble(MarketInfo(OrderSymbol(),Digits))) ) //1 for uptrend and -1 for downtrend { double trailingStop = NormalizeDouble(SupertrendUpTrend(),MarketInfo(OrderSymbol(),Digits)) bool resSL = OrderModify(orderId,OrderOpenPrice(),trailingStop,OrderTakeProfit(),0); if(!resSL) { Print("Error in Order Modify. Error code=",GetLastError()); return; } else Print("Order modify successfully for ticket: ", OrderTicket()); } } }
if(OrderStopLoss() < SupertrendUpTrend() && SupertrendDirection() == 1.0000)
doesn't this part of the code already checking the value of the old vs the new SL?
I do also put OrderStopLoss() != SupertrendUpTrend() this syntax but it gives me the same error
return error - Normalize Double - wrong parameter count and 1 warning about data loss due to conversion. And I don't think your code has any to do with the problem I've dealt with, your code just changing everything to NormalizeDouble.
return error - Normalize Double - wrong parameter count and 1 warning about data loss due to conversion. And I don't think your code has any to do with the problem I've dealt with, your code just changing everything to NormalizeDouble.
Can you upload the image in the expert tab? The error in your code is due to the fact that the old Sl and the New SL are the same value.
MarketInfo (OrderSymbol (), Digits) change to int (MarketInfo (OrderSymbol (), Digits))
doesn't this part of the code already checking the value of the old vs the new SL?
I do also put OrderStopLoss() != SupertrendUpTrend() this syntax but it gives me the same error
A simple check is
if(SupertrendUpTrend()-OrderStopLoss()>Point*0.5)
You can use point in this case as the symbol is the chart symbol. Otherwise you would need to get the point value for the symbol.
Can you upload the image in the expert tab? The error in your code is due to the fact that the old Sl and the New SL are the same value.
MarketInfo (OrderSymbol (), Digits) change to int (MarketInfo (OrderSymbol (), Digits))
I'm aware about error 1, the problem is that I don't know how to fix this. This code OrderStopLoss() < SupertrendUpTrend() should make sure OrderStopLoss() doesn't have the same value with SupertrendUpTrend() but it turns out doesn't works.
expert tab? is it the error tab in meta trader? if so this is the SS
A simple check is
You can use point in this case as the symbol is the chart symbol. Otherwise you would need to get the point value for the symbol.
already adding the condition but still error occurred.
I'm trying to change the stoploss value when opening a position from SupertrendUpTrend() to Bid-(ATR*2.5) and the result is OrderStopLoss() never change position even though the SupertrendUpTrend value is different from OrderStopLoss().
already adding the condition but still error occurred.
I'm trying to change the stoploss value when opening a position from SupertrendUpTrend() to Bid-(ATR*2.5) and the result is OrderStopLoss() never change position even though the SupertrendUpTrend value is different from OrderStopLoss().
if(OrderSelect(orderId,SELECT_BY_TICKET)) { if(OrderSymbol() == Symbol() && OrderType()==OP_BUY) { if( OrderStopLoss() < SupertrendUpTrend() && SupertrendDirection() == 1.0000 && (NormalizeDouble(SupertrendUpTrend(),MarketInfo(OrderSymbol(),Digits))!= NormalizeDouble(OrderStopLoss(),MarketInfo(OrderSymbol(),Digits))) ) //1 for uptrend and -1 for downtrend { double trailingStop = NormalizeDouble(SupertrendUpTrend(),MarketInfo(OrderSymbol(),Digits)) bool resSL = OrderModify(orderId,OrderOpenPrice(),trailingStop,OrderTakeProfit(),0); if(!resSL) { Print("Error in Order Modify. Error code=",GetLastError()); return; } else Print("Order modify successfully for ticket: ", OrderTicket()); } } }
the result is the same, error code 1 is still
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In my strategy I used stoploss in price when I open position. And after that I use the supertrend indicator to be used as a trailing stop. In the supertrend indicator there is a direction value that indicate that the supertrend indicator going uptrend or downtrend. ince supertrend indicator can be the same value as the previous bar the result of the OrderModify can be an error 1. I want to use if(OrderStopLoss == trailingStop) then skip doing order modify, how can I achieve that since break statement only works in loop?
This is my code for the trailing stoploss for buy position if needed: