OrderSend error with OP_SELLSTOP and OP_BUYSTOP

 
Hi there,

I have a problem with issuing OP_SELLSTOP/OP_BUYSTOP.

I issued:
MyPrice = High[1]+(iATR(Symbol(),0,6,1)*1.5);
Ticket=OrderSend(Symbol(), OP_BUYSTOP, Lots, MyPrice,3, Low[1], 0,"BUYSTOP",0,0,Green);



MyPrice returns 1.16925750.

It gives me an error "2005.11.28 22:00:06 EURUSD,H1: invalid price 1.16925750 for OrderSend function". It is associated with error code: 4107.

So, I thought it was because of the rounding off issue. Hence, I replaced it with

MyPrice = High[1]+NormalizeDouble(((iATR(Symbol(),0,6,1), 4)*1.5);
Ticket=OrderSend(Symbol(), OP_BUYSTOP, Lots, MyPrice,3, Low[1], 0,"BUYSTOP",0,0,Green);



Now, I get "OrderSend BUYSTOP failed with error #4109"

Funnily enough, I had a period when the first code above actually worked last week. Does anyone have any idea?

Thanks.

 
try putting the NormalizeDouble on the outside, like this...
MyPrice = NormalizeDouble(High[1]+(iATR(NULL,0,6,1)*1.5),Digits);

and allow a point or 2 or 3 slippage in the ordersend function.

 
Error 4109 is ERR_TRADE_NOT_ALLOWED.
Use something like this,
   if(IsTradeAllowed()){
   	double MyPrice = NormalizeDouble(High[1]+(iATR(NULL,0,6,1)*1.5),Digits);
   	int Ticket=OrderSend(Symbol(), OP_BUYSTOP, Lots, MyPrice, 3, Low[1], 0,"BUYSTOP",0,0,Green);
   	}
 
Thanks GT,

Actually the NormalizeDouble was already on the outside, just like how you described it. I made a mistake in pasting it in. Otherwise, I would have gotten a syntax error anyway during compilation.

Why did I get a 4109 (Trade not allowed) error? I did this during an open market session. I did try it on the weekend when the market was closed, and I did get different error from the server. 4109 is a MQL4 run time error, and not a server error. I get the same error when I hard code everything:

OrderSend(Symbol(), OP_BUYSTOP, 1, 1.1900, 3, Low[1], 0,"BUYSTOP",0,0,Green);

Does anyone know how we are meant to use OP_BUYSTOP/OP_SELLSTOP in an OrderSend properly? Can someone give me a working sample code? I'd like to see the parameters. and what is the real meaning of 4109?

By the way, I set the slippage = 3, and there is enough gap for the StopLoss.

Thanks in advance.
 
search the forums for "Trade not allowed" and related terms.

The MT4 client only allows one thread at a time to communicate with the server. So if you have 2 ea's going at once and they both trigger orders at the same instant, only one will get through. That is why you use the IsTradeAllowed(). That way if the thread isn't open for that particular script eventhough the conditions for order execution are present, the execution code wont run and it should (theoretically) just wait until the next tick. (i.e. call of the start() )
 
GT,

Can I ask a favour? Can you run the following and tell me if it works for you?

OrderSend("EURUSD", OP_BUYSTOP, 1, 1.1900, 3, Low[1], 0,"BUYSTOP",0,0,Green);

Thanks!
 
I think I've found the answer, but I'd also like to register a possible bug. I use MT4 build 186.

Slawa, can you confirm this.

1. Whenever I use OP_BUYSTOP/OP_SELLSTOP command that works on Expert Advisors, it won't work on straight script. I will always get 4109 (Trade not allowed).

2. Whenever I use OP_BUYSTOP/OP_SELLSTOP command where the price has more decimal places, I would get 4107 (Price Invalid). Is that correct? So for example, EURUSD price of "1.16925750" must be rounded off FOUR decimal places to "1.1693".

Thank you all, thank you GT!
 
Forex Trader:
Error 4109 is ERR_TRADE_NOT_ALLOWED.
Use something like this,
 thanks so much
 
Bwalya Tambule:
 thanks so much

You are in the top diggers. Answering a 12 years topic to say thanks ! You should be really happy :-)

Almost sure you are number one