- You can't sum when you clear it each time in the inner loop.
- No need for the j==i, start the loop at j=pos+1
Dannoo007:
Hello forum.
How do you go about it??
before I double check, will this ever work, at a conceptual level, or should this be done differently?
double sum = 0.0; int Period = 10; int pos = Period - 1; for(int i = pos + 1; i < rates_total; i++) { sum += close[i] - close[i-1]; }
Although the loop is redundent because you are just summing the differences between the close prices. The problem can be reduced to the following
int Period = 10; int pos = Period - 1; double sum = close[pos] - close[rates_total-1];
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello forum.
I am looking to set up this indicator where I want to add ALL differences among closing price
- for ALL bars,
- compared to one another,
- within specified Period.
How do you go about it?? I was thinking of a "Nested FOR" logic, but it wouldn't compile (see below).
before I double check, will this ever work, at a conceptual level, or should this be done differently?
simplified excerpt from OnCalculate() :
etc etc