Custom Criteria Coding issues - page 2

 
R4tna C #:

Sure - please do follow the NormalizeDouble() recommendation, may not be apparent at first but I have hit subtle bugs when it was omitted.

Good luck with you trading and ongoing coding

I am unfamiliar with  NormalizeDouble().. how would I use that in the code? I didn't notice it in your adjustments. Will the win_ratio code work?

 double win_ratio = (TesterStatistics(STAT_PROFIT_TRADES) / TesterStatistics(STAT_LOSS_TRADES))

Dividing an enum by an enum like that? It feels off, but that's the best way I could think it up.

Now I'm worried about that NormalizeDouble() comment. And Thanks! I appreciate your help!

 

Like this?

  double win_ratio = (TesterStatistics(STAT_PROFIT_TRADES) / TesterStatistics(STAT_LOSS_TRADES));
  NormalizeDouble(win_ratio, 4)

This explanation confused me further:

https://docs.mql4.com/convert/normalizedouble

NormalizeDouble - Conversion Functions - MQL4 Reference
NormalizeDouble - Conversion Functions - MQL4 Reference
  • docs.mql4.com
NormalizeDouble - Conversion Functions - MQL4 Reference
 
Nicholas C Weber #:

Like this?

This explanation confused me further:

https://docs.mql4.com/convert/normalizedouble

Yes this works - normalizes to 4 decimal places

  NormalizeDouble(win_ratio, 4)
But have a look at the 2nd line in the code I posted:
   if(NormalizeDouble(balance, 1) > NormalizeDouble(0.0, 1) ) //Recommendation (example only of 1 decimal place) - apply to all double comparisons

Best to do this every time you compare doubles

 
Nicholas C Weber #:

Dividing an enum by an enum like that? It feels off, but that's the best way I could think it up.

Actually this is not dividing an enum - the TesterStatistics() receives an enum but returns a double

 
R4tna C #:

Actually this is not dividing an enum - the TesterStatistics() returns a double

Do the Enums need to be normalized? Or can they remain floating?

 
Nicholas C Weber #:

Do the Enums need to be normalized? Or can they remain floating?

No Enums are integers.

Only doubles, floats, i.e. all fractional numbers need to have accuracy applied when comparing

 
R4tna C #:

No Enums are integers.

Only doubles, floats, i.e. all fractional numbers need to have accuracy applied when comparing

So this isn't overkill?

  double  min_dd = (TesterStatistics(STAT_EQUITY_DD) + TesterStatistics(STAT_BALANCE_DD) / 2);
  if(NormalizeDouble(min_dd, 4) > NormalizeDouble(0.0, 1) )
  {
    NormalizeDouble(min_dd, 4) = (NormalizeDouble(1.0, 1) / NormalizeDouble(min_dd, 4) );
  }
 
I guess I could normalize it once after specifying the double constant and all the if else code would comply with the normalized constant? Or would I have to normalize it each time I was comparing it to something else?
 
Nicholas C Weber #:

So this isn't overkill?

No I think it's good. Maybe you could normalize it once and then compare, but personally I prefer leave the numbers as is, and to normalize with every comparison to avoid bugs like I had in the past.

Also in different situations you may like to use different numbers of decimal places, so you can choose that at comparison time if you leave the number as is

 
R4tna C #:

No I think it's good. Maybe you could normalize it once and then compare, but personally I prefer to normalize with every comparison to avoid bugs like I had in the past

I guess that answers my last reply. LOL. Thanks again. I'm normalizing the crud out of it now. I've revised this EA soooo many times. On the market, it's like 2.6, but on my computer it's well over 20-30. I think it's 2.9.5 or something.

Reason: