Can't work out why this isn't working

 

Hello

I'd be very grateful for a little assistance.  I can't work out why this little bit of script doesn't work:

double v1=AccountFreeMargin()*(RPC/100);
double v2=ABC*AccountLeverage();
double v3=(v1/v2);

Where:

RPC = 1

ABC=20 

I'm sure its something simple that I just haven't been able to find (eg. data type mismatch), but I can't discover what!

Thank you.

 
jmb:

Hello

I'd be very grateful for a little assistance.  I can't work out why this little bit of script doesn't work:

Where:

RPC = 1

ABC=20 

I'm sure its something simple that I just haven't been able to find (eg. data type mismatch), but I can't discover what!

Thank you.

If RPC is an int then divide by 100.0 not 100 otherwise you will end up with RPC/100 = 0

Type Casting 

 

Thank you for that.  I gave it a try, but still didn't work!

What did work was reversing the last line, from

double v3=(v1/v2);

... to

double v3=(v2/v1);

That doesn't, of course, give me the correct result, but it shows something - not sure what!

The results of line 1 are 100:

...of line 2 are  1279.5 (I made a mistake in my first comment with ABC=20, should be 12.79!).

Both of these work individually, and I can show their results in a comment.

But line 3 isn't playing ball.  The result should be 0.078 

 
jmb:

Hello

I'd be very grateful for a little assistance.  I can't work out why this little bit of script doesn't work:

Where:

RPC = 1

ABC=20 

I'm sure its something simple that I just haven't been able to find (eg. data type mismatch), but I can't discover what!

Thank you.


What doesn't work ? You have an error message ? Use Print(...") to show your value and explain what's your problem.
 

Oh dear!  What a nit-wit I am!  I'm so sorry to have troubled you.  At least you can have the last laugh knowing I've spent the last 2 hours going round and round on this!  In my variable lists ABC and RPC were initialised at zero values.  Now, as we all know, anything multiplied or divided by zero equals...

They are both now initialised at 1! 

Sorry!  ...and thank you!   :)