Ea open order tp and sl correct price issue

 
Hi everyone,

I'm programming an expert advisor for mt4 but when i run it on icmarket or any broker and the bot start opening a trade, it is not setting up the right price for the tp and sl. For exemple, imagine it opened a buy order at the price 1900 and i fix the tp at 30. It will set up randomly like for example sometimes at 1910 or sometimes at 1945 but almost never at the good price. I'm aware that slippage and spread can be the cause but i'm using it on a raw spread account (0 pips on icmarket) and slippage can't be this high ! Knowing that i defined in the ordersend function slippage =1 and if condition maxspread=1. So why does the tp and sl are not the correct one when opening an order ? But in backtest there is no problem, tp and sl are always the same when trade is opened.

The part of the code is the following one :

[...]

int maxspread = 1;

double Ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK); 

double Bid = SymbolInfoDouble(Symbol(), SYMBOL_BID);

double Spread=Ask-Bid;

if(Spread<=maxspread){

double LotSize = 1.0*Point(); 

int Slippage = 1;

int TakeProfit = 30; 

int StopLoss = 12; 


OrderSend(_Symbol, OP_BUY, LotSize, Ask, Slippage, Bid - StopLoss * Point(), Ask + TakeProfit * Point(), "My order", MagicNumber, 0, Green); 

}

[...]


It is the first time for me to post on the forum so please be indulgent with me if anything is wrong. Thank you very much if anyone can help me.

 
Good morning
You should go post on the English part of the site and post your code (ALT+S)
 
Gerard Willia G J B M Dinh Sy #:
Good morning
You should go post on the English part of the site and post your code (ALT+S)
Ok, thank you my friend
Raison: