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?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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:
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! :)