OrderModify error 1 during back testing - page 2

 
GumRai:


In the OP's code

you could simply change it to something like

if you are trying to replicate the error


I hear you. I was asking for more code simply because he says " The code works absolutely fine and does its job of break even at the correct point " so I was curious if he get's the errors before or after the OrderModify was successful .
 
thrdel:

I hear you. I was asking for more code simply because he says " The code works absolutely fine and does its job of break even at the correct point " so I was curious if he get's the errors before or after the OrderModify was successful .

I had a similar problem and the first OrderModify worked fine, subsequent OrderModifies were called because of the failure of comparing 2 doubles.

I started this thread

https://forum.mql4.com/56943

when I was just starting to learn to code.

It's beyond me why prices aren't automatically normalised to Digits, but they obviously aren't.

 
GumRai:

I had a similar problem and the first OrderModify worked fine, subsequent OrderModifies were called because of the failure of comparing 2 doubles.

I started this thread

https://forum.mql4.com/56943

when I was just starting to learn to code.

It's beyond me why prices aren't automatically normalised to Digits, but they obviously aren't.


Bits me too, but they do mention the need to normalize calculated stops.

Does it get done automatically in mt5?

 
thrdel:


Bits me too, but they do mention the need to normalize calculated stops.

Does it get done automatically in mt5?

Not, the same applies to MT5 regarding doubles and stops.
 

Fot those that think that the OrderOpenPrice should already be a normalised double

Put this in a script

void OnStart()
  {
//---

  for(int index=OrdersHistoryTotal()-1;index>=0;index--)
     {
     if(!OrderSelect(index,SELECT_BY_POS,MODE_HISTORY) ) continue;
        Print(OrderTicket()," ",OrderSymbol()," ",DoubleToStr(OrderOpenPrice(),16)  );
     }
  }
//+------------------------------------------------------------------+

ALL the trades were placed using Ask or Bid

The result from the above script

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51606602 GBPUSDm 1.6686300000000002

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51606532 GBPUSDm 1.6684500000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51584597 GBPJPYm 170.3480000000000132

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51582545 EURUSDm 1.3729800000000001

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51582536 EURUSDm 1.3729800000000001

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51579753 GBPUSDm 1.6668800000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51579209 GBPJPYm 170.3480000000000132

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51578931 GBPJPYm 170.3009999999999877

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51578298 GBPJPYm 170.3750000000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575675 GBPUSDm 1.6463400000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575673 GBPUSDm 1.6478400000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575671 GBPUSDm 1.6493400000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575670 GBPUSDm 1.6508400000000002

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575669 GBPUSDm 1.6523400000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575668 GBPUSDm 1.6538400000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575665 GBPUSDm 1.6553400000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575662 GBPUSDm 1.6568400000000002

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575660 GBPUSDm 1.6583400000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575659 GBPUSDm 1.6598400000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575657 GBPUSDm 1.6613400000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575656 GBPUSDm 1.6628400000000002

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575655 GBPUSDm 1.6643400000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51575131 GBPUSDm 1.6658400000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51491427 GBPJPYm 169.9809999999999946

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51482028 XAUUSDm 1339.8089999999999692

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51481726 GBPJPYm 169.9809999999999946

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51481205 GBPJPYm 169.8350000000000080

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51478860 GBPJPYm 170.1320000000000050

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51474409 GBPJPYm 169.9470000000000028

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51472676 GBPJPYm 169.9470000000000028

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51457057 XAUUSDm 1339.8089999999999692

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51457055 GBPJPYm 169.7709999999999866

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51424359 GBPJPYm 169.5730000000000076

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51424350 GBPJPYm 169.5970000000000084

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51423533 GBPJPYm 169.5490000000000066

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51421850 GBPJPYm 169.5869999999999892

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51421774 GBPJPYm 169.5459999999999924

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51421734 GBPJPYm 169.5800000000000126

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51421471 GBPJPYm 169.5459999999999924

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51420693 GBPJPYm 169.5749999999999886

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51420280 GBPJPYm 169.5060000000000002

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51419784 GBPJPYm 169.6109999999999900

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51415332 GBPJPYm 169.4329999999999927

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51401644 GBPJPYm 169.4900000000000092

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51398071 GBPJPYm 169.4900000000000092

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51378377 GBPJPYm 169.4900000000000092

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51377134 GBPJPYm 169.6140000000000044

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51357246 GBPJPYm 169.7810000000000060

 
GumRai:

Fot those that think that the OrderOpenPrice should already be a normalised double

What is a "normalised double" ?

Can you try this on your data for comparison . . .

void OnStart()
  {
//---

  for(int index=OrdersHistoryTotal()-1;index>=0;index--)
     {
     if(!OrderSelect(index,SELECT_BY_POS,MODE_HISTORY) ) continue;
        Print(OrderTicket()," ",OrderSymbol()," ",DoubleToStr(OrderOpenPrice(),16), " Normalised: ", DoubleToStr( NormalizeDouble( OrderOpenPrice(), Digits ), 16 ) );
     }
  }
//+------------------------------------------------------------------+
 
GumRai:

Fot those that think that the OrderOpenPrice should already be a normalised double

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51606602 GBPUSDm 1.6686300000000002

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51606532 GBPUSDm 1.6684500000000000

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51584597 GBPJPYm 170.3480000000000132

19:14:43 OrderOpenPriceTest GBPUSDm,H1: 51582545 EURUSDm 1.3729800000000001


They are normalized to 5 digits. Many decimal numbers can NOT be represented in floating point exactly (the decimal fraction "0.1" is equivalent to an infinitely repeating binary fraction: 0.000110011.) Reread The == operand. - MQL4 forum You can NOT compare doubles with equality. 1.6686250000001, 1.6686300000000002, and 1.6686349999999999 are all the same price (1.66863 +/- Ticksize/2)
 
GumRai:

Fot those that think that the OrderOpenPrice should already be a normalised double

Put this in a script

ALL the trades were placed using Ask or Bid

...

RaptorUK:

What is a "normalised double" ?

Can you try this on your data for comparison . . .


A double is always a double, normalized or not. It means that there is not necessarily an exact representation (power of 2) of the value.

However NormalizeDouble() function can be used to compare double. If we are talking about price there is no point to use 16 digits, but only _Digits :

Calculated values of StopLoss, TakeProfit, and values of open prices for pending orders must be normalized with the accuracy, the value of which can be obtained by Digits().

I made some tests :

   double testvalue1=1.375864999998;           // Greater value rounded to 1.37586
   double testvalue2=1.375854999999;           // Smaller value rounded to 1.37586
   Print("value1=value ? ",testvalue1==testvalue2);
   Print("value1=",DoubleToString(testvalue1,16)," value2=",DoubleToString(testvalue2,16));
   Print("Normalized value1= Normalized value ? ",NormalizeDouble(testvalue1,_Digits)==NormalizeDouble(testvalue2,_Digits));
   Print("Normalized value1=",DoubleToString(NormalizeDouble(testvalue1,_Digits))," Normalized value 2=",DoubleToString(NormalizeDouble(testvalue2,_Digits)));

Results (rounding change on 12th digit):

2014.03.05 15:07:58.104 _quick_tests_ EURUSD,M5: Normalized value1=1.37586000 Normalized value 2=1.37586000
2014.03.05 15:07:58.104 _quick_tests_ EURUSD,M5: Normalized value1= Normalized value ? true
2014.03.05 15:07:58.104 _quick_tests_ EURUSD,M5: value1=1.3758649999980000 value2=1.3758549999990000
2014.03.05 15:07:58.104 _quick_tests_ EURUSD,M5: value1=value ? false

 
angevoyageur: However NormalizeDouble() function can be used to compare double.

Sure, it can. But then

  1. you run into Can price != price ? - MQL4 forum and those problems.
  2. You get people normalizing to Digits when price must be normalized to tickValue (not necessary equal to Point=10**Digits) therefor generally wrong.
  3. You get people normalizing to 0.01 when lotsize must be normalized to lotStep (not necessary equal to a power of ten) therefor generally wrong.
  4. it's an expensive call. MathAbs( v1 - v2 ) < Point/2 (equality) and v1 - v2 > -Point/2 (>=) are efficient, and explicitly show the equality test.

Sure, it can, but I recommend never use it for any reason.



 
WHRoeder:

Sure, it can. But then

  1. you run into Can price != price ? - MQL4 forum and those problems.
  2. You get people normalizing to Digits when price must be normalized to tickValue (not necessary equal to Point=10**Digits) therefor generally wrong.
  3. You get people normalizing to 0.01 when lotsize must be normalized to lotStep (not necessary equal to a power of ten) therefor generally wrong.
  4. it's an expensive call. MathAbs( v1 - v2 ) < Point/2 (equality) and v1 - v2 > -Point/2 (>=) are efficient, and explicitly show the equality test.

Sure, it can, but I recommend never use it for any reason.



Yes I know your recommendation, that makes sense. But if people knows and understands the limitations, it can be used.

About your point 4, do you check it effectively ? Just curious.