Page 2 of 3

Re: Stochastic RSI

PostPosted: Sun May 22, 2011 3:24 am
by Apprentice
Post, mq4 code you are using.
So we could see the difference.
Out there is a lot of different versions.

Re: Stochastic RSI

PostPosted: Sun May 22, 2011 10:43 am
by station0524
Here is the code,
Code: Select all
Input Parameters:
RSIPeriod = The RSI Period to use (Default 8)
PeriodK = The Stochastic %K period. (Default 8)
SlowPeriod = The final smoothing (slow) value (Default 3)

Revision History

Version 1.0
* Initial Release

Version 1.1 ( 14 Nov 2007 )
* Fixed bug in HHV/LLV calculations to use current bar.  This avoids values > 100
   
*/   


#property copyright "Copyright © 2007, Bruce Hellstrom (brucehvn)"
#property link      "http: //www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2

#property indicator_level1 20.0
#property indicator_level2 80.0
#property indicator_levelcolor Red
#property indicator_levelwidth 1
#property indicator_levelstyle STYLE_DOT

#define INDICATOR_VERSION "v1.1"


// Input Parameters
extern int RSIPeriod = 8;
extern int PeriodK = 8;
extern int SlowPeriod = 3;

// Buffers
double RSIBuffer[];
double StochBuffer[];
double TempBuffer[];
bool debug = false;


// Other Variables
string ShortName;


/////////////////////////////////////////////////////////////////////
// Custom indicator initialization function
/////////////////////////////////////////////////////////////////////

int init() {

    IndicatorBuffers( 1 );
    SetIndexStyle( 0, DRAW_LINE, STYLE_SOLID, 1 );
    SetIndexBuffer( 0, StochBuffer );
    SetIndexDrawBegin( 0, RSIPeriod );
   
    ShortName = "MT4-StochasticRSI-Oscillator-" + INDICATOR_VERSION + " (" + RSIPeriod + "," + PeriodK + "," + SlowPeriod + ")";
   
    IndicatorShortName( ShortName );
    SetIndexLabel( 0, ShortName );
   
    ArraySetAsSeries( RSIBuffer, true );
    ArraySetAsSeries( TempBuffer, true );
   
    Print( ShortName );
    Print( "Copyright (c) 2007 - Bruce Hellstrom, bhweb@speakeasy.net" );
   
    return( 0 );
}

/////////////////////////////////////////////////////////////////////
// Custom indicator deinitialization function
/////////////////////////////////////////////////////////////////////

int deinit() {
    return( 0 );
}

/////////////////////////////////////////////////////////////////////
// Indicator Logic run on every tick
/////////////////////////////////////////////////////////////////////

int start() {
   
    int counted_bars = IndicatorCounted();
   
    // Check for errors
    if ( counted_bars < 0 ) {
        return( -1 );
    }

    // Last bar will be recounted
    if ( counted_bars > 0 ) {
        counted_bars--;
    }

    // Resize the non-buffer array if necessary
    if ( ArraySize( RSIBuffer ) != ArraySize( StochBuffer ) ) {
        ArraySetAsSeries( RSIBuffer, false );
        ArrayResize( RSIBuffer, ArraySize( StochBuffer ) );
        ArraySetAsSeries( RSIBuffer, true );
    }
   
    if ( ArraySize( TempBuffer ) != ArraySize( StochBuffer ) ) {
        ArraySetAsSeries( TempBuffer, false );
        ArrayResize( TempBuffer, ArraySize( StochBuffer ) );
        ArraySetAsSeries( TempBuffer, true );
    }
   
   
    // Get the upper limit
    int limit = Bars - counted_bars;
   
    for ( int ictr = 0; ictr < limit; ictr++ ) {
        RSIBuffer[ictr] = iRSI( NULL, 0, RSIPeriod, PRICE_CLOSE, ictr );
        if ( debug ) {
            if ( RSIBuffer[ictr] > 100.0 ) {
                Print( "Bar: ", ictr, " RSI: ", RSIBuffer[ictr] );
            }
        }
    }

    for ( ictr = 0; ictr < limit; ictr++ ) {
        double llv = LLV( RSIBuffer, PeriodK, ictr );
        double hhv = HHV( RSIBuffer, PeriodK, ictr );
       
        if ( ( hhv - llv ) > 0 ) {
            TempBuffer[ictr] = ( ( RSIBuffer[ictr] - llv ) /
                                 ( hhv - llv ) ) * 100;
            if ( debug && ictr < 100 ) {
                if ( TempBuffer[ictr] > 100.0 ) {
                    Print( "Bar: ", ictr, " TempBuffer: ", TempBuffer[ictr], " RSI: ", RSIBuffer[ictr], " hhv: ", hhv, " llv:", llv );
                }
            }
        }
    }
   
    for ( ictr = 0; ictr < limit; ictr++ ) {
        StochBuffer[ictr] = iMAOnArray( TempBuffer, 0, SlowPeriod, 0, MODE_EMA, ictr );
    }
   
    return( 0 );
}


double LLV( double& indBuffer[], int Periods, int shift ) {
    double dblRet = 0.0;
    int startindex = shift;
   
    for ( int llvctr = startindex; llvctr < ( startindex + Periods ); llvctr++ ) {
        if ( llvctr == startindex ) {
            dblRet = indBuffer[llvctr];
        }
        dblRet = MathMin( dblRet, indBuffer[llvctr] );
    }
   
    return( dblRet );
}

double HHV( double& indBuffer[], int Periods, int shift ) {
    double dblRet = 0.0;
    int startindex = shift;
   
    for ( int hhvctr = startindex; hhvctr < ( startindex + Periods ); hhvctr++ ) {
        if ( hhvctr == startindex ) {
            dblRet = indBuffer[hhvctr];
        }
        dblRet = MathMax( dblRet, indBuffer[hhvctr] );
    }
   
    return( dblRet );
}

Re: Stochastic RSI

PostPosted: Tue Jul 12, 2011 11:45 pm
by Alexander.Gettinger
Please, see this version of oscillator.

Download:
StochasticRSI.lua
(3.78 KiB) Downloaded 2087 times

Re: Stochastic RSI

PostPosted: Wed Jul 13, 2011 7:18 pm
by Blackcat2
Alexander.Gettinger wrote:Please, see this version of oscillator.

Download:
StochasticRSI.lua

I think it requires another indicator, could you please tell me where I can get it?

Thanks :)

Re: Stochastic RSI

PostPosted: Thu Jul 14, 2011 3:09 am
by sunshine
Please install the Averages indicator
http://www.fxcodebase.com/code/viewtopi ... =17&t=2430

Re: Stochastic RSI

PostPosted: Tue Nov 22, 2011 9:09 am
by JPNWV7
kkhart1935 wrote:I cannot get this to work. I get an error that says to download stochrsi. What am I doing wrong?



I get the same thing

Re: Stochastic RSI

PostPosted: Mon Dec 02, 2013 11:08 am
by Alexander.Gettinger
MQL4 version of Stochastic RSI: viewtopic.php?f=38&t=60051.

Re: Stochastic RSI

PostPosted: Sun Dec 06, 2015 4:35 am
by Apprentice
Compatibility issue Fix. _Alert helper is not longer needed.

Re: Stochastic RSI

PostPosted: Thu Aug 11, 2016 10:25 am
by TxChristopher
Would it be possible for one of you programmers to add a "live" option to this indicator like the "Stochastic with Alert" indicator has? This is a good indicator but the tremendous lag of having to wait for end of turn is especially crippling to it.

The biggest problem with this indicator is once the market starts moving you need to know and waiting for the end of turn often causes losses or missing most of the move, especially in longer time frames obviously because end of turn can be hours away. If this indicator had all the sweet options to alert the trader that the Stochastic with Alert indicator has it would make a huge difference in its usability.

Since they are very similar indicators (but with quite different results often) this would seem like a very easy to do thing.

What say you coders?

Re: Stochastic RSI

PostPosted: Fri Aug 12, 2016 11:23 am
by Apprentice
"live" / "end of turn" option add for "Stochastic RSI with Alert"