MQL5: How do I calculate the upper and lower boundary values for an indicator window

 

Hi all

I use a MA(50) and also overlaid an RSI just to make use of the levels 90, 80, 50, 20 and 10. The signal line color of the RSI I make the same as the background color to make it "disappear". All I am interested in from the RSI is the levels. MA's levels function does not work.

In MQL5, is use the iMA function to determine the values for the past 50 candles. To convert the values to base 0 to 100, I use the formula in the loop (see code below).

This works fine, however, the top and bottom values for the 50 MA values are 0 and 100 (off course). But I'm trying to achieve exactly the same results as in the indicator window. The upper and lower values are not 100 and 0 for an MA(50). The can get pretty high, like 95+ or very low, but my calculated values different.


Can you tell me how I arrive at the same upper and lower values (red arrow) as in the attached screenshot? Either the real value or 100-based.

   double SMAto100Base(void)   
      {
         double         dSMA_Array[];
         double         dSMA_Base100_Array[];
         string         msg = "";
         double         dTotal;
         double         dMax;
         double         dMin;

         ArraySetAsSeries(dSMA_Array, false);
         CopyBuffer(iSMA_Def, 0, 0, iSMA_Period+1, dSMA_Array);

         dTotal = MathSum(dSMA_Array);
         MathRange(dSMA_Array, dMax, dMin);
         
         ArraySetAsSeries(dSMA_Base100_Array, false);
         ArrayResize(dSMA_Base100_Array,iSMA_Period+1);

         for( int i=iSMA_Period; i>=0; --i)
            {
               dSMA_Base100_Array[i] = ((dSMA_Array[i] - dMin) / ((dMax -dMin ) /100 ));
            }
         return dSMA_Array[0];
      }


MACD - Oscillators - MetaTrader 5 Help
MACD - Oscillators - MetaTrader 5 Help
  • www.metatrader5.com
Moving Average Convergence/Divergence (MACD) is a trend-following dynamic indicator. It indicates the correlation between two Moving Averages of a...
 

Error (very serious error) - according to the MQL5 style, the indicator handle must be created ONCE and must be done in OnInit.

Correct it - until you correct this error, it is useless to move on.

 
Vladimir Karputov #:

Error (very serious error) - according to the MQL5 style, the indicator handle must be created ONCE and must be done in OnInit.

Correct it - until you correct this error, it is useless to move on.

Done. 

Question still remains. 

 

If you want to learn both iMA and iRSI in one window - see this option: RSIOnMAOnRSI

RSIOnMAOnRSI

 

Hi Vadimir, interesting stuff. Let me play around with it.

 
Vladimir, your code is copyrighted? How can I use it?
 
Sytze Visser # :
Vladimir, your code is copyrighted? How can I use it?

CodeBase is free editable code.

 
Sytze Visser #:
Vladimir, your code is copyrighted? How can I use it?

It is written in the terms:

§4.6:
"4.6. By submitting any materials to the sections of www.mql5.com for public use, the User automatically grants (or warrants that the owner of such materials has expressly granted MetaQuotes Ltd) MetaQuotes Ltd, its partners and Affiliated Entities the royalty-free, perpetual, irrevocable, non-exclusive right (non-exclusive license) to use, post, store, reproduce, modify, create derivative works from (such as those resulting from translations, adaptations or other optimizations), communicate, publish, publicly perform, publicly display and distribute such materials, worldwide for the full term of any copyright that may exist in such material as stipulated by local laws. The above rights are used for the limited purpose of operating, promoting, and improving the website www.mql5.com. No additional formality, including that in writing, will be required for the rights granted by the User to be recognized. This license shall continue even if You stop using the website www.mql5.com. Before You submit to MetaQuotes Ltd any materials and thus grant this license for their use, make sure You have the necessary rights to do so."

Terms of Use of MQL5.community
Terms of Use of MQL5.community
  • www.mql5.com
Terms of Use of MQL5.community website and different traders services.