Find the High or Low for a number of bars -- code
Why not use iHighest and iLowest? https://docs.mql4.com/series/iHighest
Yes of course! Use the right tool for the right job.
double apexBars(int Nbars, string highLow) { double barApex; if(highLow == "Low") barApex = Low[iLowest(NULL,0,MODE_LOW,Nbars,0)]; if(highLow == "High") barApex = High[iHighest(NULL,0,MODE_HIGH,Nbars,0)]; Print("Index:",Nbars," highLow:",highLow," barApex:",barApex); return(barApex); }
This function will find the High or Low of some number of bars. I was pulling my hair out debugging this thing. The High part of the function worked great but the Low part of function always return 0. Then I realized that The variable barApex was not initially defined and so was set to 0. It was hard to find a Low price lower than 0!
-- enjoy.