Settings = {
Name = "*StohRSI",
round = «off»,
Period = 5,
Per_K = 9,
PeriodSO = 5,
Shift = 3,
VType = «Close», --Open, High, Low, Close, Volume, Median, Typical, Weighted, Difference
line = {
{Name = «RSI», Type = TYPE_LINE, Color = RGB(255, 255, 128)},
{Name = «SO», Type = TYPE_LINE, Color = RGB(255, 0, 0)},
{Name = «Sign», Type = TYPE_LINE, Color = RGB(128, 255, 128)},
{Name = «line 20», Type = TYPE_LINE, Color = RGB(0, 128, 255)},
{Name = «line 80», Type = TYPE_LINE, Color = RGB(0, 128, 255)}
}
}
function Init()
func = RSI()
return #Settings.line
end
function OnCalculate(Index)
if not CandleExist(Index) then
return nil
end
return func(Index, Settings)
end
function RSI() --Relative Strength I(«RSI»)
local Up = {}
local Down = {}
local val_Up = {}
local val_Down = {}
local K_MA1=MA()
local K_MA2=MA()
local D_MA=MA()
local proSO={}
local Out = {}
return function (I, Fsettings, ds)
local Fsettings=(Fsettings or {})
local P = (Fsettings.Period or 14)
local PK = (Fsettings.Per_K or 5)
local PerSO = (Fsettings.PeriodSO or 5)
local S = (Fsettings.Shift or 3)
local PD = (Fsettings.Period_D or 3)
local VT = (Fsettings.VType or «Close»)
local R = (Fsettings.round or «off»)
local MD = (Fsettings.Metod_D or «SMA»)
local M = (Fsettings.Metod or «SMA»)
if I <=PerSO then
Up[I] = 0
Down[I] = 0
end
if I>PerSO then
local Val = Value(I,«T»,ds)
local ValPrev = Value(I-1,VT,ds)
if ValPrev < Val then
Up[I] = Val — ValPrev
else
Up[I] = 0
end
if ValPrev > Val then
Down[I] = ValPrev — Val
else
Down[I] = 0
end
if (I == P) or (I == P+1) then
local sumU = 0
local sumD = 0
for i = I-P+1, I do
sumU = sumU + Up[i]
sumD = sumD + Down[i]
end
val_Up[I] = sumU/P
val_Down[I] = sumD/P
end
if I > P+1 then
val_Up[I] = (val_Up[I-1] * (P-1) + Up[I]) / P
val_Down[I] = (val_Down[I-1] * (P-1) + Down[I]) / P
Out[I] = 100 / (1 + (val_Down[I] / val_Up[I]))
end
end
if I > PK*2 then
RsiOut=D_MA(I,{Period=PK, Metod = M, VType=«Any», round=R}, Out)
end
_,_,proSO[I]= MaxMin(I,5,ds,3)
if I>=(PK+3-1) then
SignSO=D_MA(I, {Period=3, Metod = «SMA», VType=«Any», round=«off»}, proSO)
end
return rounding(RsiOut, 4),rounding(proSO[I], 4),rounding(SignSO, 4),rounding(Out[I], 4)
end
end
-------------------------------------------------------
-------------------------------------------------------
function MA() --Moving Average («MA»)
local t_SMA = F_SMA()
local t_EMA = F_EMA()
return function(I, Fsettings, ds)
local Out = nil
local Fsettings=(Fsettings or {})
local P = (Fsettings.Period or 9)
local M = (Fsettings.Metod or «EMA»)
local VT = (Fsettings.VType or «Close»)
local R = (Fsettings.round or «off»)
if M == «SMA» then
Out = t_SMA(I, P, VT, ds, R)
elseif M == «EMA» then
Out = t_EMA(I, P, VT, ds, R)
else
Out = nil
end
return rounding(Out, R)
end
end
------------------------------------------------------
function MaxMin(ind,Pk,ds,Sk)
if ind < Pk+Sk then
return nil
else
local suCM=0
local suMM=0
for i = ind — Sk+1, ind do
MAX = Value(i-Pk+1,«High»,ds)
MIN = Value(i-Pk+1,«Low»,ds)
for k = 0, Pk-1 do
MAX=math.max(MAX,Value(i-k,«High»,ds))
MIN=math.min(MIN,Value(i-k,«Low»,ds))
end
--message('тран:'..OutWR,1)
suCM=suCM+(Value(i, «Close», ds)-MIN)
suMM=suMM+(MAX-MIN)
end
local TenKu=(MAX+MIN)/2
local OutWR=100*(Value(ind,«Close», ds)-MIN)/(MAX-MIN)
local proKol =100*suCM/suMM
local wpr = ((MAX — Value(ind,«Close», ds)) / (MAX — MIN)) * (-100)
return rounding(TenKu, 6),rounding(OutWR, 6),rounding(proKol, 6)
end
end
------------------------------------------------------------------
function F_SMA()
return function (I, Period, VType, ds, R)
local Out = nil
if I >= Period then
local sum = 0
for i = I-Period+1, I do
sum = sum +Value(i, VType, ds)
end
Out = sum/Period
end
return rounding(Out,R)
end
end
---------------------------------------------------------
function F_EMA()
local EMA_TMP={}
return function(I, Period, VType, ds, R)
local Out = nil
if I == 1 then
EMA_TMP[I]=rounding(Value(I, VType, ds),R)
else
EMA_TMP[I]=rounding((EMA_TMP[I-1]*(Period-1)+2*Value(I, VType, ds)) / (Period+1),R)
end
if I >= Period then
Out = EMA_TMP[I]
end
return rounding(Out,R)
end
end
-------------------------------------------------------
function Value(I,VType,ds)
local Out = nil
VType=(VType and string.upper(string.sub(VType,1,1))) or «A»
if VType == «O» then --Open
Out = (O and O(I)) or (ds and ds:O(I))
elseif VType == «H» then --High
Out = (H and H(I)) or (ds and ds:H(I))
elseif VType == «L» then --Low
Out = (L and L(I)) or (ds and ds:L(I))
elseif VType == «C» then --Close
Out = (C and C(I)) or (ds and ds:C(I))
elseif VType == «V» then --Volume
Out = (V and V(I)) or (ds and ds:V(I))
elseif VType == «M» then --Median
Out = ((Value(I,«H»,ds) + Value(I,«L»,ds)) / 2)
elseif VType == «T» then --Typical
Out = ((Value(I,«M»,ds) * 2 + Value(I,«C»,ds))/3)
elseif VType == «W» then --Weighted
Out = ((Value(I,«T»,ds) * 3 + Value(I,«O»,ds))/4)
elseif VType == «D» then --Difference
Out = (Value(I,«H»,ds) — Value(I,«L»,ds))
elseif VType == «A» then --Any
if ds then Out = ds[I] else Out = nil end
end
return Out
end
function rounding(num, round)
if round and string.upper(round)== «ON» then round=0 end
if num and tonumber(round) then
local mult = 10^round
if num >= 0 then return math.floor(num * mult + 0.5) / mult
else return math.ceil(num * mult — 0.5) / mult end
else return num end
end
Сохранить в файл с расширением lua
Например StohRsi,lua
Файл поместиь в папку Luaindicators
Glago, Если квик 8, то у меня он на линуксе через вине. Скрипты луа не правил и они работают нормально и после обновления. Как 8-ка работает на виндовозе не проверял.
Settings = {
Name = "*StohRSI",
round = «off»,
Period = 5,
Per_K = 9,
PeriodSO = 5,
Shift = 3,
VType = «Close», --Open, High, Low, Close, Volume, Median, Typical, Weighted, Difference
line = {
{Name = «RSI», Type = TYPE_LINE, Color = RGB(255, 255, 128)},
{Name = «SO», Type = TYPE_LINE, Color = RGB(255, 0, 0)},
{Name = «Sign», Type = TYPE_LINE, Color = RGB(128, 255, 128)},
{Name = «line 20», Type = TYPE_LINE, Color = RGB(0, 128, 255)},
{Name = «line 80», Type = TYPE_LINE, Color = RGB(0, 128, 255)}
}
}
function Init()
func = RSI()
return #Settings.line
end
function OnCalculate(Index)
if not CandleExist(Index) then
return nil
end
return func(Index, Settings)
end
function RSI() --Relative Strength I(«RSI»)
local Up = {}
local Down = {}
local val_Up = {}
local val_Down = {}
local K_MA1=MA()
local K_MA2=MA()
local D_MA=MA()
local proSO={}
local Out = {}
return function (I, Fsettings, ds)
local Fsettings=(Fsettings or {})
local P = (Fsettings.Period or 14)
local PK = (Fsettings.Per_K or 5)
local PerSO = (Fsettings.PeriodSO or 5)
local S = (Fsettings.Shift or 3)
local PD = (Fsettings.Period_D or 3)
local VT = (Fsettings.VType or «Close»)
local R = (Fsettings.round or «off»)
local MD = (Fsettings.Metod_D or «SMA»)
local M = (Fsettings.Metod or «SMA»)
if I <=PerSO then
Up[I] = 0
Down[I] = 0
end
if I>PerSO then
local Val = Value(I,«T»,ds)
local ValPrev = Value(I-1,VT,ds)
if ValPrev < Val then
Up[I] = Val — ValPrev
else
Up[I] = 0
end
if ValPrev > Val then
Down[I] = ValPrev — Val
else
Down[I] = 0
end
if (I == P) or (I == P+1) then
local sumU = 0
local sumD = 0
for i = I-P+1, I do
sumU = sumU + Up[i]
sumD = sumD + Down[i]
end
val_Up[I] = sumU/P
val_Down[I] = sumD/P
end
if I > P+1 then
val_Up[I] = (val_Up[I-1] * (P-1) + Up[I]) / P
val_Down[I] = (val_Down[I-1] * (P-1) + Down[I]) / P
Out[I] = 100 / (1 + (val_Down[I] / val_Up[I]))
end
end
if I > PK*2 then
RsiOut=D_MA(I,{Period=PK, Metod = M, VType=«Any», round=R}, Out)
end
_,_,proSO[I]= MaxMin(I,5,ds,3)
if I>=(PK+3-1) then
SignSO=D_MA(I, {Period=3, Metod = «SMA», VType=«Any», round=«off»}, proSO)
end
return rounding(RsiOut, 4),rounding(proSO[I], 4),rounding(SignSO, 4),rounding(Out[I], 4)
end
end
-------------------------------------------------------
-------------------------------------------------------
function MA() --Moving Average («MA»)
local t_SMA = F_SMA()
local t_EMA = F_EMA()
return function(I, Fsettings, ds)
local Out = nil
local Fsettings=(Fsettings or {})
local P = (Fsettings.Period or 9)
local M = (Fsettings.Metod or «EMA»)
local VT = (Fsettings.VType or «Close»)
local R = (Fsettings.round or «off»)
if M == «SMA» then
Out = t_SMA(I, P, VT, ds, R)
elseif M == «EMA» then
Out = t_EMA(I, P, VT, ds, R)
else
Out = nil
end
return rounding(Out, R)
end
end
------------------------------------------------------
function MaxMin(ind,Pk,ds,Sk)
if ind < Pk+Sk then
return nil
else
local suCM=0
local suMM=0
for i = ind — Sk+1, ind do
MAX = Value(i-Pk+1,«High»,ds)
MIN = Value(i-Pk+1,«Low»,ds)
for k = 0, Pk-1 do
MAX=math.max(MAX,Value(i-k,«High»,ds))
MIN=math.min(MIN,Value(i-k,«Low»,ds))
end
--message('тран:'..OutWR,1)
suCM=suCM+(Value(i, «Close», ds)-MIN)
suMM=suMM+(MAX-MIN)
end
local TenKu=(MAX+MIN)/2
local OutWR=100*(Value(ind,«Close», ds)-MIN)/(MAX-MIN)
local proKol =100*suCM/suMM
local wpr = ((MAX — Value(ind,«Close», ds)) / (MAX — MIN)) * (-100)
return rounding(TenKu, 6),rounding(OutWR, 6),rounding(proKol, 6)
end
end
------------------------------------------------------------------
function F_SMA()
return function (I, Period, VType, ds, R)
local Out = nil
if I >= Period then
local sum = 0
for i = I-Period+1, I do
sum = sum +Value(i, VType, ds)
end
Out = sum/Period
end
return rounding(Out,R)
end
end
---------------------------------------------------------
function F_EMA()
local EMA_TMP={}
return function(I, Period, VType, ds, R)
local Out = nil
if I == 1 then
EMA_TMP[I]=rounding(Value(I, VType, ds),R)
else
EMA_TMP[I]=rounding((EMA_TMP[I-1]*(Period-1)+2*Value(I, VType, ds)) / (Period+1),R)
end
if I >= Period then
Out = EMA_TMP[I]
end
return rounding(Out,R)
end
end
-------------------------------------------------------
function Value(I,VType,ds)
local Out = nil
VType=(VType and string.upper(string.sub(VType,1,1))) or «A»
if VType == «O» then --Open
Out = (O and O(I)) or (ds and ds:O(I))
elseif VType == «H» then --High
Out = (H and H(I)) or (ds and ds:H(I))
elseif VType == «L» then --Low
Out = (L and L(I)) or (ds and ds:L(I))
elseif VType == «C» then --Close
Out = (C and C(I)) or (ds and ds:C(I))
elseif VType == «V» then --Volume
Out = (V and V(I)) or (ds and ds:V(I))
elseif VType == «M» then --Median
Out = ((Value(I,«H»,ds) + Value(I,«L»,ds)) / 2)
elseif VType == «T» then --Typical
Out = ((Value(I,«M»,ds) * 2 + Value(I,«C»,ds))/3)
elseif VType == «W» then --Weighted
Out = ((Value(I,«T»,ds) * 3 + Value(I,«O»,ds))/4)
elseif VType == «D» then --Difference
Out = (Value(I,«H»,ds) — Value(I,«L»,ds))
elseif VType == «A» then --Any
if ds then Out = ds[I] else Out = nil end
end
return Out
end
function rounding(num, round)
if round and string.upper(round)== «ON» then round=0 end
if num and tonumber(round) then
local mult = 10^round
if num >= 0 then return math.floor(num * mult + 0.5) / mult
else return math.ceil(num * mult — 0.5) / mult end
else return num end
end
Сохранить в файл с расширением lua
Например StohRsi,lua
Файл поместиь в папку Luaindicators
Имя файла должно быть с точкой: StohRsi.lua
drive.google.com/file/d/1TLUgJzCnvseGZFChY0IdOCAkiQUj98Sl/view?usp=sharing
Если не получится сообщи куда выслать
Eskware, там просит доступ.
Если не трудно на bukinistufa@gmail.com скиньте. Пожалуйста.