Help confirm simple code operation

 

Hi forum,

 

Many thanks for the information I've sucked from you thus far.

 

Let me precede this post by stating that I am a beginner, and only learning.  The code below is not an EA, or even part of one. I just want to confirm some VERY basic code, and that it is actually doing what I intend.

 

I'm doing a simple exercise of comparing values of two time periods.  Eg.  Candle 1 and Candle 2.  That is, the most recent complete candle, and the one before it.  (Correct?)

 

Am I right to think that if I use the RSI function (or any function for that matter, MACD, etc), I need to use the "shift" property to specify which time period I want to work on?

 

I'd really appreciate it if someone would be kind enough to confirm if the code below does what I am expecting, or if my understanding is mislead.

 

I expect the code will retrieve the RSI value for candle 1, then candle 2, then will compare and print statements accordingly.  Note the difference in shift values, which is my main point of concern here.

 

Any info would be great. 

 

Cheers,

 

Dan 

 

double Candle_1_Value
double Candle_2_Value

Candle_1_Value = iRSI ( Symbol (), 0, 0, PRICE_TYPICAL, 1 ) ;
Candle_2_Value = iRSI ( Symbol (), 0, 0, PRICE_TYPICAL, 2 ) ;

if ( Candle_1_Value > Candle_2_Value )
        {
        Print ("RSI value is increasing.");
        }

else if ( Candle_1_Value < Candle_2_Value )
        {
        Print ("RSI value is decreasing.");
        }
 
Candle_1_Value = iRSI ( Symbol (), 0, 0, PRICE_TYPICAL, 1 ) ; // period 0 ???
Candle_2_Value = iRSI ( Symbol (), 0, 0, PRICE_TYPICAL, 2 ) ; // period 0 ???
 

Sorry qjol,

 

Does a zero in this field not mean the current chart value is used...?

 

That is to say, if the chart is a 5 minute period, the RSI will calculate on a 5 minute period.  If chart is a 15 minute period, RSI will be 15 minute period, etc...? 

 
double  iRSI(
   string       symbol,           // symbol         First paraeter
   int          timeframe,        // timeframe      Second parameter
   int          period,           // period         third parameter
   int          applied_price,    // applied pricen ...
   int          shift             // shift          ...
   );
 

I see, my mistake......

 

Lets try again. 

 

Say we are working on 30 periods, 15 minute intervals:

 

double Candle_1_Value
double Candle_2_Value

Candle_1_Value = iRSI ( Symbol (), PERIOD_M15, 30, PRICE_TYPICAL, 1 ) ;
Candle_2_Value = iRSI ( Symbol (), PERIOD_M15, 30, PRICE_TYPICAL, 2 ) ;

if ( Candle_1_Value > Candle_2_Value )
        {
        Print ("RSI value is increasing.");
        }

else if ( Candle_1_Value < Candle_2_Value )
        {
        Print ("RSI value is decreasing.");
        }

 

If I want to compare the RSI value of Candle 1 to the RSI value of candle 2, do I do this via the shift function, as above...? 

 

I suppose another way to do the same thing might be:

 

...? 

 

if ( iRSI ( Symbol (), PERIOD_M15, 30, PRICE_TYPICAL, 1 ) > iRSI ( Symbol (), PERIOD_M15, 30, PRICE_TYPICAL, 2 ) )
        {
        Print ("RSI value is increasing.");
        }
else
        {
        Print ("RSI value is decreasing.");
        }

 

Note:  I ask this question in the most basic form, leaving out arguments like "it should be >=" or it should have a check for "==".......

 

Just keen to know if the shift value is what I want for my purposes. 

 

5T3L7H:

double Candle_1_Value
double Candle_2_Value

Candle_1_Value = iRSI ( Symbol (), PERIOD_M15, 30, PRICE_TYPICAL, 1 ) ;
Candle_2_Value = iRSI ( Symbol (), PERIOD_M15, 30, PRICE_TYPICAL, 2 ) ;

if ( Candle_1_Value > Candle_2_Value )
        {
        Print ("RSI value is increasing.");
        }

else if ( Candle_1_Value < Candle_2_Value )
        {
        Print ("RSI value is decreasing.");
        }

If I want to compare the RSI value of Candle 1 to the RSI value of candle 2, do I do this via the shift function, as above...? 


that's right

the question is what you wanna do if it's equal (you didn't cover this possibility in your code above)

5T3L7H:

 

I suppose another way to do the same thing might be:

if ( iRSI ( Symbol (), PERIOD_M15, 30, PRICE_TYPICAL, 1 ) > iRSI ( Symbol (), PERIOD_M15, 30, PRICE_TYPICAL, 2 ) )
        {
        Print ("RSI value is increasing.");
        }
else
        {
        Print ("RSI value is decreasing.or equal");
        }


also right

 

Thanks qjol,

 

That's ok, you answered my question perfectly.

 

I really just wanted to check if shift was the correct value to be changing for this comparison.

 

I'll work out the intricacies of my strategy when my skills are a little better developed...  Just learning for now.

 

;-)

 

Thanks again. 

 

everything is written

Alphabetic Index of MQL4 Functions (600+)

iRSI

double  iRSI(
   string       symbol,           // symbol         
   int          timeframe,        // timeframe      
   int          period,           // period         
   int          applied_price,    // applied pricen 
   int          shift             // shift          
   );


 

I just wasn't 100% sure how the shift function worked...

 

For some reason I had this crazy idea that all periods were still calculated, but the shift value varied the calculation.  I suppose like the effect a weight MA has...

 

Silly, I know...  Hence me double checking things on here!

 

Thanks for the link to WHRoeder's post.  I've bookmarked that one! 

 

To confirm my understanding:

"Shift" defines the period from which the calculated value is returned.

 Shift = "0" Will return the value from the "live" candle.

 Shift = "1" will return the value from the first complete candle.

 Shift = "100" will return the value from 100 candles prior.

 This applies to EA and Indicator functions, of all types.  eg. iMACD, iMA, iRSI, etc.

It doesn't affect calculation as such, only offsets the value being returned by the function.

Correct.......? 

Reason: