How to fix invalid stops error

 

I keep running into this error at the automated validation testing:

test on EURUSD,H1 (netting)
strategy tester report 606 total trades
test on XAUUSD,D1 (netting)
 2018.06.25 01:34:00   failed exchange buy 0.20 XAUUSD at 1271.980 sl: 1271.480 tp: 1272.480 [Invalid stops]
 2018.06.27 01:00:30   failed exchange sell 0.20 XAUUSD at 1258.300 sl: 1258.800 tp: 1257.800 [Invalid stops]
strategy tester report 83 total trades

Everything else is a pass:

I kept trying to change # of ticks, symbols, trade frequency, trailing, etc. but nothing have worked. 

I also tried messing with the stops and take levels back and forth, but still to no avail fixing it.

Any suggestions? 

I already tried this:  https://www.mql5.com/en/forum/285056

 

Also other problem is that this is an H12 bot and the fail is on H1 and D1 netting.


I don't think the error has to do with this code:

//--- inputs for main signal
input int                Signal_ThresholdOpen              =10;                 // Signal threshold value to open [0...100]
input int                Signal_ThresholdClose             =10;                 // Signal threshold value to close [0...100]
input double             Signal_PriceLevel                 =0.0;                // Price level to execute a deal
input double             Signal_StopLevel                  =50.0;               // Stop Loss level (in points)
input double             Signal_TakeLevel                  =50.0;               // Take Profit level (in points)
double NormalizePrice(double price)
  {
   double m_tick_size=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
   return(NormalizeDouble(MathRound(price/m_tick_size)*m_tick_size,_Digits));
  }
 
  1. 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.

  2. NormalizeDouble, It's use is usually wrong
    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 - 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

 
Hi, have I used the NormalizeDouble() function wrong or not in this instance? Also this comment was posted before by you in numerous forums, but still doesn't give me a clue on a direct fix? I'm wondering if something like this: https://www.mql5.com/en/forum/146370#comment_3693988 may fix it, but unsure?
Trailing Bar Entry EA
Trailing Bar Entry EA
  • 2013.08.16
  • www.mql5.com
Hello, I have written an EA that trails one bar high or low and opens 2 positions. After that, it should halt and do nothing more...
 
ANDREW MAGDY KAMAL :

I keep running into this error at the automated validation testing:


Everything else is a pass:

I kept trying to change # of ticks, symbols, trade frequency, trailing, etc. but nothing have worked. 

I also tried messing with the stops and take levels back and forth, but still to no avail fixing it.

Any suggestions? 

I already tried this:  https://www.mql5.com/en/forum/285056

Did you forget to check the symbol freeze levels? Read the article: THE CHECKS A TRADING ROBOT MUST PASS BEFORE PUBLICATION IN THE MARKET

The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks, as a small error in the expert or indicator logic can cause losses on the trading account. That is why we have developed a series of basic checks to ensure the required quality level of the Market products. If any errors are identified by the Market...
 
The sky is blue. Is the sky blue?
The ocean is wet. Is the Ocean wet?
It won't work on Metals. So do it right
ANDREW MAGDY KAMAL: have I used the NormalizeDouble() function wrong or not in this instance?
 
Vladimir Karputov:

Did you forget to check the symbol freeze levels? Read the article: THE CHECKS A TRADING ROBOT MUST PASS BEFORE PUBLICATION IN THE MARKET

Yes didn't work

 

Also how do you prevent or catch:

Modification failed due to order or position being close to market


That may fix it, although the error is never set when it trades on its intended time frame. Just the automatic validation stuff.
 

The same problem with me. to solve the problem, I just create a function to place stop loss:


#

The same problem with me. to solve the problem, I just create a function to place stop loss:
#property library
//import the trade function
#include <Trade\trade.mqh>
CTrade trade;
void Placestoploss(string Positioncomment="",long SL_point=250)export
  {
  
 
   for(int i=PositionsTotal()-1; i>=0; i--)
     {
      
      
      ulong PositionTicket=PositionGetTicket(i);
      string symbol=PositionGetSymbol(i);
      int Symbol_Digit=SymbolInfoInteger(symbol,SYMBOL_DIGITS);
      double Symbol_Point=SymbolInfoDouble(symbol,SYMBOL_POINT);
      double checkcurrentstoploss=PositionGetDouble(POSITION_SL);
      double PositionPriceOpen=PositionGetDouble(POSITION_PRICE_OPEN);
      long stopLevels = SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL)+SymbolInfoInteger(symbol, SYMBOL_SPREAD);
      SL_point=MathMax(stopLevels,SL_point);
      if(PositionGetString(POSITION_COMMENT)==Positioncomment)
      {

      if(checkcurrentstoploss==0||(MathAbs(checkcurrentstoploss-PositionPriceOpen)>=(SL_point+200)*Symbol_Point)
         )
        {
           
         if(PositionGetInteger(POSITION_TYPE)==ORDER_TYPE_SELL)
           {
            trade.PositionModify(PositionTicket,NormalizeDouble(PositionPriceOpen+(Symbol_Point*SL_point),Symbol_Digit),0);
           }

         else
          {
            if(PositionGetInteger(POSITION_TYPE)==ORDER_TYPE_BUY)
              {
               trade.PositionModify(PositionTicket,NormalizeDouble(PositionPriceOpen-(Symbol_Point*SL_point),Symbol_Digit),0);
              }
           }
         }
      }

      }
   }
 
Trần văn #: The same problem with me. to solve the problem, I just create a function to place stop loss:
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. PositionPriceOpen+(_Point*Autoplacestoploss)
    PositionPriceOpen+(_Point*Autoplacestoploss),
    

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. 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?

    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 close to 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 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)

 
Hello, someone please help, I am getting invalid stops error in validation process of the EA, and my EA doesn't use any stop loss or take profit levels, then why this error ?