https://docs.mql4.com/trading/ordersend
StopLoss and TakeProfit levels cannot be too close to the market. The minimal distance of stop levels in points can be obtained using the MarketInfo() function with MODE_STOPLEVEL parameter. In the case of erroneous or unnormalized stop levels, the error 130 (ERR_INVALID_STOPS) will be generated.
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Error 130 on MT4, has been EXTENSIVELY discussed on the forum, so please search 🔍 before you post. Your question has already been discussed multiple times on the forum.
But even after that, your code can only work if you have the BTCUSD M5 chart window open. If that chart is not open, iClose will most likely generate an error and return some random price or 0.
The easiest option is to get the closing price from the current chart. That is, if you need M5, then run the advisor on M5 and use Close[].
If the option with the current chart does not suit you, then you will have to learn how to correctly receive data from another chart.
double sellPriceBTC = iClose("BTCUSD", PERIOD_M5, 1); double buffer = 70.0; double stopLossBTC = sellPriceBTC - (400 / 1.24) - buffer; int ticketBTC = OrderSend("BTCUSD", OP_SELL, 1.24, Bid, 3, stopLossBTC, 0, "Sell BTC", 0, 0, clrRed);
You have hard code the symbol BTC. If that is not the chart's symbol,
-
then using the Predefined Variable Bid is wrong.
-
On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)
double stopLossBTC = sellPriceBTC - (400 / 1.24) - buffer;
-
Floating point has an infinite number of decimals, it's you were not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
Double-precision floating-point format - Wikipedia, the free encyclopediaSee also The == operand. - MQL4 programming forum (2013)
-
Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.
-
SL/TP (stops) need to be normalized to tick size (not Point) — invalid price on non-currencies.
On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum #10 (2011)And abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum (2012)
-
Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on non-currencies. So do it right.
Trailing Bar Entry EA - MQL4 programming forum (2013)
Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum (2012) -
Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
(MT4 2013)) (MT5 2022)) -
MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
MT4:NormalizeDouble - MQL5 programming forum (2017)
How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum (2017) -
Prices (and lots) you get from the terminal are already correct (normalized).
-
PIP, Point, or Tick are all different in general.
What is a TICK? - MQL4 programming forum (2014)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone,
I'm facing an issue with my Expert Advisor (EA) on MetaTrader 4, connected to a demo account with [name redacted by moderator] . When I try to place an order with a predefined Stop Loss (SLO), I receive the Error 130 (Invalid Stops), even though I've already tried the following:
Here is the code I am using to send the order:
I am trying to execute the order with a Stop Loss of 400 euros and no Take Profit. I would like to know if there are any rules or restrictions from the broker or MT4 platform that I might be missing, particularly since this is a demo account with [name redacted by moderator].
Any suggestions or advice would be greatly appreciated!
Thank you in advance!
Antonio