Problem with Update Build 5800

 

My 2 years identical code is runing on errors now after this release.

For example i have added to my code DWEX Portfolio Risk Man Multi Position.mqh

and i am getting anerror 

 zero divide, check divider to avoid this error in (3939,86)

which used to work fine.

bool CPortfolioRiskMan::GetAssetStdDevReturns(string VolSymbolName, double &StandardDevOfReturns)
  {
///Print("Running " + __FUNCTION__ + "()");

   double returns[];

   ArrayResize(returns, StandardDeviationPeriods);

//STORE 'CHANGE' IN CLOSE PRICES TO ARRAY
   for(int calcLoop=0; calcLoop < StandardDeviationPeriods; calcLoop++) //START LOOP AT 1 BECAUSE DON'T WANT TO INCLUDE CURRENT BAR (WHICH MIGHT NOT BE COMPLETE) IN CALC.
     {
      //USE calcLoop + 1 BECAUSE DON'T WANT TO INCLUDE CURRENT BAR (WHICH WILL NOT BE COMPLETE) IN CALC.  CALCULATE RETURN AS A RATIO. i.e. 0.01 IS A 1% INCREASE, AND -0.01 IS A 1% DECREASE
      returns[calcLoop] = (iClose(VolSymbolName, ValueAtRiskTimeframe, calcLoop + 1) / iClose(VolSymbolName, ValueAtRiskTimeframe, calcLoop + 2)) - 1.0; 
     }

//CALCULATE THE STD DEV OF ALL RETURNS (MathStandardDeviation() IN #include <Math\Stat\Math.mqh>)
   StandardDevOfReturns = MathStandardDeviation(returns);

   return true;
  }

I think it has to do with open and close price, because when i ignore the error by skiping the part of codem i get errors related to my SL open and close price

 

A recent build fixed an issue where division by 0 might not result in a "zero divide" error at runtime. The problem is in your code; a runtime crash is the expected result of division by 0.

You can disable the floating point dividers check in the project properties, then your advisor will stop crashing at runtime:

https://www.metatrader5.com/en/metaeditor/help/mql5storage/projects#properties

  • Check floating point dividers: applications with the check disabled work a little faster, because the zero divide error is not checked during code execution.

But this will only mask the real problem - your code is unreliable.

 
Vladislav Boyko #:
your code is unreliable

iClose fails and returns 0. As a result of dividing by 0, you assign inf to returns[calcLoop] (if checking floating point dividers is disabled and the EA didn't crash). If returns[calcLoop] affects the trading logic, it will lead to incorrect trading:

  • in the best case, the EA may send invalid trading orders that will not be executed
  • in the worst case, trading orders that should not exist according to the strategy will be executed

https://www.mql5.com/en/docs/series/iclose

Return Value

The Close price of the bar (indicated by the 'shift' parameter) on the corresponding chart or 0 in case of an error. For error details, call the GetLastError() function.