double MarginCheck = MarginFree / Margin;
When I use this I get a division by zero error.
I ended up doing:
double MarginFree = AccountInfoDouble(ACCOUNT_MARGIN_FREE);double Eqty = AccountInfoDouble(ACCOUNT_EQUITY);double MarginCheck = ValNonZero(MarginFree/Eqty);
Just so you know, you may still get divide by zero problems if Eqty is 0.
That calculation is done BEFORE the result is passed to ValNonZero()
Well, not really.
Have you checked what AccountInfoDouble() returns when you aren't connected to an account? It returns 0
So if you aren't connected to your account before this code runs, you will get a zero divide error. Like when you restart the terminal.
This is probably what was happening with your initial ACCOUNT_MARGIN check giving zero divide errors.
Also, there is no point in ValNonZero() if you are already dividing by 0...