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
jsanders
39
jsanders  

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  
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
15551
whroeder1  
And MathPow(10,-Digits) == _Point == Point() and point is not a tick on metals. MarketInfo(pair, MODE_TICKSIZE)
Drazen Penic
2668
Drazen Penic  

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  
Thank you all for the feedback!
To add comments, please log in or register