I get sporadic 130s when using an MA as my stop loss value, so I want to write something that will check for all OrderModify() calls when I have a change in my take profit (or stop loss) values, like:
So, should the code below work, given that the order is properly selected, etc.? Also, can I NormalizeDouble in the subroutine and the value won't be modified when it's passed to the OrderModify? I'm fairly inexperienced with MT4 internals and don't know whether it passes parameters by reference address or value.
MQL4:
retval = OrderModify( OrderTicket(), OrderOpenPrice(), Valid_SL(MyCalcSL,OrderType()), Valid_TP(MyCalcTP,OrderType()), 0, CLR_NONE );
So, should the code below work, given that the order is properly selected, etc.? Also, can I NormalizeDouble in the subroutine and the value won't be modified when it's passed to the OrderModify? I'm fairly inexperienced with MT4 internals and don't know whether it passes parameters by reference address or value.
MQL4:
double Valid_SL( double SL, int OT ); { RefreshRates(); int StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL); if (SL < StopLevel) SL = StopLevel; if ( OT == 0 && Bid - SL < StopLevel * _Point) SL = Bid - StopLevel * _Point; else if ( OT == 1 && SL - Ask < StopLevel * _Point) SL = Ask + StopLevel * _Point; return (NormalizeDouble(SL,Digits)); } double Valid_TP( double TP, int OT ); { RefreshRates(); int StopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL); if (TP < StopLevel) TP = StopLevel; if ( OT == 0 && TakeProfit - Bid < StopLevel * _Point) TakeProfit = Bid + StopLevel * _Point; else if ( OT == 1 && Ask - TakeProfit < StopLevel * _Point) TakeProfit = Ask - StopLevel * _Point; return (NormalizeDouble(TP,Digits)); }
Last edited by a moderator: