Linear Cycles Indicator for ThinkorSwim

J007RMC

J007RMC

Well-known member
2019 Donor
VIP
The exact opposite way to view candles and price action. this indicator shows high vol as red candles near the peak of trend and it shows green candles near the trend bottom all other candles show grey. I Plan to load this up Monday. This is a 3000t chart



Code:
#VM_LinearCycles
#by gROwEx
# TOS Chat room 121216
# growex: Oh..remember..the green bars shows the increase of downside momentum and it tells you to tighten your trailinf stop. Opposite for red ones. Arrows signals to exit the trade..not to open it
# growex: it works better on tick based charts
# AlphaInvestor: No green bars the way it is configured, only arrows Plot S1 and Plot S2, what do I turn on for the green bars?
# growex: AI..no..there is no setting for that...apply it to some volatile chart...for example /cl 2000 tick. Just to see how it looks like
# AlphaInvestor: You are talking about green price bars and red price bars then?
# 15:47 growex: yes
# Harndog, added Paintbars, 121316


script linereg {
input price = hl2;
input period = 20;
def x = BarNumber();
def y = price;
def p = period;
def a = ((Sum(y, p) * Sum(Sqr(x), p)) - (Sum(x, p) * Sum((x * y), p))) / ((p * Sum(Sqr(x), p)) - sqr(Sum(x, p)));
plot line = price-a;
}
def t = 30;
input Paintbars = yes;
def line5 = linereg(hl2,5);
def line6 = linereg(hl2,6);
def line7 = linereg(hl2,7);
def line8 = linereg(hl2,8);
def line9 = linereg(hl2,9);
def line10 = linereg(hl2,10);
def line11 = linereg(hl2,11);
def line12 = linereg(hl2,12);
def line13 = linereg(hl2,13);
def line14 = linereg(hl2,14);
def line15 = linereg(hl2,15);
def line16 = linereg(hl2,16);
def line17 = linereg(hl2,17);
def line18 = linereg(hl2,18);
def line19 = linereg(hl2,19);
def line20 = linereg(hl2,20);
def line21 = linereg(hl2,21);
def line22 = linereg(hl2,22);
def line23 = linereg(hl2,23);
def line24 = linereg(hl2,24);
def line25 = linereg(hl2,25);
def line26 = linereg(hl2,26);
def line27 = linereg(hl2,27);
def line28 = linereg(hl2,28);
def line29 = linereg(hl2,29);
def line30 = linereg(hl2,30);
def line31 = linereg(hl2,31);
def line32 = linereg(hl2,32);
def line33 = linereg(hl2,33);
def line34 = linereg(hl2,34);
def line35 = linereg(hl2,35);
def line36 = linereg(hl2,36);


