Need help making a loop count pips.

28

Hi,

I'm trying to figure out how to make a loop count length of bars in pips over multiple bars, But I've never used loops and i don't know how. I tried it bunch of times and felt stupid so the code I have is not in a loop form.

What I have is this:

double h=High[BarsBack];
double h1=High[BarsBack-1];
double h2=High[BarsBack-2];

double l=Low[BarsBack];
double l1=Low[BarsBack-1];
double l2=Low[BarsBack-2];

double q=h-l;
double q1=h1-l1;
double q2=h2-l2;

double pipsintotal=q+q1+q2;

What I want to do is make a loop that does the above except counts all pips in a longer length of bars than three. So say I was counting 1000 bars it would measure each bar in pips, add all 1000 of them together, and output total pips traveled.

-Thank you very much for your time. Have a wonderful day :^)

Moderator
2326

```   double total_pips = 0;
for(int i=0; i<fmin(Bars,1000); i++) total_pips+=(High[i]-Low[i]);
```

That adds together the range of the last 1000 bars (or the maximum number of bars, if less).

HTH