Download MetaTrader 5

How Do I SendOrder 1 for Buy Stop with Limit 1 Tick above High and Stop Loss 1 Tick Below Low

To add comments, please log in or register
How to use MQL5.community messages editor? Find out in the article!
jsanders
39
jsanders 2014.06.06 16:54 

How do I issue the SendOrder command for a Buy Stop with the Limit set 1 tick above the High and the Stop Loss set 1 tick below the Low? I tried the following:

res=OrderSend(Symbol(),OP_BUYSTOP,.5,High[1]+MathPow(10,-Digits()),0,Low[1]-MathPow(10,-Digits()),0,"",MAGICMA,0,Blue);

check=GetLastError();

if(check!=ERR_NO_ERROR) Print("Message not sent. Error: ", ErrorDescription(check)); 

 

I get the error: invalid stops. 

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.06.07 01:56  
res=OrderSend(Symbol(),OP_BUYSTOP,.5,High[1]+MathPow(10,-Digits()),0,Low[1]-MathPow(10,-Digits()),0,"",MAGICMA,0,Blue);
Invalid stops means the price for the command is too near the actual price.
whroeder1
14519
whroeder1 2014.06.07 16:50  
And MathPow(10,-Digits) == _Point == Point() and point is not a tick on metals. MarketInfo(pair, MODE_TICKSIZE)
Drazen Penic
2544
Drazen Penic 2014.06.07 18:17  

You have to find minimum stop level set by your broker for current instrument.

It's minimum number of points your S/L and T/P must be from order price.

Use this:

 

double stopLevel = MarketInfo(Symbol(), MODE_STOPLEVEL);  // Stop level in points
res=OrderSend(Symbol(),OP_BUYSTOP,.5,High[1]+stopLevel*Point(),0,Low[1]-stopLevel*Point(),0,"",MAGICMA,0,Blue); 

 

If you have fast market movement, you still need to check if order is opened, because price can change in time your order is sent to the broker.

See this for other marketinfoconstants information you can get about trading conditions.

jsanders
39
jsanders 2014.06.09 12:49  
Thank you all for the feedback!
To add comments, please log in or register