Download MetaTrader 5

iRSI

To add comments, please log in or register
Do you have idle PCs? Connect them to MQL5 Cloud Network and earn money!
raloscreek
9
raloscreek 2014.10.30 19:34 

Hello,

I have  code snippets that I think should be identical, but they are not.  I'm using the iRSI function on the 5 minute chart. I want to calc the current RSI and compare to the previous RSI.  So if it was above 70, and is now below 70, that is a sell. 

The first way I tried was (I'm calling this function from OnTick):

void CheckForCross()

{

   double RSI;

   static double RSIPrev;

   if(Volume[0]>1) {

      return;

   }

   RSI=iRSI(NULL,0,14,PRICE_CLOSE,0);

   Print(__FUNCTION__," RSI=",RSI," RSIPrev=",RSIPrev);

   if ((RSI > BuyTrigger) && (RSIPrev < BuyTrigger)) {

      Alert(__FUNCTION__, " RSI Cross Up - Buy");

   }

   if ((RSI < SellTrigger) && (RSIPrev > SellTrigger)) {

      Alert(__FUNCTION__, " RSI Cross Up - Sell");

   }

   RSIPrev=RSI; 

}

 

The second way is this (using the shift in the iRSI call):

 

void CheckForCross()

{

   double RSI;

   double RSIPrev;

   if(Volume[0]>1) {

      return;

   }

     RSI=iRSI(NULL,0,14,PRICE_CLOSE,0);

     RSIPrev=iRSI(NULL,0,14,PRICE_CLOSE,1);


   Print(__FUNCTION__," RSI=",RSI," RSIPrev=",RSIPrev);

   if ((RSI > BuyTrigger) && (RSIPrev < BuyTrigger)) {

      Alert(__FUNCTION__, " RSI Cross Up - Buy");

   }


   if ((RSI < SellTrigger) && (RSIPrev > SellTrigger)) {

      Alert(__FUNCTION__, " RSI Cross Up - Sell");

   }

 

The value for RSIPrev comes out different. I must not understand the shift parm on iRSI.  Can anyone elaborate for me?  My understanding is that the shift moves back one bar and calculates from there.  Isnt that the same as saving the RSI in a static variable?

 

Thanks.... 

James Hodges
3157
James Hodges 2014.10.30 20:51  

The static variable contains what the RSI[0] happened to be when the function ran...

It can change before the end of the candle ... and that end result is saved as it becomes candle 1..

 RSI[1] equals what RSI[0] was on it's very last tick....

If you want a signal that can not change... Make RS1 [1] and RSIPrev [2] not [0] and [1] 

PipPip...Jimdandy 

raloscreek
9
raloscreek 2014.10.30 22:14  
Great. Thanks!
To add comments, please log in or register