Page 1 of 3

Stochastic RSI

PostPosted: Tue Mar 09, 2010 7:36 pm
by Nikolay.Gekht
The indicator was introduced by by Tuschar Chande and Stanley Kroll in December, 1992 Stocks and Commodities' article and combines two indicators RSI and Stochastic.

The Stochastic RSI Oscillator is a momentum indicator which shows the relation of the current RSI value relative to its high/low range over a given number of periods.

The indicator has four parameters:
N - the number of periods for RSI calculation
K - the number of periods to calculate the stochastic fast line
SK - the number of periods to smooth the stochastic fast line (use 1 to do not smooth the fast line)
D - the number of periods to calculate the stochastic slow line

The formula is:
LR = Lowest RSI(PRICE, N) for K periods
HR = Highest RSI(PRICE, N) for K periods
FAST = MVA((RSI(PRICE, N)[now] - LR) / (HR - LR) * 100), SK)
SLOW = MVA(FAST, D)

stochrsi.png


Code: Select all
-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
function Init()
    indicator:name("Stochastic RSI");
    indicator:description("");
    indicator:requiredSource(core.Tick);
    indicator:type(core.Oscillator);

    indicator.parameters:addInteger("N", "Number of periods for RSI", "", 14, 1, 200);
    indicator.parameters:addInteger("K", "%K Stochastic Periods", "", 14, 1, 200);
    indicator.parameters:addInteger("KS", "%K Slowing Periods", "", 5, 1, 200);
    indicator.parameters:addInteger("D", "%D Slowing Stochastic Periods", "", 3, 1, 200);
    indicator.parameters:addColor("K_color", "Color of K", "Color of K", core.rgb(0, 255, 0));
    indicator.parameters:addColor("D_color", "Color of D", "Color of D", core.rgb(255, 0, 0));
end

-- Indicator instance initialization routine

-- Parameters block
local N;
local K;
local KS;
local D;

local firstSKI;
local firstK;
local firstD;
local source = nil;

-- Streams block
local SKI = nil;
local SK = nil;
local SD = nil;
local RSI = nil;
local MVA1 = nil;
local MVA2 = nil;

-- Routine
function Prepare()
    N = instance.parameters.N;
    K = instance.parameters.K;
    KS = instance.parameters.KS;
    D = instance.parameters.D;
    source = instance.source;
    first = source:first();

    RSI = core.indicators:create("RSI", source, N);
    local name = profile:id() .. "(" .. source:name() .. ", " .. N .. ", " .. K .. ", " .. KS ..", " .. D .. ")";
    instance:name(name);
    firstSKI = RSI.DATA:first() + K;
    SKI = instance:addInternalStream(firstSKI, 0);
    MVA1 = core.indicators:create("MVA", SKI, KS);
    firstK = MVA1.DATA:first();
    SK = instance:addStream("K", core.Line, name .. ".K", "K", instance.parameters.K_color, firstK);
    SK:addLevel(20);
    SK:addLevel(50);
    SK:addLevel(80);
    MVA2 = core.indicators:create("MVA", SK, D);
    firstD = MVA2.DATA:first();
    SD = instance:addStream("D", core.Dot, name .. ".D", "D", instance.parameters.D_color, firstD);
end

-- Indicator calculation routine
function Update(period, mode)
    RSI:update(mode);

    if (period >= firstSKI) then
        local min, max;
        local range;
        range = core.rangeTo(period, K);
        min = core.min(RSI.DATA, range);
        max = core.max(RSI.DATA, range);
        if (min == max) then
            SKI[period] = 100;
        else
            SKI[period] = (RSI.DATA[period] - min) / (max - min) * 100;
        end
    end

    MVA1:update(mode);

    if period >= firstK then
        SK[period] = MVA1.DATA[period];
    end

    MVA2:update(mode);

    if (period >= firstD) then
        SD[period] = MVA2.DATA[period];
    end
end


StochRSI.lua
(2.71 KiB) Downloaded 4665 times

Other two version can be found here.
viewtopic.php?f=17&t=8169

p.s. Sorry for delays with publishing new indicators. I'm deep in preparing a new Marketscope release...
p.p.s. I'm already moved to the new release, so, in case anything fails on the previous version - please do not hesitate to report it immediatelly.

Added By Apprentice
Stochastic RSI with Alert.png

This indicator provides Audio / Email Alerts for six signals.
1) OB Zone Cross
2) OS Zone Cross
3) Cental Line Cross
4) Slope change
5) Slope change in OB zone
6) Slope change in OS zone
Stochastic RSI with Alert.lua
(15.8 KiB) Downloaded 2305 times

Dec 5, 2015: Compatibility issue Fix. _Alert helper is not longer needed.

I also made Style and Performance Updates
using subsequently available functionality.

The indicator was revised and updated

Re: Stochastic RSI

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

Re: Stochastic RSI

PostPosted: Tue Mar 01, 2011 9:43 am
by kkhart1935
I get the following error
An error occurred during the calculation of the indicator 'MTF_ STOCHRSI'. The error details: [string "MTF_ StochRSI.lua"]:140: [string "StochRSI.lua"]:219: attempt to call method 'barSize' (a nil value).

Re: Stochastic RSI

PostPosted: Tue Mar 01, 2011 10:07 am
by Apprentice
I tested both MTF indicators.
I can not repeat the bug.

Interesting.
Can you restart the platform.

Re: Stochastic RSI

PostPosted: Tue Apr 26, 2011 3:58 am
by Apprentice
Line Style Option Added.
StochRSI.lua
(3.48 KiB) Downloaded 2736 times

Re: Stochastic RSI

PostPosted: Tue Apr 26, 2011 1:40 pm
by jeisenm
very nice indicator. thanks apprentice.

Re: Stochastic RSI

PostPosted: Wed Apr 27, 2011 7:48 am
by ayatullah
Dear Apprentice

Thank you for adding this indicator.

Is there a possibility of you adding an alert for when the SK line and SD crossover to this indicator?

Thanks

Jawad

Re: Stochastic RSI

PostPosted: Sat May 14, 2011 4:47 pm
by station0524
I do not know why but the indicator seems to be incorrect. When compared to the same indicator on other charting programs like Metatrader and Fib Trader the values that yours produce is not the same. Put them side by side, same chart, same time frame, same settings, yours is the only one that is different.

Re: Stochastic RSI

PostPosted: Sun May 15, 2011 9:41 am
by Apprentice
There are several solutions.
Can you post the version you mention.
(Code or Link)

Re: Stochastic RSI

PostPosted: Sat May 21, 2011 1:13 pm
by station0524
The version I downloaded is the one posted here on this page. Not sure if you want me to post the metatrader versions or yours.