def line37 = linereg(hl2,37);
def line38 = linereg(hl2,38);
def line39 = linereg(hl2,39);
def line40 = linereg(hl2,40);
def line41 = linereg(hl2,41);
def line42 = linereg(hl2,42);
def line43 = linereg(hl2,43);
def line44 = linereg(hl2,44);
def line45 = linereg(hl2,45);
def line46 = linereg(hl2,46);
def line47 = linereg(hl2,47);
def line48 = linereg(hl2,48);
def line49 = linereg(hl2,49);
def line50 = linereg(hl2,50);
def line51 = linereg(hl2,51);
def line52 = linereg(hl2,52);
def line53 = linereg(hl2,53);
def line54 = linereg(hl2,54);
def line55 = linereg(hl2,55);
def count5 = if line5 > 0 then 1 else -1;
def count6 = if line6 > 0 then 1 else -1;
def count7 = if line7 > 0 then 1 else -1;
def count8 = if line8 > 0 then 1 else -1;
def count9 = if line9 > 0 then 1 else -1;
def count10 = if line10 > 0 then 1 else -1;
def count11 = if line11 > 0 then 1 else -1;
def count12 = if line12 > 0 then 1 else -1;
def count13 = if line13 > 0 then 1 else -1;
def count14 = if line14 > 0 then 1 else -1;
def count15 = if line15 > 0 then 1 else -1;
def count16 = if line16 > 0 then 1 else -1;
def count17 = if line17 > 0 then 1 else -1;
def count18 = if line18 > 0 then 1 else -1;
def count19 = if line19 > 0 then 1 else -1;
def count20 = if line20 > 0 then 1 else -1;
def count21 = if line21 > 0 then 1 else -1;
def count22 = if line22 > 0 then 1 else -1;
def count23 = if line23 > 0 then 1 else -1;
def count24 = if line24 > 0 then 1 else -1;
def count25 = if line25 > 0 then 1 else -1;
def count26 = if line26 > 0 then 1 else -1;
def count27 = if line27 > 0 then 1 else -1;
def count28 = if line28 > 0 then 1 else -1;
def count29 = if line29 > 0 then 1 else -1;
def count30 = if line30> 0 then 1 else -1;
def count31 = if line31 > 0 then 1 else -1;
def count32 = if line32 > 0 then 1 else -1;
def count33 = if line33 > 0 then 1 else -1;
def count34 = if line34 > 0 then 1 else -1;
def count35 = if line35 > 0 then 1 else -1;
def count36 = if line36 > 0 then 1 else -1;
def sum = count5+count6+count7+count8+count9+count10+count11+count12+count13+count14+count15+count16+count17+count18+count19+count20+count21+count22+count23+count24+count25+count26+count27+count28+count29+count30+count31+count32+count33+count34+count35+count36;
def stopup = line5 crosses below line36;
def stopdn = line5 crosses above line36;
def length = 20;
def displace = 10;
input price = close;
def vw = Average(price,length)[-displace];
def count = if price > 0 then count[1]+1 else double.NaN;
def bars = barNumber();
def sample = sample[1] + sqr(price - vw);
def var = sample/count;
def dev = sqrt(var);
def z = (price-vw[displace])/dev[displace];
def data = z;
input alpha = 0.07;
def iTrend = If barnumber() < 7 then data + 2*data[1]
[LIST]
[*]data[2]/4 else(alpha- alpha*alpha/4)*data
[*].5* alpha * alpha * data[1] -
[/LIST]
(alpha - .75 * alpha*alpha) * data[2] + 2
*(1 - alpha) * iTrend[1] -(1 - alpha)
*(1-alpha)*iTrend[2];
plot s1 =  stopup and sum >= t and z >1.5;
s1.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
plot s2 =  stopdn and sum <=-t and z<-1.5;
s2.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_up);
assignPriceColor(if paintbars and sum ==32 then color.dark_red else if sum == -32 then color.dark_green else color.gray);


#End Study
 
K

kelvin

Member
def iTrend = If barnumber() < 7 then data + 2*data[1]

My TOS says: Invalid statement: def at 124:1
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
Seems to be working well on my end
 
R

RascalDog

New member
The following lines from the script aren't valid thinkscript:

  • data[2]/4 else(alpha- alpha*alpha/4)*data
  • .5* alpha * alpha * data[1] -
 
J007RMC

J007RMC

Well-known member
2019 Donor
VIP
Perhaps the coders can take a look this was download through open post on One Note?
 
D

diazlaz

Well-known member
2019 Donor
VIP
here is the completed study:

Ruby:
#VM_LinearCycles
#by gROwEx
# TOS Chat room 121216
# growex: Oh..remember..the green bars shows the increase of downside momentum and it tells you to tighten your trailinf stop. Opposite for red ones. Arrows signals to exit the trade..not to open it
# growex: it works better on tick based charts
# AlphaInvestor: No green bars the way it is configured, only arrows Plot S1 and Plot S2, what do I turn on for the green bars?
# growex: AI..no..there is no setting for that...apply it to some volatile chart...for example /cl 2000 tick. Just to see how it looks like
# AlphaInvestor: You are talking about green price bars and red price bars then?
# 15:47 growex: yes
# Harndog, added Paintbars, 121316
 
 
script linereg {
input price = hl2;
input period = 20;
def x = BarNumber();
def y = price;
def p = period;
def a = ((Sum(y, p) * Sum(Sqr(x), p)) - (Sum(x, p) * Sum((x * y), p))) / ((p * Sum(Sqr(x), p)) - sqr(Sum(x, p))); 
plot line = price-a;
}
def t = 30;
input Paintbars = yes;
def line5 = linereg(hl2,5);
def line6 = linereg(hl2,6);
def line7 = linereg(hl2,7);
def line8 = linereg(hl2,8);
def line9 = linereg(hl2,9);
def line10 = linereg(hl2,10);
def line11 = linereg(hl2,11);
def line12 = linereg(hl2,12);
def line13 = linereg(hl2,13);
def line14 = linereg(hl2,14);
def line15 = linereg(hl2,15);
def line16 = linereg(hl2,16);
def line17 = linereg(hl2,17);
def line18 = linereg(hl2,18);
def line19 = linereg(hl2,19);
def line20 = linereg(hl2,20);
def line21 = linereg(hl2,21);
def line22 = linereg(hl2,22);
def line23 = linereg(hl2,23);
def line24 = linereg(hl2,24);
def line25 = linereg(hl2,25);
def line26 = linereg(hl2,26);
def line27 = linereg(hl2,27);
def line28 = linereg(hl2,28);
def line29 = linereg(hl2,29);
def line30 = linereg(hl2,30);
def line31 = linereg(hl2,31);
def line32 = linereg(hl2,32);
def line33 = linereg(hl2,33);
def line34 = linereg(hl2,34);
def line35 = linereg(hl2,35);
def line36 = linereg(hl2,36);
 
 
def line37 = linereg(hl2,37);
def line38 = linereg(hl2,38);
def line39 = linereg(hl2,39);
def line40 = linereg(hl2,40);
def line41 = linereg(hl2,41);
def line42 = linereg(hl2,42);
def line43 = linereg(hl2,43);
def line44 = linereg(hl2,44);
def line45 = linereg(hl2,45);
def line46 = linereg(hl2,46);
def line47 = linereg(hl2,47);
def line48 = linereg(hl2,48);
def line49 = linereg(hl2,49);
def line50 = linereg(hl2,50);
def line51 = linereg(hl2,51);
def line52 = linereg(hl2,52);
def line53 = linereg(hl2,53);
def line54 = linereg(hl2,54);
def line55 = linereg(hl2,55);
def count5 = if line5 > 0 then 1 else -1;
def count6 = if line6 > 0 then 1 else -1;
def count7 = if line7 > 0 then 1 else -1;
def count8 = if line8 > 0 then 1 else -1;
def count9 = if line9 > 0 then 1 else -1;
def count10 = if line10 > 0 then 1 else -1;
def count11 = if line11 > 0 then 1 else -1;
def count12 = if line12 > 0 then 1 else -1;
def count13 = if line13 > 0 then 1 else -1;
def count14 = if line14 > 0 then 1 else -1;
def count15 = if line15 > 0 then 1 else -1;
def count16 = if line16 > 0 then 1 else -1;
def count17 = if line17 > 0 then 1 else -1;
def count18 = if line18 > 0 then 1 else -1;
def count19 = if line19 > 0 then 1 else -1;
def count20 = if line20 > 0 then 1 else -1;
def count21 = if line21 > 0 then 1 else -1;
def count22 = if line22 > 0 then 1 else -1;
def count23 = if line23 > 0 then 1 else -1;
def count24 = if line24 > 0 then 1 else -1;
def count25 = if line25 > 0 then 1 else -1;
def count26 = if line26 > 0 then 1 else -1;
def count27 = if line27 > 0 then 1 else -1;
def count28 = if line28 > 0 then 1 else -1;
def count29 = if line29 > 0 then 1 else -1;
def count30 = if line30> 0 then 1 else -1;
def count31 = if line31 > 0 then 1 else -1;
def count32 = if line32 > 0 then 1 else -1;
def count33 = if line33 > 0 then 1 else -1;
def count34 = if line34 > 0 then 1 else -1;
def count35 = if line35 > 0 then 1 else -1;
def count36 = if line36 > 0 then 1 else -1;
def sum = count5+count6+count7+count8+count9+count10+count11+count12+count13+count14+count15+count16+count17+count18+count19+count20+count21+count22+count23+count24+count25+count26+count27+count28+count29+count30+count31+count32+count33+count34+count35+count36;
def stopup = line5 crosses below line36;
def stopdn = line5 crosses above line36;
def length = 20;
def displace = 10;
input price = close;
def vw = Average(price,length)[-displace];
def count = if price > 0 then count[1]+1 else double.NaN;
def bars = barNumber();
def sample = sample[1] + sqr(price - vw);
def var = sample/count;
def dev = sqrt(var);
def z = (price-vw[displace])/dev[displace];
def data = z;
input alpha = 0.07;
def iTrend = If barnumber() < 7 then data + 2*data[1]
+ data[2]/4 else(alpha- alpha*alpha/4)*data
+ .5* alpha * alpha * data[1] -
(alpha - .75 * alpha*alpha) * data[2] + 2
*(1 - alpha) * iTrend[1] -(1 - alpha)
*(1-alpha)*iTrend[2];
plot s1 =  stopup and sum >= t and z >1.5;
s1.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
plot s2 =  stopdn and sum <=-t and z<-1.5;
s2.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_up);
assignPriceColor(if paintbars and sum ==32 then color.dark_red else if sum == -32 then color.dark_green else color.gray);
 
#End Study
 

Similar threads

Top