# Is it possible to calculate the difference between the high and low?

Speed up MQL5 Cloud Network. Install Strategy Tester Agent!
456
2016.03.30 21:23
I want to calculate the difference between the high and low of the second last bar on the charts that are open on my screen and present as a display on the screen or chart itself? Is this possible? Will I need a script for this or indicator of EA?
Moderator
30722
2016.03.30 22:01
Yes it's possible, it can be done in script, indicator or EA, it depends of your needs.
21
2016.03.30 23:03

You can use either a script, indy or an EA, but it's best to use EA's as they have their own thread so it doesn't affect the GUI thread.

What you ask isn't perfunctory because you need to scan the charts you have open, which is a question unto itself. You could attach an EA to each chart, but that's not the best method. It's better to attach a master EA to only one chart and then it can scan all other charts you have open and do as you need.

```const int LOOK_BACK = 2; // which candle to target
MqlRates rates[];
ArraySetAsSeries(rates, true); // set array so newest candle is array[0]
double c2Hi, c2Lo, diff;
int copied = CopyRates(_Symbol, _Period, 0, LOOK_BACK, rates);

if (copied >= LOOK_BACK) {
c2Hi = rates[LOOK_BACK-1].high; // arrays are zero-based, so subtract 1
c2Lo = rates[LOOK_BACK-1].low;
diff = (c2Hi - c2Lo) / Point(); // use Point() to get the symbols decimal places
printf("c2Hi:%g c2Lo:%g diff:%g", c2Hi, c2Lo, diff); // c2Hi:1.13757 c2Lo:1.0814 diff:5617
}

N.B. The difference is in pipettes, so divide by 10 if you want pips (562pips)```
456
2016.03.31 06:24
pipsqueak1:

You can use either a script, indy or an EA, but it's best to use EA's as they have their own thread so it doesn't affect the GUI thread.

What you ask isn't perfunctory because you need to scan the charts you have open, which is a question unto itself. You could attach an EA to each chart, but that's not the best method. It's better to attach a master EA to only one chart and then it can scan all other charts you have open and do as you need.

Thank you!