• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest May 9th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. Settings = {
2. Name = "*A/D (Accumulation/Distribution)",
3. line = {{
4.         Name = "Horizontal line",
5.         Type = TYPE_LINE,
6.         Color = RGB(140, 140, 140)
7.         },
8.         {
9.         Width = 3,
10.         Name = "A/D_Up",
11.         Type = TYPE_HISTOGRAM,
12.         Color = RGB(0, 206, 0)
13.         },
14.         {
15.         Width = 3,
16.         Name = "A/D_Down",
17.         Type = TYPE_HISTOGRAM,
18.         Color = RGB(221, 44, 44)
19.         }
20.         },
21. Round = "off",
22. Multiply = 1,
23. Horizontal_line="0"
24. }
25.
26. function Init()
28.     return #Settings.line
29. end
30.
31. function OnCalculate(Index)
32. local Out = ConvertValue(Settings, func(Index, Settings))
33. local HL = tonumber(Settings.Horizontal_line)
34.     if Out then
35.         if Out > (HL or 0) then
36.             return HL,Out,nil
37.         else
38.             return HL,nil,Out
39.         end
40.     else
41.         return HL,nil,nil
42.     end
43. end
44.
46.     local tmp = {pp=nil, p=nil}
47.     local it = {p=0, l=0}
48. return function (I, Fsettings, ds)
49.     if I == 1 then
50.         tmp = {pp=nil, p=nil}
51.         it = {p=0, l=0}
52.     end
53.     if CandleExist(I,ds) then
54.         if I~=it.p then
55.             it={p=I, l=it.l+1}
56.             tmp.pp = tmp.p
57.         end
58.         local CLH=(2*GetValueEX(it.p,CLOSE,ds)-GetValueEX(it.p,HIGH,ds) - GetValueEX(it.p,LOW,ds))*GetValueEX(it.p,VOLUME,ds)
59.         local HL=GetValueEX(it.p,HIGH,ds) - GetValueEX(it.p,LOW,ds)
60.         if HL==0 then
61.             tmp.p = tmp.pp or 0
62.         else
63.             tmp.p = CLH/HL + (tmp.pp or 0)
64.         end
65.         if it.l==1 then
66.             if HL == 0 then return 0
67.             else return CLH/HL end
68.         else
69.             return tmp.p
70.         end
71.     end
72. return nil
73. end
74. end
75.
76.
77. SMA,MMA,EMA,WMA,SMMA,VMA = "SMA","MMA","EMA","WMA","SMMA","VMA"
78. OPEN,HIGH,LOW,CLOSE,VOLUME,MEDIAN,TYPICAL,WEIGHTED,DIFFERENCE,ANY = "O","H","L","C","V","M","T","W","D","A"
79.
80. function CandleExist(I,ds)
81. return (type(C)=="function" and C(I)~=nil) or
82.     (type(ds)=="table" and (ds[I]~=nil or (type(ds.Size)=="function" and (I>0) and (I<=ds:Size()))))
83. end
84.
85. function Squeeze(I,P)
86.     return math.fmod(I-1,P+1)
87. end
88.
89. function ConvertValue(T,...)
90. local function r(V, R)
91.     if R and string.upper(R)== "ON" then R=0 end
92.     if V and tonumber(R) then
93.         if V >= 0 then return math.floor(V * 10^R + 0.5) / 10^R
94.         else return math.ceil(V * 10^R - 0.5) / 10^R end
95.     else return V end
96. end
97.     if arg.n > 0 then
98.         for i = 1, arg.n do
99.             arg[i]=arg[i] and r(arg[i] * ((T and T.Multiply) or 1), (T and T.Round) or "off")
100.         end
101.         return unpack(arg)
102.     else return nil end
103. end
104.
105. function GetValueEX(I,VT,ds)
106. VT=(VT and string.upper(string.sub(VT,1,1))) or ANY
107.     if VT == OPEN then          --Open
108.         return (O and O(I)) or (ds and ds:O(I))
109.     elseif VT == HIGH then      --High
110.         return (H and H(I)) or (ds and ds:H(I))
111.     elseif VT == LOW then       --Low
112.         return (L and L(I)) or (ds and ds:L(I))
113.     elseif VT == CLOSE then     --Close
114.         return (C and C(I)) or (ds and ds:C(I))
115.     elseif VT == VOLUME then        --Volume
116.         return (V and V(I)) or (ds and ds:V(I))
117.     elseif VT == MEDIAN then        --Median
118.         return ((GetValueEX(I,HIGH,ds) + GetValueEX(I,LOW,ds)) / 2)
119.     elseif VT == TYPICAL then   --Typical
120.         return ((GetValueEX(I,MEDIAN,ds) * 2 + GetValueEX(I,CLOSE,ds))/3)
121.     elseif VT == WEIGHTED then  --Weighted
122.         return ((GetValueEX(I,TYPICAL,ds) * 3 + GetValueEX(I,OPEN,ds))/4)
123.     elseif VT == DIFFERENCE then    --Difference
124.         return (GetValueEX(I,HIGH,ds) - GetValueEX(I,LOW,ds))
125.     else                            --Any
126.         return (ds and ds[I])
127.     end
128. return nil
129. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?