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 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
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
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.
I also made Style and Performance Updates
using subsequently available functionality.
The indicator was revised and updated