Hello,
Normally, Stop Loss execute in broker server and it send a data of Stop Loss value to broker. This has a disadvantage of too many operation and also Stop Hunting from most of the Forex brokers. To avoid this, i heard there is a concept called Virtual Stop loss which act same as normal but it does not send value to Broker server instead it keep in the values in Local meta trader.
Classic Trailing Stop Loss code :
I have no idea how should i code or convert this to Virtual Trailing Stop Loss. Can someone provide me a idea or sample code how to convert this code which work same as this code except modifying real stop loss value.
Normally, Stop Loss execute in broker server and it send a data of Stop Loss value to broker. This has a disadvantage of too many operation and also Stop Hunting from most of the Forex brokers. To avoid this, i heard there is a concept called Virtual Stop loss which act same as normal but it does not send value to Broker server instead it keep in the values in Local meta trader.
Classic Trailing Stop Loss code :
MQL4:
void TrailingStopLoss(int TrailingStopLoss_magic) { // Loop through all open orders for(int i = OrdersTotal() - 1; i >= 0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { double TrailingStopLoss_entryPrice = OrderOpenPrice(); // Check if the order is a buy order with magic number 1 if(OrderSymbol() == Symbol() && OrderMagicNumber() == TrailingStopLoss_magic && OrderType() == OP_BUY) { if(Bid - (TrailingStopLoss_entryPrice + Trailing_TP * gPips) > gPips * Trailing_Gap) { if(OrderStopLoss() < Bid - gPips * Trailing_Gap || OrderStopLoss() == 0) { ResetLastError(); RefreshRates(); gOrderModifyCheck = OrderModify(OrderTicket(), OrderOpenPrice(), Bid - gPips * Trailing_Gap, OrderTakeProfit(), 0, clrBlue); if((_LastError != ERR_NO_ERROR && _LastError != ERR_NO_MQLERROR) || !gOrderModifyCheck) Print(__FUNCTION__ + " => Buy Order Error Code : " + GetLastError()); } } } // Check if the order is a sell order with magic number 2 if(OrderSymbol() == Symbol() && OrderMagicNumber() == TrailingStopLoss_magic && OrderType() == OP_SELL) { if((TrailingStopLoss_entryPrice - Trailing_TP * gPips) - Ask > gPips * Trailing_Gap) { if(OrderStopLoss() > Ask + gPips * Trailing_Gap || OrderStopLoss() == 0) { ResetLastError(); RefreshRates(); gOrderModifyCheck = OrderModify(OrderTicket(), OrderOpenPrice(), Ask + gPips * Trailing_Gap, OrderTakeProfit(), 0, clrPink); if((_LastError != ERR_NO_ERROR && _LastError != ERR_NO_MQLERROR) || !gOrderModifyCheck) Print(__FUNCTION__ + " => Sell Order Error Code : " + GetLastError()); } } } } } }
I have no idea how should i code or convert this to Virtual Trailing Stop Loss. Can someone provide me a idea or sample code how to convert this code which work same as this code except modifying real stop loss value.