Why am I getting INVALID STOPS, please?

 

I dont understand the whole invalid stops thing.

This is my code and output. Im using a multiplier of ATR added or deducted to ASK. 

   if(PositionsTotal()==0)
      // buy when candle is bullish
      if(PriceInfo[1].close > PriceInfo[1].open)
        {
         // buy
         trade.Buy(
            minVol, // how much
            _Symbol, //current symbol
            Ask, //buy price
            sl1, //stop loss
            tp1, // take profit
            "Long Position: " // Comment or command
         );

2020.06.10 05:44:23.251 2020.05.01 11:51:40   <------------->

2020.06.10 05:44:23.251 2020.05.01 11:51:40   TESTY ATR_OUTPUT: 16.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   ASK: 19580.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   tp: 112.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   SL: 64.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   full tp: 19692.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   full SL: 19516.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   <------------->

2020.06.10 05:44:23.495 2020.05.01 11:51:40   failed market buy 0.01 @MJNK sl: 19516 tp: 19692 [Invalid stops]

2020.06.10 05:44:23.495 2020.05.01 11:51:40   CTrade::OrderSend: market buy 0.01 @MJNK sl: 19516 tp: 19692 [invalid stops]


 
codenameCookie:

I dont understand the whole invalid stops thing.

This is my code and output. Im using a multiplier of ATR added or deducted to ASK. 

2020.06.10 05:44:23.251 2020.05.01 11:51:40   <------------->

2020.06.10 05:44:23.251 2020.05.01 11:51:40   TESTY ATR_OUTPUT: 16.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   ASK: 19580.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   tp: 112.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   SL: 64.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   full tp: 19692.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   full SL: 19516.0

2020.06.10 05:44:23.251 2020.05.01 11:51:40   <------------->

2020.06.10 05:44:23.495 2020.05.01 11:51:40   failed market buy 0.01 @MJNK sl: 19516 tp: 19692 [Invalid stops]

2020.06.10 05:44:23.495 2020.05.01 11:51:40   CTrade::OrderSend: market buy 0.01 @MJNK sl: 19516 tp: 19692 [invalid stops]


Hi, or wrong values for tp sl or....have you checked stop levels?
Use MT function to discover how much is stop levels and check if the condition is satisfied. Broker requires Sl and TP must be distant of n points by current price.

 
Marco Montemari:

Hi, or wrong values for tp sl or....have you checked stop levels?
Use MT function to discover how much is stop levels and check if the condition is satisfied. Broker requires Sl and TP must be distant of n points by current price.

Thanks much for the reply. :)
 I got it working by hardcoding a multiple value of 5 that I got from SPREAD. Although its probably coincidence it worked and Im still not sure how to do it dynamically. Its a shame the MQL5 docs dont seem to have examples. Plus a lot of example on this forum or elsewhere seem wrong. 
 
codenameCookie:
Thanks much for the reply. :)
 I got it working by hardcoding a multiple value of 5 that I got from SPREAD. Although its probably coincidence it worked and Im still not sure how to do it dynamically. Its a shame the MQL5 docs dont seem to have examples. Plus a lot of example on this forum or elsewhere seem wrong. 
In that case it could mean that the symbol you are trading has a price step size of 5. This means that each price has to be a multiple of 5. You can verify this by using SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE).
 
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) — 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
Reason: