Error 130 - invalid stops ?

 

I don't understand. I have an EA that is working on one symbol, but not the other.

I copied the code from the good one and all I have to do is change the symbol and the magic number.

The error happens for both buy and sell.

For instance, I got this error: "Buy USDCHF at Price: 0.98184, SL: 0.98084", but I see nothing wrong with the stop.

I also get long numbers like 0.9812799999999999, but isn't there supposed to be just 5 trailing digits ?


int stoploss = 100;
double buy_stoploss =  Ask - (stoploss * _Point);
double sell_stoploss = Bid + (stoploss * _Point);

The following code won't remove the extra digits, by the way.

NormalizeDouble(Ask - (stoploss * _Point),_Digits));
NormalizeDouble(Bid + (stoploss * _Point),_Digits));
 
  1. mt4ski: I also get long numbers like 0.9812799999999999, but isn't there supposed to be just 5 trailing digits ?

    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

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

  2. double buy_stoploss =  Ask - (stoploss * _Point);
    double sell_stoploss = Bid + (stoploss * _Point);
    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.
    1. 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 would be longer. Don't you want the same/specified amount for either direction?
    2. 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
    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.)

  3. You used NormalizeDouble, It's use is usually wrong, as it is potentially 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.) (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 - General - MQL5 programming forum
                How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum

 
I implemented your NormalizePrice function for pending orders but what really solve the problem was to open the order without stop loss and take profit, then use the OrderOpenPrice() value when modifying the order.
 

Oops I spoke too soon. Although one EA was working, it was also generating some "invalid stops" errors. Now there are no more errors so I thought the second EA would work but it still doesn't. No trades are executed. All I get are "invalid stops" errors when opening pending orders even with StopLoss: 0.0, TakeProfit: 0.0

 

Show the code how you send the orders

i guess, this problem is in order send

 
amando:

Show the code how you send the orders

i guess, this problem is in order send

Okay but why does it work perfectly with one symbol and not at all with another?

ticket = OrderSend(Symbol, Type, Volume, Price, _slippage, Stop, Profit, Comment, _magicNumber, Expiration, Arrow);
                

Again with USDCHF I get the error 130 even if the stop value (0.0) is good.

So far, it doesn't work with USDCHF and NZDUSD.

But it works with CADCHF, USDCAD and GBPUSD.

 
mt4ski:

Okay but why does it work perfectly with one symbol and not at all with another?

Again with USDCHF I get the error 130 even if the stop value (0.0) is good.

So far, it doesn't work with USDCHF and NZDUSD.

But it works with CADCHF and GBPUSD.

Show ALL the relevant code, including how you set the values and the values used.

An error 130 can all arise if the open price is not good.

 
Check the minimal distance of the pending order from the current price (of the target symbol - which can differ from symbol to symbol) prior to attempting to place a pending order and then place the pending order at at least that distance. Otherwise you are going to get that error 
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The...
 
Mladen Rakic:
Check the minimal distance of the pending order from the current price (of the target symbol - which can differ from symbol to symbol) prior to attempting to place a pending order and then place the pending order at at least that distance. Otherwise you are going to get that error 
Thanks it works now. For some reason the distance parameter was set to 0 in the Expert properties. I'm going to do what you said.
Reason: