This is the set up
- On start I use a function that recognizes when a bar changes, when it does change, it calls a custom function that sets new values for global variables
- Global variables are set
- Once the global variables are set I call a function that makes calculations with global variables
- The weird thing is that calculations are ok if I add or substract, but if I divide doubles, the values of the involved doubles turn to zero, the global variable values are lost
5. I have tried NormalizeDouble, send the global variables as parameters so they are not directly involved in the calculations but every time I try to use them for calculation the global doubles turn to zero
1. You are not using Global Variables you are using globally declared variables, it's an important distinction to make to avoid confusion.
4 & 5 I assume you are talking about this code ? it is the only code you show that has a division . . .
double currentRiskReward = ((ffUpperChannelValue - ffLowerChannelValue) / ffLowerChannelValue) * 100; Print("TEMP: ",currentRiskReward);
lets work this code through with some typical EURUSD values . . .
1.2646 - 1.2545 = 0.0101
0.0101 / 1.2646 = 0.00798
0.00798 * 100 = 0.798
Print only shows 4 digits, if your upper and lower channel values are very close to each other then it could be possible for your resultant value to be less than 0.0001 and printing as 0.0, to avoid this use DoubleTo Str and read the documentation for Print()
Doers this line of code give you the correct values ?
Print("TEMP: ","setChannels",ffUpperChannelValue," ",ffLowerChannelValue);

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone
I have a strange situation that I would really appreciate any help with
This is the set up
I have tried NormalizeDouble, send the global variables as parameters so they are not directly involved in the calculations but every time I try to use them for calculation the global doubles turn to zero
The basic code to understand the issue is posted
If someone can help I would really appreciate it
Thanks