130 invalid stop loss

 

I'm trying to create an EA that will place a pending order X pips above the ask price. For example, on the daily EURUSD chart it checks when the price moves above the bar moves above a moving average and then sends the pending order 20 pips below the MA, i.e.; Ask: 1.42211, Buy would be 1.42231. Now the issue I am have is that any time I try to have it place an order with Ask + 20 I get a 130 invalid stop loss. If I use 40 or higher it works.


If I use 20 I get results like this, notice it is only adding 2 instead of 20:

2009.07.25 01:37:20 2009.07.15 23:59 Test EA EURUSD,Daily: ASK: 1.4103 BUY: 1.4106 SL: 1.4096 TP: 1.4136


Here is an example if the code.


double XPIPS=20;


if(Open_0<MA_1 && // bar opened below MA 1
Ask>MA_1// Price has moved above MA 1
){

BUY=Ask+XPIPS*Point; // Buy price
SL=BUY-Stop*Point; // Stop Loss
TP=BUY+Take*Point; // Take Profit
int EXPIRE=CurTime()+Trade_Period*60; // Order Expiration Time
int TICKET=OrderSend(Symbol(),OP_BUYSTOP,Lots,BUY,Slip,SL,TP,"",Magic,EXPIRE,Green);

if(TICKET<0){

Print("OrderSend failed with error #",GetLastError()); // Opps, there was an error
Print("ASK: ", Ask, " BUY: ", BUY, " SL: ", SL, " TP: ",TP);
return(0);
}


}

 

jsam,

Since your stop loss is fairly close to the entry price this could be a STOPLEVEL violation (depends on your broker's STOPLEVEL setting - I've seen some that are pretty high). This is what the error is suggesting...

Try adding the following Print command to see what your STOPLEVEL is:

Print("STOPLEVEL(pips)=", MarketInfo(Symbol(), MODE_STOPLEVEL);

Another possibility is that you could have a normalization problem. Try ammending your BUY, SL, and TP lines as follows (change them all):

BUY = NormalizeDouble(Ask+XPIPS*Point, Digits); // Buy price

To see what's really going out in your OrderSend command you need to convert your doubles to strings as follows:

AskPrice = DoubleToStr(Ask, 5);
BUYPrice = DoubleToStr(Buy, 5);
SLPrice = DoubleToStr(SL, 5);
TPPrice = DoubleToStr(TP, 5);
Print("ASK: ", AskPrice, " BUY: ", BUYPrice, " SL: ", SLPrice, " TP: ",TPPrice);

Also, the entry price might not be valid since you're trying to place a pending BUY order 3 pips (3.0 pips on your fractional broker) above the Ask price. This might break the rules, depending on how your broker runs the shop. I don't know if this would be a STOPLEVEL or a FREEZELEVEL issue...?

---

That's my best guess(s) from the information you've provided.

- Tovan

 

Tovan hits the nail on head.

fwiw: I offer below what is most likely over the top, but helps me remain sane. I use them everywhere in trade order workings, especially MAXSTOPFREEZE()

All a matter of taste, of course!

(I use Alpari UK/3,5 pricing)

.

double _SPREAD() {return(NormalizeDouble(MarketInfo(Symbol(),MODE_SPREAD)*Point,Digits));} //IF MI() ret(18) THEN ret(0.0001`8)
double _STOPLEVEL() {return(NormalizeDouble(MarketInfo(Symbol(),MODE_STOPLEVEL)*Point,Digits));} //IF MI() ret(20) THEN ret(0.0002`0)
double _FREEZELEVEL() {return(NormalizeDouble(MarketInfo(Symbol(),MODE_FREEZELEVEL)*Point,Digits));} //only ever seen MI() rets(0) BUT fri's ??
double MAXSTOPFREEZE() {return(MathMax(_STOPLEVEL(),_FREEZELEVEL()));}
/*Synopsis:
Freeze distance limits the possibility to modify the requested prices of opening your pending orders,
as well as the requested stop levels for market orders that are in the freeze area.
At a calm market, brokers usually don't set freeze distance, i.e., its value = 0.
However, during the period preceding important news or at high volatility,
the broker may set a certain value of a freeze distance. */

 
tovan:

jsam,

Since your stop loss is fairly close to the entry price this could be a STOPLEVEL violation (depends on your broker's STOPLEVEL setting - I've seen some that are pretty high). This is what the error is suggesting...

Try adding the following Print command to see what your STOPLEVEL is:

Another possibility is that you could have a normalization problem. Try ammending your BUY, SL, and TP lines as follows (change them all):

To see what's really going out in your OrderSend command you need to convert your doubles to strings as follows:

Also, the entry price might not be valid since you're trying to place a pending BUY order 3 pips (3.0 pips on your fractional broker) above the Ask price. This might break the rules, depending on how your broker runs the shop. I don't know if this would be a STOPLEVEL or a FREEZELEVEL issue...?

---

That's my best guess(s) from the information you've provided.

- Tovan


When I print the stoplevel it is 40. Does that sound right? I don't understand why it would request that high of a stoplevel.


2009.07.25 12:34:48 2009.07.15 23:59 Test EA EURUSD,Daily: STOPLEVELPIPs = 40


I guess that is the stop level requirement when placing a pending order?
 
jsam:


When I print the stoplevel it is 40. Does that sound right? I don't understand why it would request that high of a stoplevel.


2009.07.25 12:34:48 2009.07.15 23:59 Test EA EURUSD,Daily: STOPLEVELPIPs = 40


I guess that is the stop level requirement when placing a pending order?


This is because your broker uses fractional pips (5 digits after the decimal point of price). So you need to multiply your stop loss/take profit by 10. (XPIPS=200)

 
jsam wrote >>

When I print the stoplevel it is 40. Does that sound right? I don't understand why it would request that high of a stoplevel.

2009.07.25 12:34:48 2009.07.15 23:59 Test EA EURUSD,Daily: STOPLEVELPIPs = 40

I guess that is the stop level requirement when placing a pending order?

That's right. As RoboFx said, 40 is really only 4 pips with a fractional broker, which is pretty close to the price. It is often different with different pairs at the same broker too so if you try a different pair make sure you compensate appropriately. I have seen STOPLEVEL set much higher on some brokers. This is one of the things I look at when choosing a broker.