Finding Max/Min Indicator Values in Given Range
Topic: Finding Max/Min Indicator Values in Given Range
Hey, I am currently customizing an RVI indicator for eventual use in an EA. I figured it would be easier to check my work if I can actually see the results before moving on to back-testing.
The basic idea is to take the last 300 bars of the RVI (an indicator without fixed max/min's) and determine & draw lines at RviMax, RviMin, RviMid (middle), and some other calculated levels. Essentially I want to establish a recent RVI range without changing how the indicator naturally calculates/displays. This range should update in real-time, only changing if a new max/min is established (on bar close), or if the existing max/min turns older than 300 bars.
I think I am pretty close to the desired result. The indicator will find the MaxRVI when loaded and will display that value in the buffer correctly for all previous bars up to 300. However after the Max/Min's the values get a little crazy. It seems for the very recent candles (about 0-30) RviMax will be set to ANY local peak (even if clearly below the actual 300 bar max) and will continue to post lower and lower values until it reaches 0.00. Once the RVI returns to positive territory, RviMax begins to follow RVI back up again.
I cannot see why the actual max/min values in the array are ignored in favor of less extreme values for the most recent bars. I suspect this has something to do with how I set up the array (RVIArray) or with how I used ArrayMaximum/ArrayMinimum, but I can't say for sure. Does anyone have any idea?
I have attached the mql4 file and picture outlining the issue.