Check if SMA is below certain RSI level in MQL5 programming

81 Views Asked by At

I'm new to MQL5 programming and I'm trying to create my first Indicator. I would like to be able to tell if the current moving average is below level 10 in the RSI.

The image below explains what I mean. enter image description here

As you can see in the picture the SMA here has a tick just below RSi level 10. The SMA is the blue line chart. How can I calculate this given I have the RSI as:

int rsiInstance = iRSI(_Symbol, _Period, 14, PRICE_CLOSE);

And the SMA as:

int maInstance = iMA(_Symbol, _Period, 21, 0, MODE_SMA, PRICE_CLOSE);

So basically, a function that just returns true if that blue line touches or is below RSI Level 10 and false otherwise. Thanks for your patience and help.

2

There are 2 best solutions below

1
Mark SdS On

Your code for the iRSI and the iMA only return handles for calling them. Those are their definitions: what parameters should be involved when calculating them? See here

You'll need to create a dynamic array as a buffer and copy the returned values into that array. Then you'll have the actual values available from that array.

0
Bishow Gurung On

I am also not a pro but I think you need to parse the rsi and ima handle into array buffer something like this.

bool checkiMALevel() {
     //RSI Buffer
   int rsiInstance = iRSI(_Symbol, _Period, 14, PRICE_CLOSE);
   double rsiBuffer[];
   CopyBuffer(rsiInstance, 0, 1,3,rsiBuffer); // stores rsi of last 3 candles 
   ArraySetAsSeries(rsiBuffer, true);
   
   //IMA Buffer
   int maInstance = iMA(_Symbol, _Period, 21, 0, MODE_SMA, PRICE_CLOSE); // stores ima of last 3 candles
   double imaBuffer[];
   CopyBuffer(maInstance, 0, 1,3, imaBuffer);
   ArraySetAsSeries(imaBuffer, true);
   
   if (rsiBuffer[0] < 10 && imaBuffer[0] < 10) {
    return true;
   } else {
    return false;
   }
  }

And Call it wherever you want

bool isIMAUnderTenRsi = checkiMALevel();