-
Notifications
You must be signed in to change notification settings - Fork 47
/
AdaptiveCOGSTUDY.ts
66 lines (52 loc) · 1.87 KB
/
AdaptiveCOGSTUDY.ts
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
# AdaptiveCOG
declare upper;
# Daily settings
input price = close;
input COGlength = 10;
input InnerValue = 1.0;
input OuterValue = 1.6;
input ATRLength = 14;
input showClosingPriceLine = NO;
input showPriceBar = YES;
input smooth = 1;
def displacement = (-COGlength / 2) + 1;
def dPrice = price[displacement];
def CMA = if !IsNaN(dPrice) then Average(dPrice, AbsValue(COGlength)) else
CMA[1] + (CMA[1] - CMA[2]);
def ATR = Average(TrueRange(high, close, low), ATRLength);
plot UpperOuterBand = if !IsNaN(price) then CMA + (ATR * OuterValue) else
Double.NaN;
plot LowerOuterBand = if !IsNaN(price) then CMA - (ATR * OuterValue) else
Double.NaN;
plot UpperInnerBand = if !IsNaN(price) then CMA + (ATR * InnerValue) else
Double.NaN;
plot LowerInnerBand = if !IsNaN(price) then CMA - (ATR * InnerValue) else
Double.NaN;
plot Rating = if
close > UpperOuterBand then -1
else if close > UpperInnerBand then -0.5
else if close < LowerInnerBand then 0.5
else if close < LowerOuterBand then 1
else 0;
RATING.Hide();
plot CenterLine = if !IsNaN(price) then CMA else Double.NaN;
CenterLine.DefineColor("CMA", GetColor(1));
CenterLine.DefineColor("Extrapolated", GetColor(0));
CenterLine.AssignValueColor(if !IsNaN(dPrice) then CenterLine.Color("CMA")
else
CenterLine.Color("Extrapolated"));
CenterLine.SetLineWeight(2);
CenterLine.Hide();
CenterLine.SetStyle(Curve.SHORT_DASH);
UpperOuterBand.SetDefaultColor(GetColor(5));
UpperOuterBand.SetLineWeight(2);
LowerOuterBand.SetDefaultColor(GetColor(6));
LowerOuterBand.SetLineWeight(2);
UpperInnerBand.SetDefaultColor(GetColor(5));
UpperInnerBand.SetLineWeight(1);
LowerInnerBand.SetDefaultColor(GetColor(6));
LowerInnerBand.SetLineWeight(1);
# Turn AddClouds off by putting a #-sign at the first position of the lines
AddCloud(UpperOuterBand, UpperInnerBand, Color.RED);
AddCloud(LowerInnerBand, LowerOuterBand, Color.GREEN);
HidePricePlot(!showPriceBar);