Error stop loss

I’m having this error:

error ‘invalid stops’ when entering with 0.000 @0.86614

I think I have write the right code, but it keep telling me that I have invalid stop loss.

The code is very simple:

ticket = OrderSend(Symbol(), cmd, volume, prc, Slippage, 0,tp, cmt, MagicNumber,0,clr);

I put 0 as stop loss. Anyone can help? Thanks

It may be an error with the data type being interpreted in Metatrader.

OrderSend expects a double for stoploss, so instead of 0, try 0.0:

ticket = OrderSend(Symbol(), cmd, volume, prc, Slippage, 0.0,tp, cmt, MagicNumber,0,clr);

int OrderSend( string symbol, int cmd, double volume, double price, int slippage, double stoploss, double takeprofit, string comment=NULL, int magic=0, datetime expiration=0, color arrow_color=CLR_NONE)

can you show all the code ?

0 is fine for SL or TP values. where does the tp value come from ? What is the error code ?

Hi Guys, here’s the screenshot

current price is 0.86918
want to buy
stop loss 0.86388
take profit 0.8711

want stop loss 50 pips
and profit 20 pips

I’m entering with 0.01 lot.

@Scottish Mike
Metatrader 4 doesn’t do a good job of converting integers to doubles. Sometimes it triggers a hard to understand error and sometimes it does not. As there is no way to know when it will cause an exception, the best practice is to always explicitly use 0.0 for a double type rather than 0 which Metatrader interprets as an integer. I understand that type conversion is built into MT5.

You may be running into NFA FIFO rules. Try placing the order with no SL or TP, then use OrderModify to add a stop loss and take profit to your open order. If you need help implementing this I wrote up a sample for a buy/sell script that does this. Google “buy with place stop loss and profit target in MT4?” and you should find it at the top of the list.

Thanks FXEZ. It appear to be working.

You’re welcome goodmast3r, glad I could help!

yes, I always define it as a double in my code, but in the times I have sent through an order with 0 for both SL and TP I’ve never had a problem.