TPprice = entryprice - pips * Getpipval(); ⋮ SLprice = entryprice - pips * Getpipval();
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.
-
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
-
Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close 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.)
Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
My GBPJPY shows average spread = 26 points, average maximum spread = 134.
My EURCHF shows average spread = 18 points, average maximum spread = 106.
(your broker will be similar).
Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)
Thank you for the reply Mr William,
I tested if the problem is from the spread before posting here.
correct me if i am wrong please,
As you can see from the new Print Screen that the spread is 0.6 Pips and the SL is 28 pips as it's printed in the log but the actual SL that the EA set is 28.2 ( not 28.6).
The 0.2 difference in the print screen is from the Ask Printed in the logs which is 1.73356 and the actual price in the trade which is 1.733568.
And i tested it many times in different spread environment and i noticed even if the spread is 0, Sometimes the EA sets the SL not equal to the printed SL in the logs.
And tested it in when the spread is more than 1 Pip spread and the EA set the SL accurately as it is printed in the logs.
if the problem is from the Spread shouldn't be always wrong calculation?
Please note that the SL is not always not accurate that what's making me confused.
Any help will be very appreciated thanks in advance.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
please can someone help me to find the solution for the problem,
as you can see in the Print screen that the EA SL and TP targets are different than the Values printed in the logs (which is circled in Red and Green).
then i noticed that there is difference in the price that the EA took in the actual trade which was 1.72894 and the ASK Price printed in the log 1.72895 (which is circled with Yellow)
i tested it many times always the difference between SL and TP targets is equal to the difference between the actual price in the trade and the ASK or BID Price printed in the logs.
Please note that the this differences not happing always.
This is the code and Thanks in advance,