-
int ticket = OrderSend(symbol, OP_SELL, risk, price, maxSlippagePercent, stopLoss, takeProfit);
Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. The moderators will likely move this thread there soon. -
double price = Bid; double takeProfit = NormalizeDouble(price * (1 - 0.8 * 0.01), decimals); double stopLoss = NormalizeDouble(price * (1 + 0.02 * 0.01), decimals);
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)
-
- nameless nameless: All the calculations are correct and exactly the same when it goes through and also when it throws an error which makes no sense. Whats going on??
Stop guessing and find out.
Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
Code debugging - Developing programs - MetaEditor Help
Error Handling and Logging in MQL5 - MQL5 Articles (2015)
Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)
I already tried placing the stop losses and take profits off of the ask for short and bid for long. I'm not guessing I've been debugging for hours, I have a good amount of programming experience but this is my first time working the mql4 so I wanted to see if anyone else would know how to fix this issue while I continue to debug.
![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
I'm trading BTCUSDT which has a minimum stop loss of 50 pips. My stop loss is roughly $5 away (0.02%) for every trade. Only about 10% of the trades actually go through, and every time it throws an error I print the price, SL and TP. All the calculations are correct and exactly the same when it goes through and also when it throws an error which makes no sense. Whats going on??
Here is the snippet of code where I calculate everything:
And here are the calculations from when it throws an error (going short) (I've also attached a screenshot):
Price: 27915
Take Profit: 27691.68
Stop Loss: 27920.58