-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRSIDivergence.lua
68 lines (53 loc) · 1.94 KB
/
RSIDivergence.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- check for RSI divergence
-- 1 for bullish divergence, -1 for bearish divergence
function Init()
indicator:name("RSIDivergence");
indicator:description("RSI Divergence");
indicator:requiredSource(core.Bar);
indicator:type(core.Oscillator);
indicator:setTag("group", "Classic Oscillators");
indicator.parameters:addGroup("Calculation");
indicator.parameters:addInteger("rsiN", "Number of RSI periods", "Number of RSI periods", 14, 2, 1000);
indicator.parameters:addInteger("bbN", "Number of BB periods", "Number of BB periods", 20, 2, 1000);
indicator.parameters:addInteger("bbDiv", "BB Divs", "BB Divs", 2, 1, 10);
indicator.parameters:addGroup("Style");
indicator.parameters:addColor("rsid", "Line color", "Line color", core.rgb(255, 0, 0));
end
-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- Parameters block
local rsiN;
local bbN;
local bbDiv;
local first;
local source = nil;
-- Streams block
local RSI = nil;
local BB = nil;
local RSID = nil;
-- Routine
function Prepare()
rsiN = instance.parameters.rsiN;
bbN = instance.parameters.bbN;
bbDiv = instance.parameters.bbDiv;
source = instance.source;
local name = profile:id() .. "(" .. source:name() .. ", " .. rsiN .. ")";
instance:name(name);
RSI = core.indicators:create("RSI", source.close, rsiN);
BB = core.indicators:create("BB", source.close, bbN, bbDiv);
first = math.max(RSI.DATA:first(), BB.DATA:first()) + 1;
RSID = instance:addStream("RSID", core.Line, name, "RSID", instance.parameters.rsid, first);
require("RSIDState");
RSID:addLevel(-0.9);
RSID:addLevel(0.9);
RSIDState.init(source, RSI, BB);
--Thisinit(source, RSI, BB);
end
-- Indicator calculation routine
function Update(period, mode)
RSI:update(mode);
BB:update(mode);
RSID[period] = RSIDState.update(period);
--RSID[period] = Thisupdate(period);
end
--