if(sl!=0) internalSLSell=NormalizePrice(Bid+(SL*Point)); if(tp!=0) internalTPSell=NormalizePrice(Bid-(TP*Point)); ticket=OrderSend( Symbol(), // symbol orderTypeTrade, // operation lot, // volume Bid,
Your stops have StopLoss/Takeprofit Points minus spread for buys and that plus spread for sells.) Don't you want the same amount for either direction?You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
- Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP is longer.
- Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the
Ask reaches it. To trigger at a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25 - The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (Control-O) → charts → Show ask line.)
-
Why did you post your MT4 question in the
Root /
MT5 EA section
instead of the MQL4 section,
(bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon.
Hi, I have looked at your code. I will tell you my understanding, so I apologize in advance if it does not help.
The code executes the 1st trade differently to the subsequent trades. This is what the function openfirsttrade() is for.
However, in your Buy function and sell function, The code refers to sl!=0 AND tp!=0, but I cannot see in your code any defined values for tp and sl.
in the line where they are declared they are not assigned any value.
So I would recommend to assign a value to sl and tp and try run the code again.
- Your stops have StopLoss/Takeprofit Points minus spread for buys and that plus
spread for sells.) Don't you want the same amount for either direction?
You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
- Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask. Your SL is shorter by the spread and your TP is longer.
- Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the
Ask reaches it. To trigger at a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25 - The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (Control-O) → charts → Show ask line.)
- Why did you post your MT4 question in the Root / MT5
EA section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon.
Hello William Roeder
Thanks for taking the time to help me.
Can you please enlighten me a little more?
As in the example above I used Bid price to Sell and Ask price to Buy with the TP and SL. This way I thought I already added the spread because I was using the opening price as a reference for my TP, and after that i only needed to add the distance of the TP.
For me to at least guarantee that my order will have the value of TP plus spread, what is the correct way?
Thanks in advance
I used this video as a reference
Hi, I have looked at your code. I will tell you my understanding, so I apologize in advance if it does not help.
The code executes the 1st trade differently to the subsequent trades. This is what the function openfirsttrade() is for.
However, in your Buy function and sell function, The code refers to sl!=0 AND tp!=0, but I cannot see in your code any defined values for tp and sl.
in the line where they are declared they are not assigned any value.
So I would recommend to assign a value to sl and tp and try run the code again.
Hello, thanks for the help, but in the code above I put TP and SL as input for users

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I don't know if I'm handling orders in the right way. Can anyone please analyze my code and help me solve this problem?
In the following image the EA had a TP of 10 points or 1 pip, in the first order respect the values, but in the second order opened with the same entry price.
I also attached the original EA
Thank you