divide zero error

 

Can someone spot what is wrong with my code. I only have one place in my code where any division is being done but I continue to get zero divide errors

double CalculateLotSize(double EquityPercent, double StopLoss )
{
   //Code to Calculate lot size
                     // Print("AccountEquity(): "+AccountEquity() );
                      RiskAmount = AccountBalance()*(EquityPercent / 100.0);
                                Print("RiskAmount: "+RiskAmount);
                                 TickValue = MarketInfo(Symbol(),MODE_TICKVALUE);
                                Print("TickValue: "+TickValue);
                                if(Point == 0.001 || Point == 0.00001) TickValue *= 10;
                                 double LotSize = NormalizeDouble( (RiskAmount/StopLoss)/TickValue,1);
                           Print("TickValue check: "+TickValue);
                      Print("LotSize: "+LotSize);       
                      Print("stoploss: "+StopLoss);     
                      
                      return(LotSize);     
}
double EquityPercent = 2;//by default
double StopLoss is passed by value in the EA
 

Before this line . . . .

double LotSize = NormalizeDouble( (RiskAmount/StopLoss)/TickValue,1);

. . add a Print for StopLoss . . . you have a Zero somewhere, print all your Denominators.

 
jeemba2012:

Can someone spot what is wrong with my code. I only have one place in my code where any division is being done but I continue to get zero divide errors

You haven't declared TickValue as an int by any chance?

I'm guessing that you do not see zeros in your Prints. But if you do have a zero in StopLoss or TickValue it will not print!

Try putting the prints before the divide, then you may see something.

 
dabbler:

You haven't declared TickValue as an int by any chance?

I'm guessing that you do not see zeros in your Prints. But if you do have a zero in StopLoss or TickValue it will not print!

Try putting the prints before the divide, then you may see something.


thanks I was able to find the error.

Reason: