Error 130

 

Hi,

I am getting error 130. I read many articles regarding the same. But couldn't fix the error. because the same code is working with some input and not with some other.

I am using NormalizeDouble function for Tradeprice, SL and TP. Pls help me with it.

2020.06.29 14:13:01.637 2020.06.02 04:30:00  ravi_v2_Super_candle EURUSD,M15: Ticket = 1, Buy Price = 1.1152, SL = 1.112, TP = 1.12, Bid = 1.1166, Ask = 1.1167
2020.06.29 14:13:01.637 2020.06.02 04:30:00  ravi_v2_Super_candle EURUSD,M15: open #1 buy limit 1.00 EURUSD at 1.1152 sl: 1.1120 tp: 1.1200 ok
2020.06.29 14:13:01.601 2020.06.02 03:45:00  ravi_v2_Super_candle EURUSD,M15: Ticket = -1, Sell Price = 1.1128, SL = 1.1131, TP = 1.1124, Bid = 1.1124, Ask = 1.1125
2020.06.29 14:13:01.601 2020.06.02 03:45:00  ravi_v2_Super_candle EURUSD,M15: OrderSend error 130
2020.06.29 14:13:01.569 2020.06.02 03:00:00  ravi_v2_Super_candle EURUSD,M15: Ticket = -1, Sell Price = 1.1127, SL = 1.113, TP = 1.1123, Bid = 1.1119, Ask = 1.112
2020.06.29 14:13:01.569 2020.06.02 03:00:00  ravi_v2_Super_candle EURUSD,M15: OrderSend error 130
2020.06.29 14:13:01.561 2020.06.02 02:45:00  ravi_v2_Super_candle EURUSD,M15: Ticket = -1, Buy Price = 1.1132, SL = 1.112, TP = 1.115, Bid = 1.1135, Ask = 1.1136
2020.06.29 14:13:01.561 2020.06.02 02:45:00  ravi_v2_Super_candle EURUSD,M15: Ticket = -1, Buy Price = 1.1132, SL = 1.112, TP = 1.115, Bid = 1.1135, Ask = 1.1136
2020.06.29 14:13:01.561 2020.06.02 02:45:00  ravi_v2_Super_candle EURUSD,M15: OrderSend error 130

 
SL = NormalizeDouble(SL, Digits);
 
Gopalakrishna R:
NormalizeDouble, It's use is usually wrong, as it is in your case.
  1. Floating point has infinite number of decimals, it's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
              Double-precision floating-point format - Wikipedia, the free encyclopedia

    See also The == operand. - MQL4 programming forum

  2. Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

  3. SL/TP (stops) need to be normalized to tick size (not Point) — code fails on metals. (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum) 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

  4. 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 Metals. So do it right: Trailing Bar Entry EA - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum

  5. 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.

  6. MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
              MT4:NormalizeDouble - MQL5 programming forum
              How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum

  7. Prices you get from the terminal are already normalized.

  8. PIP, Point, or Tick are all different in general.
              What is a TICK? - MQL4 programming forum 2014.08.03
 
Gopalakrishna R: am getting error 130.
Ticket = -1, Sell Price = 1.1128, SL = 1.1131, TP = 1.1124, Bid = 1.1124, Ask = 1.1125
  1. "Sell Price" doesn't tell us whether you are trying to open a sell, sell limit or sell stop.

  2. You are using 3 PIP SL minus the spread, a 4 PIP TP (including the spread), and an open price of 3 PIP

    You can't move stops (or pending prices) closer to the market than the minimum: MODE_STOPLEVEL * _Point or SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

    On some ECN type brokers the value might be zero (broker doesn't know.) Use a minimum of two (2) PIPs.

  3. You buy at the Ask and sell at the Bid.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. 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 at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. 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 spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134.

  4. When I tried pending orders, I saw similiar problems. It may be comparing TP/SL to current prices not pending price. You could try creating the order and then setting the stops.

  5. Humans can't watch the screen 24/7 so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
 
William Roeder:
  1. "Sell Price" doesn't tell us whether you are trying to open a sell, sell limit or sell stop.

  2. You are using 3 PIP SL minus the spread, a 4 PIP TP (including the spread), and an open price of 3 PIP

    You can't move stops (or pending prices) closer to the market than the minimum: MODE_STOPLEVEL * _Point or SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).
              Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

    On some ECN type brokers the value might be zero (broker doesn't know.) Use a minimum of two (2) PIPs.

  3. You buy at the Ask and sell at the Bid.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using the Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. 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 at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. 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 spread widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY (OANDA) shows average spread = 26 points, but average maximum spread = 134.

  4. When I tried pending orders, I saw similiar problems. It may be comparing TP/SL to current prices not pending price. You could try creating the order and then setting the stops.

  5. Humans can't watch the screen 24/7 so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.

Thank you. I ll try these things.

Reason: