Stochastic RSI

Here you can post and download custom indicators. PLEASE: Do not start topics unless you are posting your own indicator, they will be moved to appropriate section even if you do.

Moderator: admin

Stochastic RSI

Postby Nikolay.Gekht » Tue Mar 09, 2010 7:36 pm

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 3559 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 1298 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
Nikolay.Gekht
FXCodeBase: Base Builder
 
Posts: 1222
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Stochastic RSI

Postby kkhart1935 » Tue Mar 01, 2011 9:09 am

I cannot get this to work. I get an error that says to download stochrsi. What am I doing wrong?
kkhart1935
 
Posts: 2
Joined: Tue Mar 01, 2011 9:03 am

Re: Stochastic RSI

Postby kkhart1935 » Tue Mar 01, 2011 9:43 am

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).
kkhart1935
 
Posts: 2
Joined: Tue Mar 01, 2011 9:03 am

Re: Stochastic RSI

Postby Apprentice » Tue Mar 01, 2011 10:07 am

I tested both MTF indicators.
I can not repeat the bug.

Interesting.
Can you restart the platform.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 19458
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Stochastic RSI

Postby Apprentice » Tue Apr 26, 2011 3:58 am

Line Style Option Added.
StochRSI.lua
(3.48 KiB) Downloaded 1832 times
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 19458
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Stochastic RSI

Postby jeisenm » Tue Apr 26, 2011 1:40 pm

very nice indicator. thanks apprentice.
jeisenm
 
Posts: 8
Joined: Thu Apr 22, 2010 10:44 am

Re: Stochastic RSI

Postby ayatullah » Wed Apr 27, 2011 7:48 am

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
ayatullah
 
Posts: 3
Joined: Wed Jan 12, 2011 5:19 pm

Re: Stochastic RSI

Postby station0524 » Sat May 14, 2011 4:47 pm

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.
station0524
 
Posts: 25
Joined: Sat May 14, 2011 4:30 pm

Re: Stochastic RSI

Postby Apprentice » Sun May 15, 2011 9:41 am

There are several solutions.
Can you post the version you mention.
(Code or Link)
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 19458
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Stochastic RSI

Postby station0524 » Sat May 21, 2011 1:13 pm

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.
station0524
 
Posts: 25
Joined: Sat May 14, 2011 4:30 pm

Next

Return to Custom Indicators

Who is online

Users browsing this forum: No registered users and 15 guests