Skip to content

Instantly share code, notes, and snippets.

@matthewkastor
Last active January 23, 2016 21:11
Show Gist options
  • Save matthewkastor/00e6aa82e81af1c9ea67 to your computer and use it in GitHub Desktop.
Save matthewkastor/00e6aa82e81af1c9ea67 to your computer and use it in GitHub Desktop.
get the range of price from the given quantity of bars in metatrader 4
// Gets the range (highest minus lowest) of price for the last 5 bars
// double currentRange = CalculateCurrentRange(5);
double CalculateCurrentRange(int howManyBars){
double highVal;
double lowVal;
int highVal_index=iHighest(NULL,0,MODE_HIGH,howManyBars,0);
int lowVal_index=iLowest(NULL,0,MODE_LOW,howManyBars,0);
if(highVal_index!=-1 && lowVal_index!=-1) {
highVal=High[highVal_index];
lowVal=Low[lowVal_index];
return NormalizeDouble(highVal - lowVal,Digits);
} else {
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment