ok, here is the function in my EA that calls the above ModifySL() function and passes the newSL variable to it.
int GetOpenSignal()
{
int precision = MarketInfo(Symbol(),MODE_DIGITS);
//---- check for long signal
if(newLow>pastLow+diff*Point){
GoLongNow = True;
GoShortNow = False;
longEntry = NormalizeDouble(High[1]+(Filter+Spread)*Point, precision); // this line of code calculates entry price for a long signal. if at the same time a short position is present, the long entry price also becomes the
new stoploss for the short entry.
}
//---- check for short signal
if(newHigh<pastHigh-diff*Point){
GoLongNow = False;
GoShortNow = True;
shortEntry = NormalizeDouble(Low[1]-Filter*Point, precision);
}
//---- long signal
if(GoLongNow==True && ForbidLong==False){the
//----
DeletePending();
//----
if(ExitNow==True) ClosePositions();
else ModifySL(longEntry); // this calls for the above ModifySL() function and passes the longEntry variable as the new stoploss for existing short positions.
//---- send signal to go long
return(OP_BUYSTOP);
}
//---- short signal
if(GoShortNow==True && ForbidShort==False){
//----
DeletePending();
//----
if(ExitNow==True) ClosePositions();
else ModifySL(shortEntry);
//---- send a signal to go short
return(OP_SELLSTOP);
}
//---- send signal to do nothing
return(-1);
}
to the best of my knowledge, I couldn't see anything wrong with this function. not to mention that it works just fine with MT4 build201. does this suggest that there may be a bug with the latest build of MT4?
oh, btw, the variables in the GetOpenSignal() function that are not locally declared are all global variables.
and also, when I do backtesting, I always use the Open Prices Only method.
For instance, OrderModify returns ERR_INVALID_STOPS if stoplevel is 5 points and newSL for long position is 1.3683 and Bid is 1.3686.
1.3686 - 1.3683 < 5 * Point.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello. I've just upgraded from MT4 build201 to MT4 build207. an EA of mine that used to work just fine with build201 has begun to give me repeated error messages: ordermodify error 130. I didn't do any modification to the EA, and the same EA when switched back to build201 worked with no error message. below is the related function that has been causing the error message. (the newSL variable is normalized).
this code is very simple and straightforward. I checked again and again but just couldn't figure out what's causing the error messages. could someone please shed some light on this?
int ModifySL(double newSL)
{
//----
int i,total,tries;
//----
total = OrdersTotal();
//----
for(i=total;i>=0;i--){
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==magic_base){
if(newSL>0.0 && (OrderStopLoss()<=0. 0 || OrderStopLoss()<newSL))
OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clr_modify);
}
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic_base){
if(newSL>0.0 && (OrderStopLoss()<=0. 0 || OrderStopLoss()>newSL))
OrderModify(OrderTicket(), OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clr_modify);
}
}
}
//----
return(0);
}