How to re modify the SL while the bid change

EnrichWave

Master Trader
May 15, 2018
410
104
89
India
Hi,
while we use
CTrade c_trade;

In the c_trade.PositionModify If we set SL near 20 points to Bid price it's not changing the SL while the Bid price change fast (says invalid stop in Journal). Any solution to recheck check again and change SL to new 20 points near Bid price?. (all orders must changed to 20 points of current Bid even the Bid price changed faster)
 
Last edited:
Hi,
while we use
CTrade c_trade;

In the c_trade.PositionModify If we set SL near 20 points to Bid price it's not changing the SL while the Bid price change fast (says invalid stop in Journal). Any solution to recheck check again and change SL to new 20 points near Bid price?. (all orders must changed to 20 points of current Bid even the Bid price changed faster)
Refresh the bid price just before calling PositionModify. Like this for example:
MQL5:
Bid = SymbolInfoDouble(position_symbol, SYMBOL_BID);
 
Refresh the bid price just before calling PositionModify
Got it Enivid. Wonderful idea. I used this code.

MQL5:
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
      {
         price_bid = SymbolInfoDouble(symbol, SYMBOL_BID);
         c_trade.PositionModify(ticket,price_bid-stoploss_adj,PositionGetDouble(POSITION_TP));
         }

It modifies the SL sometimes, But unfortunately most of the time it still says Invalid stops and left the order unmodified while the price moves faster.
I would like to move the SL until no order left as unmodified.
 
Last edited:
Got it Enivid. Wonderful idea. I used this code.

MQL5:
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
      {
         price_bid = SymbolInfoDouble(symbol, SYMBOL_BID);
         c_trade.PositionModify(ticket,price_bid-stoploss_adj,PositionGetDouble(POSITION_TP));
         }

It modifies the SL sometimes, But unfortunately most of the time it still says Invalid stops and left the order unmodified while the price moves faster.
I would like to move the SL until no order left as unmodified.
First, you probably need to check your new SL distance against the Stops Level value, which could be dynamic at your broker. The SL distance should should be greater than:
MQL5:
SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL) * _Point
To make sure that all positions get modified, you could be calling the PositionModify in a cycle of N tries until it works.
 
  • ℹ️
Reactions: EnrichWave
  • ℹ️
Reactions: EnrichWave
Retries is the input parameter for the number of retries to go with for each trade. For example, if you enter 10 there, it will try to close each trade 10 times before giving up on it.
Wonderful Enivid.

is there any way that we can check how the program running step by step?. (like in c++ F5,F6,F7 I don't know exact key. it's old school learned 😛)
 
Wonderful Enivid.

is there any way that we can check how the program running step by step?. (like in c++ F5,F6,F7 I don't know exact key. it's old school learned 😛)
Yes, you can launch the Debug from MetaEditor, though I personally, don't like it.
 
  • 🎉
Reactions: EnrichWave