Take Profit and Stop Loss not always working as expected

To add comments, please log in or register
joaomvr
7
joaomvr  

Hello Everyone,

I have recently started using MQL5 and I am testing my first algorithm. It is supposed to send a buy limit order to buy a stock at price p_latest and sell it at price (p_latest - stop_loss) or (p_latest + take_profit). My stoploss is 5 points and my takeprofit is 1 points.

However, sometimes it takes profit with 0 or negative profit and stop due to loss with -4 points or -6 points, compared to the initial price, as illustrated in the figure below.


The code is shown below:

MqlTradeRequest mrequest;  // To be used for sending our trade requests
mrequest.price = NormalizeDouble(latest_price.bid ,_Digits);          // Price to buy the order
mrequest.sl = NormalizeDouble(latest_price.bid - StopLoss*_Point,_Digits); // Stop Loss
mrequest.tp = NormalizeDouble(latest_price.bid + TakeProfit*_Point,_Digits); // Take Profit

I know spread can be a issue, but I just want to ignore its existence and work only with the bid price, so my profits will always be 1 points and losses 5 points, is that possible?

Thanks in advance! :)

To add comments, please log in or register