Stop loss must be above order price(selling)? What if I want it not to be? - page 3

 
Ahmet Metin Yilmaz:
Of course it is market info and i am the Who advised you to use it. 
I Just Wonder What is the problem? 
Then It might be spread! 

OK, this is really strange!!!

When i try to move my stop 50 points down, to 97250, I receive:

2020.05.25 18:49:26.533 2019.06.05 11:06:20   position modified [#4 sell 1 WIN$N 97300 sl: 97250 tp: 96945]

When i try to move my stop 83 points down, to 97217, I receive:

2020.05.25 18:47:47.786 2019.06.05 11:06:20   failed modify #4 sell 1 WIN$N sl: 97300, tp: 96945 -> sl: 97217, tp: 96945 [Invalid stops]

When i try to move my stop 84 points down, to 96216 

2020.05.25 18:51:16.696 2019.06.05 11:06:20   failed modify #4 sell 1 WIN$N sl: 97300, tp: 96945 -> sl: 97216, tp: 96945 [Invalid stops]

When i try to move my stop 85 points down, to 97215 I receive:

2020.05.25 18:45:05.786 2019.06.05 11:06:20   position modified [#4 sell 1 WIN$N 97300 sl: 97215 tp: 96945]

When i try to move my stop 100 points down, to 97200 I receive:

2020.05.25 18:52:56.563 2019.06.05 11:06:20   position modified [#4 sell 1 WIN$N 97300 sl: 97200 tp: 96945]


All of this happens in the same candle at the same time. the code is:

int novostop = entrada - 100;
Print(novostop);
trade.PositionModify( _Symbol, novostop, take_profit)


And the same occurs if i just input the price in PositionModify function.

edit:It seems that If the price of SL is multiple of 5, PositionModify works very well

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
 
So what I did was create a function for finding the closest multiple of five, and I'm using it when I need to move a stop
 

WIN$20 has a tick size of 5, you need to normalize all your prices according to it. Market price is moving by step of 5 so prices like 97216 or 97217 are invalid.

Forum on trading, automated trading systems and testing trading strategies

Need help to round order last digit to 0 or 5

Alain Verleyen, 2016.10.23 18:47

Normalize your price like that :

//+------------------------------------------------------------------+
//| Normalize price according to tick size                           |
//+------------------------------------------------------------------+
double normalizePrice(double price)
  {
   double tickSize=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_SIZE);
   return(MathRound(price/tickSize)*tickSize);
  }
If you would not have posted in a wrong section you had received an answer 5 hours sooner.
 
NormalizeDouble, It's use is usually wrong, as it is might be 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
 
William Roeder:
NormalizeDouble, It's use is usually wrong, as it is might be 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

You come late

and he didn't even use NormalizeDouble().

 
Alain Verleyen:

You come late

and he didn't even use NormalizeDouble().

Thank you guys for the help!!
I came with a similar solution to NormalizeDouble but loved to read about what William Roeder wrote and understand a bit more of the problem we are facing here..

Really really thank you everyone!

See ya!

Reason: