## 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.

### Stochastic RSI

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)

Code: Select all
`-- Indicator profile initialization routine-- Defines indicator profile properties and indicator parametersfunction 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 blocklocal N;local K;local KS;local D;local firstSKI;local firstK;local firstD;local source = nil;-- Streams blocklocal SKI = nil;local SK = nil;local SD = nil;local RSI = nil;local MVA1 = nil;local MVA2 = nil;-- Routinefunction 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 routinefunction 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];    endend`

StochRSI.lua

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.

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

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

using subsequently available functionality.

The indicator was revised and updated
Nikolay.Gekht
FXCodeBase: Base Builder

Posts: 1223
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

### Re: Stochastic RSI

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

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

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

Interesting.
Can you restart the platform.

Apprentice
FXCodeBase: Confirmed User

Posts: 20795
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### Re: Stochastic RSI

StochRSI.lua

Apprentice
FXCodeBase: Confirmed User

Posts: 20795
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### Re: Stochastic RSI

very nice indicator. thanks apprentice.
jeisenm

Posts: 8
Joined: Thu Apr 22, 2010 10:44 am

### Re: Stochastic RSI

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

ayatullah

Posts: 3
Joined: Wed Jan 12, 2011 5:19 pm

### Re: Stochastic RSI

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

There are several solutions.
Can you post the version you mention.

Apprentice
FXCodeBase: Confirmed User

Posts: 20795
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia