So I just spent over an hour trying to find why the code below was always outputting lotmin.
If you take a look at calcLot and calcLot1 you will see the only difference is a stupid pair of brackets, this was the cause of my frustration which I would not wish upon anyone. Hopefully this is of some use and saves someone time (since time = money).
Another quirk I sometimes get is dividing by a variable doesn't always output the desired value, less stress for me now just to multiply by MathPow(var, -1). Anybody got some other surprises they've encountered in their coding days?
If you take a look at calcLot and calcLot1 you will see the only difference is a stupid pair of brackets, this was the cause of my frustration which I would not wish upon anyone. Hopefully this is of some use and saves someone time (since time = money).
Inserted Code
extern int Risk=1;
extern int StopLoss = 250;
int init()
{
double Lots;
int Step;
if(MarketInfo(Symbol(),MODE_LOTSTEP) == 0.01) Step = 2;
if(MarketInfo(Symbol(),MODE_LOTSTEP) == 0.10) Step = 1;
if(MarketInfo(Symbol(),MODE_LOTSTEP) == 1.00) Step = 0;
double value = MarketInfo(Symbol(),MODE_TICKSIZE);
double lotmin = MarketInfo(Symbol(), MODE_MINLOT);
double calcLot = (AccountFreeMargin() * Risk/100) / ((StopLoss/Point) * value);
double calcLot1 = (AccountFreeMargin() * (Risk/100)) / ((StopLoss/Point) * value);
Lots = NormalizeDouble( MathMax(lotmin,calcLot),Step);
Print(DoubleToStr(calcLot,4), " ", DoubleToStr(calcLot1,4));
Comment(DoubleToStr(Lots,Step));
return(0);
} Another quirk I sometimes get is dividing by a variable doesn't always output the desired value, less stress for me now just to multiply by MathPow(var, -1). Anybody got some other surprises they've encountered in their coding days?