Ehlers Stochastic CG Oscillator [LazyBear] For ThinkOrSwim

autoloader

Member
VIP
Author states:
Ehlers likes the idea behind StochRSI so much, he dedicated a full chapter in his book (linked below) on how stoch works with his "superlative" (his words, not mine) indicators. This is stoch of his CG oscillator.

Standard stochastic oscillator uses fixed period for calculations and does not adjust to the constantly changing market cycle length. Stochastic CG Oscillator does not have such a drawback.

Use this like normal stochRSI osc
fRnrKC3.png


This one caught my interest because of the Ehlers reference.
https://www.tradingview.com/script/aX0yTFaA-Ehlers-Stochastic-CG-Oscillator-LazyBear/
 
Last edited by a moderator:
This one caught my interest because of the Ehlers reference.
https://www.tradingview.com/script/aX0yTFaA-Ehlers-Stochastic-CG-Oscillator-LazyBear/

19J9MNu.png


Code:
//
// @author LazyBear
//
// List of my public indicators: http://bit.ly/1LQaPK8
// List of my app-store indicators: http://blog.tradingview.com/?p=970
//
study("Ehlers Stochastic CG Oscillator [LazyBear]", shorttitle="ESCGO_LB", overlay=false, precision=3)
src=input(hl2, title="Source")
length=input(8, title="Length", minval=1, maxval=100)
lvls=input(0.8, title="OB/OS Level")
fr=input(true, title="Fill Osc/Trigger region")
nm0=0, dm0=0
nm1=1<=length ? (nm0+(1 + 0) * src[0]) : nm0, dm1=1<=length ? dm0+src[0] : dm0
nm2=2<=length ? (nm1+(1 + 1) * src[1]) : nm1, dm2=2<=length ? dm1+src[1] : dm1
nm3=3<=length ? (nm2+(1 + 2) * src[2]) : nm2, dm3=3<=length ? dm2+src[2] : dm2
nm4=4<=length ? (nm3+(1 + 3) * src[3]) : nm3, dm4=4<=length ? dm3+src[3] : dm3
nm5=5<=length ? (nm4+(1 + 4) * src[4]) : nm4, dm5=5<=length ? dm4+src[4] : dm4
nm6=6<=length ? (nm5+(1 + 5) * src[5]) : nm5, dm6=6<=length ? dm5+src[5] : dm5
nm7=7<=length ? (nm6+(1 + 6) * src[6]) : nm6, dm7=7<=length ? dm6+src[6] : dm6
nm8=8<=length ? (nm7+(1 + 7) * src[7]) : nm7, dm8=8<=length ? dm7+src[7] : dm7
nm9=9<=length ? (nm8+(1 + 8) * src[8]) : nm8, dm9=9<=length ? dm8+src[8] : dm8
nm10=10<=length ? (nm9+(1 + 9) * src[9]) : nm9, dm10=10<=length ? dm9+src[9] : dm9
nm11=11<=length ? (nm10+(1 + 10) * src[10]) : nm10, dm11=11<=length ? dm10+src[10] : dm10
nm12=12<=length ? (nm11+(1 + 11) * src[11]) : nm11, dm12=12<=length ? dm11+src[11] : dm11
nm13=13<=length ? (nm12+(1 + 12) * src[12]) : nm12, dm13=13<=length ? dm12+src[12] : dm12
nm14=14<=length ? (nm13+(1 + 13) * src[13]) : nm13, dm14=14<=length ? dm13+src[13] : dm13
nm15=15<=length ? (nm14+(1 + 14) * src[14]) : nm14, dm15=15<=length ? dm14+src[14] : dm14
nm16=16<=length ? (nm15+(1 + 15) * src[15]) : nm15, dm16=16<=length ? dm15+src[15] : dm15
nm17=17<=length ? (nm16+(1 + 16) * src[16]) : nm16, dm17=17<=length ? dm16+src[16] : dm16
nm18=18<=length ? (nm17+(1 + 17) * src[17]) : nm17, dm18=18<=length ? dm17+src[17] : dm17
nm19=19<=length ? (nm18+(1 + 18) * src[18]) : nm18, dm19=19<=length ? dm18+src[18] : dm18
nm20=20<=length ? (nm19+(1 + 19) * src[19]) : nm19, dm20=20<=length ? dm19+src[19] : dm19
nm21=21<=length ? (nm20+(1 + 20) * src[20]) : nm20, dm21=21<=length ? dm20+src[20] : dm20
nm22=22<=length ? (nm21+(1 + 21) * src[21]) : nm21, dm22=22<=length ? dm21+src[21] : dm21
nm23=23<=length ? (nm22+(1 + 22) * src[22]) : nm22, dm23=23<=length ? dm22+src[22] : dm22
nm24=24<=length ? (nm23+(1 + 23) * src[23]) : nm23, dm24=24<=length ? dm23+src[23] : dm23
nm25=25<=length ? (nm24+(1 + 24) * src[24]) : nm24, dm25=25<=length ? dm24+src[24] : dm24
nm26=26<=length ? (nm25+(1 + 25) * src[25]) : nm25, dm26=26<=length ? dm25+src[25] : dm25
nm27=27<=length ? (nm26+(1 + 26) * src[26]) : nm26, dm27=27<=length ? dm26+src[26] : dm26
nm28=28<=length ? (nm27+(1 + 27) * src[27]) : nm27, dm28=28<=length ? dm27+src[27] : dm27
nm29=29<=length ? (nm28+(1 + 28) * src[28]) : nm28, dm29=29<=length ? dm28+src[28] : dm28
nm30=30<=length ? (nm29+(1 + 29) * src[29]) : nm29, dm30=30<=length ? dm29+src[29] : dm29
nm31=31<=length ? (nm30+(1 + 30) * src[30]) : nm30, dm31=31<=length ? dm30+src[30] : dm30
nm32=32<=length ? (nm31+(1 + 31) * src[31]) : nm31, dm32=32<=length ? dm31+src[31] : dm31
nm33=33<=length ? (nm32+(1 + 32) * src[32]) : nm32, dm33=33<=length ? dm32+src[32] : dm32
nm34=34<=length ? (nm33+(1 + 33) * src[33]) : nm33, dm34=34<=length ? dm33+src[33] : dm33
nm35=35<=length ? (nm34+(1 + 34) * src[34]) : nm34, dm35=35<=length ? dm34+src[34] : dm34
nm36=36<=length ? (nm35+(1 + 35) * src[35]) : nm35, dm36=36<=length ? dm35+src[35] : dm35
nm37=37<=length ? (nm36+(1 + 36) * src[36]) : nm36, dm37=37<=length ? dm36+src[36] : dm36
nm38=38<=length ? (nm37+(1 + 37) * src[37]) : nm37, dm38=38<=length ? dm37+src[37] : dm37
nm39=39<=length ? (nm38+(1 + 38) * src[38]) : nm38, dm39=39<=length ? dm38+src[38] : dm38
nm40=40<=length ? (nm39+(1 + 39) * src[39]) : nm39, dm40=40<=length ? dm39+src[39] : dm39
nm41=41<=length ? (nm40+(1 + 40) * src[40]) : nm40, dm41=41<=length ? dm40+src[40] : dm40
nm42=42<=length ? (nm41+(1 + 41) * src[41]) : nm41, dm42=42<=length ? dm41+src[41] : dm41
nm43=43<=length ? (nm42+(1 + 42) * src[42]) : nm42, dm43=43<=length ? dm42+src[42] : dm42
nm44=44<=length ? (nm43+(1 + 43) * src[43]) : nm43, dm44=44<=length ? dm43+src[43] : dm43
nm45=45<=length ? (nm44+(1 + 44) * src[44]) : nm44, dm45=45<=length ? dm44+src[44] : dm44
nm46=46<=length ? (nm45+(1 + 45) * src[45]) : nm45, dm46=46<=length ? dm45+src[45] : dm45
nm47=47<=length ? (nm46+(1 + 46) * src[46]) : nm46, dm47=47<=length ? dm46+src[46] : dm46
nm48=48<=length ? (nm47+(1 + 47) * src[47]) : nm47, dm48=48<=length ? dm47+src[47] : dm47
nm49=49<=length ? (nm48+(1 + 48) * src[48]) : nm48, dm49=49<=length ? dm48+src[48] : dm48
nm50=50<=length ? (nm49+(1 + 49) * src[49]) : nm49, dm50=50<=length ? dm49+src[49] : dm49
nm51=51<=length ? (nm50+(1 + 50) * src[50]) : nm50, dm51=51<=length ? dm50+src[50] : dm50
nm52=52<=length ? (nm51+(1 + 51) * src[51]) : nm51, dm52=52<=length ? dm51+src[51] : dm51
nm53=53<=length ? (nm52+(1 + 52) * src[52]) : nm52, dm53=53<=length ? dm52+src[52] : dm52
nm54=54<=length ? (nm53+(1 + 53) * src[53]) : nm53, dm54=54<=length ? dm53+src[53] : dm53
nm55=55<=length ? (nm54+(1 + 54) * src[54]) : nm54, dm55=55<=length ? dm54+src[54] : dm54
nm56=56<=length ? (nm55+(1 + 55) * src[55]) : nm55, dm56=56<=length ? dm55+src[55] : dm55
nm57=57<=length ? (nm56+(1 + 56) * src[56]) : nm56, dm57=57<=length ? dm56+src[56] : dm56
nm58=58<=length ? (nm57+(1 + 57) * src[57]) : nm57, dm58=58<=length ? dm57+src[57] : dm57
nm59=59<=length ? (nm58+(1 + 58) * src[58]) : nm58, dm59=59<=length ? dm58+src[58] : dm58
nm60=60<=length ? (nm59+(1 + 59) * src[59]) : nm59, dm60=60<=length ? dm59+src[59] : dm59
nm61=61<=length ? (nm60+(1 + 60) * src[60]) : nm60, dm61=61<=length ? dm60+src[60] : dm60
nm62=62<=length ? (nm61+(1 + 61) * src[61]) : nm61, dm62=62<=length ? dm61+src[61] : dm61
nm63=63<=length ? (nm62+(1 + 62) * src[62]) : nm62, dm63=63<=length ? dm62+src[62] : dm62
nm64=64<=length ? (nm63+(1 + 63) * src[63]) : nm63, dm64=64<=length ? dm63+src[63] : dm63
nm65=65<=length ? (nm64+(1 + 64) * src[64]) : nm64, dm65=65<=length ? dm64+src[64] : dm64
nm66=66<=length ? (nm65+(1 + 65) * src[65]) : nm65, dm66=66<=length ? dm65+src[65] : dm65
nm67=67<=length ? (nm66+(1 + 66) * src[66]) : nm66, dm67=67<=length ? dm66+src[66] : dm66
nm68=68<=length ? (nm67+(1 + 67) * src[67]) : nm67, dm68=68<=length ? dm67+src[67] : dm67
nm69=69<=length ? (nm68+(1 + 68) * src[68]) : nm68, dm69=69<=length ? dm68+src[68] : dm68
nm70=70<=length ? (nm69+(1 + 69) * src[69]) : nm69, dm70=70<=length ? dm69+src[69] : dm69
nm71=71<=length ? (nm70+(1 + 70) * src[70]) : nm70, dm71=71<=length ? dm70+src[70] : dm70
nm72=72<=length ? (nm71+(1 + 71) * src[71]) : nm71, dm72=72<=length ? dm71+src[71] : dm71
nm73=73<=length ? (nm72+(1 + 72) * src[72]) : nm72, dm73=73<=length ? dm72+src[72] : dm72
nm74=74<=length ? (nm73+(1 + 73) * src[73]) : nm73, dm74=74<=length ? dm73+src[73] : dm73
nm75=75<=length ? (nm74+(1 + 74) * src[74]) : nm74, dm75=75<=length ? dm74+src[74] : dm74
nm76=76<=length ? (nm75+(1 + 75) * src[75]) : nm75, dm76=76<=length ? dm75+src[75] : dm75
nm77=77<=length ? (nm76+(1 + 76) * src[76]) : nm76, dm77=77<=length ? dm76+src[76] : dm76
nm78=78<=length ? (nm77+(1 + 77) * src[77]) : nm77, dm78=78<=length ? dm77+src[77] : dm77
nm79=79<=length ? (nm78+(1 + 78) * src[78]) : nm78, dm79=79<=length ? dm78+src[78] : dm78
nm80=80<=length ? (nm79+(1 + 79) * src[79]) : nm79, dm80=80<=length ? dm79+src[79] : dm79
nm81=81<=length ? (nm80+(1 + 80) * src[80]) : nm80, dm81=81<=length ? dm80+src[80] : dm80
nm82=82<=length ? (nm81+(1 + 81) * src[81]) : nm81, dm82=82<=length ? dm81+src[81] : dm81
nm83=83<=length ? (nm82+(1 + 82) * src[82]) : nm82, dm83=83<=length ? dm82+src[82] : dm82
nm84=84<=length ? (nm83+(1 + 83) * src[83]) : nm83, dm84=84<=length ? dm83+src[83] : dm83
nm85=85<=length ? (nm84+(1 + 84) * src[84]) : nm84, dm85=85<=length ? dm84+src[84] : dm84
nm86=86<=length ? (nm85+(1 + 85) * src[85]) : nm85, dm86=86<=length ? dm85+src[85] : dm85
nm87=87<=length ? (nm86+(1 + 86) * src[86]) : nm86, dm87=87<=length ? dm86+src[86] : dm86
nm88=88<=length ? (nm87+(1 + 87) * src[87]) : nm87, dm88=88<=length ? dm87+src[87] : dm87
nm89=89<=length ? (nm88+(1 + 88) * src[88]) : nm88, dm89=89<=length ? dm88+src[88] : dm88
nm90=90<=length ? (nm89+(1 + 89) * src[89]) : nm89, dm90=90<=length ? dm89+src[89] : dm89
nm91=91<=length ? (nm90+(1 + 90) * src[90]) : nm90, dm91=91<=length ? dm90+src[90] : dm90
nm92=92<=length ? (nm91+(1 + 91) * src[91]) : nm91, dm92=92<=length ? dm91+src[91] : dm91
nm93=93<=length ? (nm92+(1 + 92) * src[92]) : nm92, dm93=93<=length ? dm92+src[92] : dm92
nm94=94<=length ? (nm93+(1 + 93) * src[93]) : nm93, dm94=94<=length ? dm93+src[93] : dm93
nm95=95<=length ? (nm94+(1 + 94) * src[94]) : nm94, dm95=95<=length ? dm94+src[94] : dm94
nm96=96<=length ? (nm95+(1 + 95) * src[95]) : nm95, dm96=96<=length ? dm95+src[95] : dm95
nm97=97<=length ? (nm96+(1 + 96) * src[96]) : nm96, dm97=97<=length ? dm96+src[96] : dm96
nm98=98<=length ? (nm97+(1 + 97) * src[97]) : nm97, dm98=98<=length ? dm97+src[97] : dm97
nm99=99<=length ? (nm98+(1 + 98) * src[98]) : nm98, dm99=99<=length ? dm98+src[98] : dm98
nm100=100<=length ? (nm99+(1 + 99) * src[99]) : nm99, dm100=100<=length ? dm99+src[99] : dm99
nm=nm100, dm=dm100
cg = iff(dm != 0, -nm/dm + (length + 1) / 2.0, 0)
maxc = highest(cg, length)
minc = lowest(cg, length)
v1 = iff(maxc != minc, (cg - minc) / (maxc - minc), 0)
v2_ = (4*v1 + 3*v1[1] + 2*v1[2] + v1[3]) / 10.0
v2 = 2*(v2_ - 0.5)
t = ( 0.96 * ( ( v2[1]) + 0.02 ) )
duml=plot(fr?(v2>t?v2:t):na, style=circles, linewidth=0, color=gray, title="Dummy")
cmil=plot(v2, title="StochCGOsc", color=red)
tl=plot(t, title="Trigger",color=green)
plot(0, title="ZeroLine", color=gray)
u1=abs(lvls),l1=abs(lvls)*-1.0
plot(u1,title="Level+",color=gray)
plot(l1,title="Level-",color=gray)
fill(cmil, duml, color=red, transp=50, title="NegativeFill")
fill(tl, duml, color=lime, transp=50, title="PositiveFill")
ebc=input(false, title="Color bars?")
bc=ebc?(v2>v2[1]?(v2>0?lime:green):v2<v2[1]?(v2>0?orange:red):(v2>u1?lime:v2<l1?red:gray)):na
barcolor(bc)
check the below:

CSS:
#// @author LazyBear
#// List of my public indicators: http://bit.ly/1LQaPK8
#// List of my app-store indicators: http://blog.tradingview.com/?p=970
#study("Ehlers Stochastic CG Oscillator [LazyBear]", shorttitle="ESCGO_LB", overlay=false, precision=3)
# converted by Sam4Cok@Samer800    - 06/2024
declare lower;

input colorBars = no; #, title="Color bars?")
input colorBackground = yes; #, title="Color bars?")
input src = hl2; #, title="Source")
input length = 8; #, title="Length", minval=1, maxval=100)
input OverboughtOversoldLevel = 0.8; #, title="OB/OS Level")
input HighlightLine = yes; #true, title="Fill Osc/Trigger region")


def na = Double.NaN;
def last = IsNaN(close);
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def nm0 = 0;
def dm0 = 0;

def nm1 = if 1 <= length then (nm0 + (1 + 0) * src[0]) else nm0;
def nm2 = if 2 <= length then (nm1 + (1 + 1) * src[1]) else nm1;
def nm3 = if 3 <= length then (nm2 + (1 + 2) * src[2]) else nm2;
def nm4 = if 4 <= length then (nm3 + (1 + 3) * src[3]) else nm3;
def nm5 = if 5 <= length then (nm4 + (1 + 4) * src[4]) else nm4;
def nm6 = if 6 <= length then (nm5 + (1 + 5) * src[5]) else nm5;
def nm7 = if 7 <= length then (nm6 + (1 + 6) * src[6]) else nm6;
def nm8 = if 8 <= length then (nm7 + (1 + 7) * src[7]) else nm7;
def nm9 = if 9 <= length then (nm8 + (1 + 8) * src[8]) else nm8;
def nm10 = if 10 <= length then (nm9 + (1 + 9) * src[9]) else nm9;
def nm11 = if 11 <= length then (nm10 + (1 + 10) * src[10]) else nm10;
def nm12 = if 12 <= length then (nm11 + (1 + 11) * src[11]) else nm11;
def nm13 = if 13 <= length then (nm12 + (1 + 12) * src[12]) else nm12;
def nm14 = if 14 <= length then (nm13 + (1 + 13) * src[13]) else nm13;
def nm15 = if 15 <= length then (nm14 + (1 + 14) * src[14]) else nm14;
def nm16 = if 16 <= length then (nm15 + (1 + 15) * src[15]) else nm15;
def nm17 = if 17 <= length then (nm16 + (1 + 16) * src[16]) else nm16;
def nm18 = if 18 <= length then (nm17 + (1 + 17) * src[17]) else nm17;
def nm19 = if 19 <= length then (nm18 + (1 + 18) * src[18]) else nm18;
def nm20 = if 20 <= length then (nm19 + (1 + 19) * src[19]) else nm19;
def nm21 = if 21 <= length then (nm20 + (1 + 20) * src[20]) else nm20;
def nm22 = if 22 <= length then (nm21 + (1 + 21) * src[21]) else nm21;
def nm23 = if 23 <= length then (nm22 + (1 + 22) * src[22]) else nm22;
def nm24 = if 24 <= length then (nm23 + (1 + 23) * src[23]) else nm23;
def nm25 = if 25 <= length then (nm24 + (1 + 24) * src[24]) else nm24;
def nm26 = if 26 <= length then (nm25 + (1 + 25) * src[25]) else nm25;
def nm27 = if 27 <= length then (nm26 + (1 + 26) * src[26]) else nm26;
def nm28 = if 28 <= length then (nm27 + (1 + 27) * src[27]) else nm27;
def nm29 = if 29 <= length then (nm28 + (1 + 28) * src[28]) else nm28;
def nm30 = if 30 <= length then (nm29 + (1 + 29) * src[29]) else nm29;
def nm31 = if 31 <= length then (nm30 + (1 + 30) * src[30]) else nm30;
def nm32 = if 32 <= length then (nm31 + (1 + 31) * src[31]) else nm31;
def nm33 = if 33 <= length then (nm32 + (1 + 32) * src[32]) else nm32;
def nm34 = if 34 <= length then (nm33 + (1 + 33) * src[33]) else nm33;
def nm35 = if 35 <= length then (nm34 + (1 + 34) * src[34]) else nm34;
def nm36 = if 36 <= length then (nm35 + (1 + 35) * src[35]) else nm35;
def nm37 = if 37 <= length then (nm36 + (1 + 36) * src[36]) else nm36;
def nm38 = if 38 <= length then (nm37 + (1 + 37) * src[37]) else nm37;
def nm39 = if 39 <= length then (nm38 + (1 + 38) * src[38]) else nm38;
def nm40 = if 40 <= length then (nm39 + (1 + 39) * src[39]) else nm39;
def nm41 = if 41 <= length then (nm40 + (1 + 40) * src[40]) else nm40;
def nm42 = if 42 <= length then (nm41 + (1 + 41) * src[41]) else nm41;
def nm43 = if 43 <= length then (nm42 + (1 + 42) * src[42]) else nm42;
def nm44 = if 44 <= length then (nm43 + (1 + 43) * src[43]) else nm43;
def nm45 = if 45 <= length then (nm44 + (1 + 44) * src[44]) else nm44;
def nm46 = if 46 <= length then (nm45 + (1 + 45) * src[45]) else nm45;
def nm47 = if 47 <= length then (nm46 + (1 + 46) * src[46]) else nm46;
def nm48 = if 48 <= length then (nm47 + (1 + 47) * src[47]) else nm47;
def nm49 = if 49 <= length then (nm48 + (1 + 48) * src[48]) else nm48;
def nm50 = if 50 <= length then (nm49 + (1 + 49) * src[49]) else nm49;
def nm51 = if 51 <= length then (nm50 + (1 + 50) * src[50]) else nm50;
def nm52 = if 52 <= length then (nm51 + (1 + 51) * src[51]) else nm51;
def nm53 = if 53 <= length then (nm52 + (1 + 52) * src[52]) else nm52;
def nm54 = if 54 <= length then (nm53 + (1 + 53) * src[53]) else nm53;
def nm55 = if 55 <= length then (nm54 + (1 + 54) * src[54]) else nm54;
def nm56 = if 56 <= length then (nm55 + (1 + 55) * src[55]) else nm55;
def nm57 = if 57 <= length then (nm56 + (1 + 56) * src[56]) else nm56;
def nm58 = if 58 <= length then (nm57 + (1 + 57) * src[57]) else nm57;
def nm59 = if 59 <= length then (nm58 + (1 + 58) * src[58]) else nm58;
def nm60 = if 60 <= length then (nm59 + (1 + 59) * src[59]) else nm59;
def nm61 = if 61 <= length then (nm60 + (1 + 60) * src[60]) else nm60;
def nm62 = if 62 <= length then (nm61 + (1 + 61) * src[61]) else nm61;
def nm63 = if 63 <= length then (nm62 + (1 + 62) * src[62]) else nm62;
def nm64 = if 64 <= length then (nm63 + (1 + 63) * src[63]) else nm63;
def nm65 = if 65 <= length then (nm64 + (1 + 64) * src[64]) else nm64;
def nm66 = if 66 <= length then (nm65 + (1 + 65) * src[65]) else nm65;
def nm67 = if 67 <= length then (nm66 + (1 + 66) * src[66]) else nm66;
def nm68 = if 68 <= length then (nm67 + (1 + 67) * src[67]) else nm67;
def nm69 = if 69 <= length then (nm68 + (1 + 68) * src[68]) else nm68;
def nm70 = if 70 <= length then (nm69 + (1 + 69) * src[69]) else nm69;
def nm71 = if 71 <= length then (nm70 + (1 + 70) * src[70]) else nm70;
def nm72 = if 72 <= length then (nm71 + (1 + 71) * src[71]) else nm71;
def nm73 = if 73 <= length then (nm72 + (1 + 72) * src[72]) else nm72;
def nm74 = if 74 <= length then (nm73 + (1 + 73) * src[73]) else nm73;
def nm75 = if 75 <= length then (nm74 + (1 + 74) * src[74]) else nm74;
def nm76 = if 76 <= length then (nm75 + (1 + 75) * src[75]) else nm75;
def nm77 = if 77 <= length then (nm76 + (1 + 76) * src[76]) else nm76;
def nm78 = if 78 <= length then (nm77 + (1 + 77) * src[77]) else nm77;
def nm79 = if 79 <= length then (nm78 + (1 + 78) * src[78]) else nm78;
def nm80 = if 80 <= length then (nm79 + (1 + 79) * src[79]) else nm79;
def nm81 = if 81 <= length then (nm80 + (1 + 80) * src[80]) else nm80;
def nm82 = if 82 <= length then (nm81 + (1 + 81) * src[81]) else nm81;
def nm83 = if 83 <= length then (nm82 + (1 + 82) * src[82]) else nm82;
def nm84 = if 84 <= length then (nm83 + (1 + 83) * src[83]) else nm83;
def nm85 = if 85 <= length then (nm84 + (1 + 84) * src[84]) else nm84;
def nm86 = if 86 <= length then (nm85 + (1 + 85) * src[85]) else nm85;
def nm87 = if 87 <= length then (nm86 + (1 + 86) * src[86]) else nm86;
def nm88 = if 88 <= length then (nm87 + (1 + 87) * src[87]) else nm87;
def nm89 = if 89 <= length then (nm88 + (1 + 88) * src[88]) else nm88;
def nm90 = if 90 <= length then (nm89 + (1 + 89) * src[89]) else nm89;
def nm91 = if 91 <= length then (nm90 + (1 + 90) * src[90]) else nm90;
def nm92 = if 92 <= length then (nm91 + (1 + 91) * src[91]) else nm91;
def nm93 = if 93 <= length then (nm92 + (1 + 92) * src[92]) else nm92;
def nm94 = if 94 <= length then (nm93 + (1 + 93) * src[93]) else nm93;
def nm95 = if 95 <= length then (nm94 + (1 + 94) * src[94]) else nm94;
def nm96 = if 96 <= length then (nm95 + (1 + 95) * src[95]) else nm95;
def nm97 = if 97 <= length then (nm96 + (1 + 96) * src[96]) else nm96;
def nm98 = if 98 <= length then (nm97 + (1 + 97) * src[97]) else nm97;
def nm99 = if 99 <= length then (nm98 + (1 + 98) * src[98]) else nm98;
def nm100 = if 100 <= length then (nm99 + (1 + 99) * src[99]) else nm99;

def dm1 = if 1 <= length then (dm0 + src[0]) else dm0;
def dm2 = if 2 <= length then (dm1 + src[1]) else dm1;
def dm3 = if 3 <= length then (dm2 + src[2]) else dm2;
def dm4 = if 4 <= length then (dm3 + src[3]) else dm3;
def dm5 = if 5 <= length then (dm4 + src[4]) else dm4;
def dm6 = if 6 <= length then (dm5 + src[5]) else dm5;
def dm7 = if 7 <= length then (dm6 + src[6]) else dm6;
def dm8 = if 8 <= length then (dm7 + src[7]) else dm7;
def dm9 = if 9 <= length then (dm8 + src[8]) else dm8;
def dm10 = if 10 <= length then (dm9 +  src[9]) else dm9;
def dm11 = if 11 <= length then (dm10 + src[10]) else dm10;
def dm12 = if 12 <= length then (dm11 + src[11]) else dm11;
def dm13 = if 13 <= length then (dm12 + src[12]) else dm12;
def dm14 = if 14 <= length then (dm13 + src[13]) else dm13;
def dm15 = if 15 <= length then (dm14 + src[14]) else dm14;
def dm16 = if 16 <= length then (dm15 + src[15]) else dm15;
def dm17 = if 17    <=    length    then    (dm16    +    src[16    ])    else    dm16;
def dm18 = if 18    <=    length    then    (dm17    +    src[17    ])    else    dm17;
def dm19 = if 19    <=    length    then    (dm18    +    src[18    ])    else    dm18;
def dm20 = if 20    <=    length    then    (dm19    +    src[19    ])    else    dm19;
def dm21 = if 21    <=    length    then    (dm20    +    src[20    ])    else    dm20;
def dm22 = if 22    <=    length    then    (dm21    +    src[    21    ])    else    dm21;
def dm23 = if 23    <=    length    then    (dm22    +    src[    22    ])    else    dm22;
def dm24 = if 24    <=    length    then    (dm23    +    src[    23    ])    else    dm23;
def dm25 = if 25    <=    length    then    (dm24    +    src[    24    ])    else    dm24;
def dm26 = if 26    <=    length    then    (dm25    +    src[    25    ])    else    dm25;
def dm27 = if 27    <=    length    then    (dm26    +    src[    26    ])    else    dm26;
def dm28 = if 28    <=    length    then    (dm27    +    src[    27    ])    else    dm27;
def dm29 = if 29    <=    length    then    (dm28    +    src[    28    ])    else    dm28;
def dm30 = if 30    <=    length    then    (dm29    +    src[    29    ])    else    dm29;
def dm31 = if 31    <=    length    then    (dm30    +    src[    30    ])    else    dm30;
def dm32 = if 32    <=    length    then    (dm31    +    src[    31    ])    else    dm31;
def dm33 = if 33    <=    length    then    (dm32    +    src[    32    ])    else    dm32;
def dm34 = if 34    <=    length    then    (dm33    +    src[    33    ])    else    dm33;
def dm35 = if 35    <=    length    then    (dm34    +    src[    34    ])    else    dm34;
def dm36 = if 36    <=    length    then    (dm35    +    src[    35    ])    else    dm35;
def dm37 = if 37    <=    length    then    (dm36    +    src[    36    ])    else    dm36;
def dm38 = if 38    <=    length    then    (dm37    +    src[    37    ])    else    dm37;
def dm39 = if 39    <=    length    then    (dm38    +    src[    38    ])    else    dm38;
def dm40 = if 40    <=    length    then    (dm39    +    src[    39    ])    else    dm39;
def dm41 = if 41    <=    length    then    (dm40    +    src[    40    ])    else    dm40;
def dm42 = if 42    <=    length    then    (dm41    +    src[    41    ])    else    dm41;
def dm43 = if 43    <=    length    then    (dm42    +    src[    42    ])    else    dm42;
def dm44 = if 44    <=    length    then    (dm43    +    src[    43    ])    else    dm43;
def dm45 = if 45    <=    length    then    (dm44    +    src[    44    ])    else    dm44;
def dm46 = if 46    <=    length    then    (dm45    +    src[    45    ])    else    dm45;
def dm47 = if 47    <=    length    then    (dm46    +    src[    46    ])    else    dm46;
def dm48 = if 48    <=    length    then    (dm47    +    src[    47    ])    else    dm47;
def dm49 = if 49    <=    length    then    (dm48    +    src[    48    ])    else    dm48;
def dm50 = if 50    <=    length    then    (dm49    +    src[    49    ])    else    dm49;
def dm51 = if 51    <=    length    then    (dm50    +    src[    50    ])    else    dm50;
def dm52 = if 52    <=    length    then    (dm51    +    src[    51    ])    else    dm51;
def dm53 = if 53    <=    length    then    (dm52    +    src[    52    ])    else    dm52;
def dm54 = if 54    <=    length    then    (dm53    +    src[    53    ])    else    dm53;
def dm55 = if 55    <=    length    then    (dm54    +    src[    54    ])    else    dm54;
def dm56 = if 56    <=    length    then    (dm55    +    src[    55    ])    else    dm55;
def dm57 = if 57    <=    length    then    (dm56    +    src[    56    ])    else    dm56;
def dm58 = if 58    <=    length    then    (dm57    +    src[    57    ])    else    dm57;
def dm59 = if 59    <=    length    then    (dm58    +    src[    58    ])    else    dm58;
def dm60 = if 60    <=    length    then    (dm59    +    src[59    ])    else    dm59;
def dm61 = if 61    <=    length    then    (dm60    +    src[60    ])    else    dm60;
def dm62 = if 62    <=    length    then    (dm61    +    src[61    ])    else    dm61;
def dm63 = if 63    <=    length    then    (dm62    +    src[62    ])    else    dm62;
def dm64 = if 64    <=    length    then    (dm63    +    src[63    ])    else    dm63;
def dm65 = if 65    <=    length    then    (dm64    +    src[64    ])    else    dm64;
def dm66 = if 66    <=    length    then    (dm65    +    src[65    ])    else    dm65;
def dm67 = if 67    <=    length    then    (dm66    +    src[66    ])    else    dm66;
def dm68 = if 68    <=    length    then    (dm67    +    src[67    ])    else    dm67;
def dm69 = if 69    <=    length    then    (dm68    +    src[68    ])    else    dm68;
def dm70 = if 70    <=    length    then    (dm69    +    src[69    ])    else    dm69;
def dm71 = if 71    <=    length    then    (dm70    +    src[70    ])    else    dm70;
def dm72 = if 72    <=    length    then    (dm71    +    src[71    ])    else    dm71;
def dm73 = if 73    <=    length    then    (dm72    +    src[72    ])    else    dm72;
def dm74 = if 74    <=    length    then    (dm73    +    src[73    ])    else    dm73;
def dm75 = if 75    <=    length    then    (dm74    +    src[74    ])    else    dm74;
def dm76 = if 76    <=    length    then    (dm75    +    src[75    ])    else    dm75;
def dm77 = if 77    <=    length    then    (dm76    +    src[76    ])    else    dm76;
def dm78 = if 78    <=    length    then    (dm77    +    src[77    ])    else    dm77;
def dm79 = if 79    <=    length    then    (dm78    +    src[78    ])    else    dm78;
def dm80 = if 80    <=    length    then    (dm79    +    src[79    ])    else    dm79;
def dm81 = if 81    <=    length    then    (dm80    +    src[80    ])    else    dm80;
def dm82 = if 82    <=    length    then    (dm81    +    src[81    ])    else    dm81;
def dm83 = if 83    <=    length    then    (dm82    +    src[82    ])    else    dm82;
def dm84 = if 84    <=    length    then    (dm83    +    src[83    ])    else    dm83;
def dm85 = if 85    <=    length    then    (dm84    +    src[84    ])    else    dm84;
def dm86 = if 86    <=    length    then    (dm85    +    src[85    ])    else    dm85;
def dm87 = if 87    <=    length    then    (dm86    +    src[86    ])    else    dm86;
def dm88 = if 88    <=    length    then    (dm87    +    src[87    ])    else    dm87;
def dm89 = if 89    <=    length    then    (dm88    +    src[88    ])    else    dm88;
def dm90 = if 90    <=    length    then    (dm89    +    src[89    ])    else    dm89;
def dm91 = if 91    <=    length    then    (dm90    +    src[90    ])    else    dm90;
def dm92 = if 92    <=    length    then    (dm91    +    src[91    ])    else    dm91;
def dm93 = if 93    <=    length    then    (dm92    +    src[92    ])    else    dm92;
def dm94 = if 94    <=    length    then    (dm93    +    src[93    ])    else    dm93;
def dm95 = if 95    <=    length    then    (dm94    +    src[94    ])    else    dm94;
def dm96 = if 96    <=    length    then    (dm95    +    src[95    ])    else    dm95;
def dm97 = if 97    <=    length    then    (dm96    +    src[96    ])    else    dm96;
def dm98 = if 98    <=    length    then    (dm97    +    src[97    ])    else    dm97;
def dm99 = if 99    <=    length    then    (dm98    +    src[98    ])    else    dm98;
def dm100 = if 100    <=    length    then    (dm99    +    src[99    ])    else    dm99;


def nm = nm100;
def dm = dm100;
def cg = If(dm != 0, -nm / dm + (length + 1) / 2.0, 0);
def maxc = Highest(cg, length);
def minc = Lowest(cg, length);
def v1 = If(maxc != minc, (cg - minc) / (maxc - minc), 0);
def v2_ = (4 * v1 + 3 * v1[1] + 2 * v1[2] + v1[3]) / 10.0;
#def v2_ = if isNaN(v22) then 0 else v22;
def v2 = 2 * (v2_ - 0.5);
def t = ( 0.96 * (v2[1]) + 0.02) ;

def duml = if HighlightLine then (if v2 > t then v2 else t) else na; # title="Dummy"
def cmil = v2; #, title="StochCGOsc", color=red)
plot tl = if IsNaN(v2) then na else t; #, title="Trigger",color=green)
plot zero = if last then na else 0;
plot u1 = if last then na else AbsValue(OverboughtOversoldLevel);
plot l1 = u1 * -1;
u1.SetDefaultColor(Color.GRAY);
l1.SetDefaultColor(Color.GRAY);
zero.SetDefaultColor(Color.DARK_GRAY);
tl.AssignValueColor(if cmil > tl then Color.GREEN else Color.RED);
AddCloud(duml, cmil, Color.RED);
AddCloud(duml, tl, Color.GREEN);

#  bar color
def bc = if v2 > v2[1] then (if v2 > 0 then 2 else 1) else
         if v2 < v2[1] then (if v2 > 0 then -1 else -2) else (if v2 > u1 then 2 else if v2 < l1 then -2 else 0);

AddCloud(if colorBackground and (bc==2 or bc[1]==2) then pos else na, neg, Color.DARK_GREEN);
AddCloud(if colorBackground and (bc==1 or bc[1]==1) then pos else na, neg, CreateColor(0, 61, 0)); #green
AddCloud(if colorBackground and (bc==-2 or bc[1]==-2) then pos else na, neg, Color.DARK_RED);
AddCloud(if colorBackground and (bc==-1 or bc[1]==-1) then pos else na, neg, CreateColor(80, 0, 0)); #red

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if bc == 2 then Color.GREEN else
                 if bc == 1 then Color.DARK_GREEN else
                 if bc == -2 then Color.RED else
                 if bc == -1 then Color.DARK_RED else Color.GRAY);


#== END of CODE
 
Last edited by a moderator:
check the below:

CSS:
#// @author LazyBear
#// List of my public indicators: http://bit.ly/1LQaPK8
#// List of my app-store indicators: http://blog.tradingview.com/?p=970
#study("Ehlers Stochastic CG Oscillator [LazyBear]", shorttitle="ESCGO_LB", overlay=false, precision=3)
# converted by Sam4Cok@Samer800    - 06/2024
declare lower;

input colorBars = no; #, title="Color bars?")
input colorBackground = yes; #, title="Color bars?")
input src = hl2; #, title="Source")
input length = 8; #, title="Length", minval=1, maxval=100)
input OverboughtOversoldLevel = 0.8; #, title="OB/OS Level")
input HighlightLine = yes; #true, title="Fill Osc/Trigger region")


def na = Double.NaN;
def last = IsNaN(close);
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def nm0 = 0;
def dm0 = 0;

def nm1 = if 1 <= length then (nm0 + (1 + 0) * src[0]) else nm0;
def nm2 = if 2 <= length then (nm1 + (1 + 1) * src[1]) else nm1;
def nm3 = if 3 <= length then (nm2 + (1 + 2) * src[2]) else nm2;
def nm4 = if 4 <= length then (nm3 + (1 + 3) * src[3]) else nm3;
def nm5 = if 5 <= length then (nm4 + (1 + 4) * src[4]) else nm4;
def nm6 = if 6 <= length then (nm5 + (1 + 5) * src[5]) else nm5;
def nm7 = if 7 <= length then (nm6 + (1 + 6) * src[6]) else nm6;
def nm8 = if 8 <= length then (nm7 + (1 + 7) * src[7]) else nm7;
def nm9 = if 9 <= length then (nm8 + (1 + 8) * src[8]) else nm8;
def nm10 = if 10 <= length then (nm9 + (1 + 9) * src[9]) else nm9;
def nm11 = if 11 <= length then (nm10 + (1 + 10) * src[10]) else nm10;
def nm12 = if 12 <= length then (nm11 + (1 + 11) * src[11]) else nm11;
def nm13 = if 13 <= length then (nm12 + (1 + 12) * src[12]) else nm12;
def nm14 = if 14 <= length then (nm13 + (1 + 13) * src[13]) else nm13;
def nm15 = if 15 <= length then (nm14 + (1 + 14) * src[14]) else nm14;
def nm16 = if 16 <= length then (nm15 + (1 + 15) * src[15]) else nm15;
def nm17 = if 17 <= length then (nm16 + (1 + 16) * src[16]) else nm16;
def nm18 = if 18 <= length then (nm17 + (1 + 17) * src[17]) else nm17;
def nm19 = if 19 <= length then (nm18 + (1 + 18) * src[18]) else nm18;
def nm20 = if 20 <= length then (nm19 + (1 + 19) * src[19]) else nm19;
def nm21 = if 21 <= length then (nm20 + (1 + 20) * src[20]) else nm20;
def nm22 = if 22 <= length then (nm21 + (1 + 21) * src[21]) else nm21;
def nm23 = if 23 <= length then (nm22 + (1 + 22) * src[22]) else nm22;
def nm24 = if 24 <= length then (nm23 + (1 + 23) * src[23]) else nm23;
def nm25 = if 25 <= length then (nm24 + (1 + 24) * src[24]) else nm24;
def nm26 = if 26 <= length then (nm25 + (1 + 25) * src[25]) else nm25;
def nm27 = if 27 <= length then (nm26 + (1 + 26) * src[26]) else nm26;
def nm28 = if 28 <= length then (nm27 + (1 + 27) * src[27]) else nm27;
def nm29 = if 29 <= length then (nm28 + (1 + 28) * src[28]) else nm28;
def nm30 = if 30 <= length then (nm29 + (1 + 29) * src[29]) else nm29;
def nm31 = if 31 <= length then (nm30 + (1 + 30) * src[30]) else nm30;
def nm32 = if 32 <= length then (nm31 + (1 + 31) * src[31]) else nm31;
def nm33 = if 33 <= length then (nm32 + (1 + 32) * src[32]) else nm32;
def nm34 = if 34 <= length then (nm33 + (1 + 33) * src[33]) else nm33;
def nm35 = if 35 <= length then (nm34 + (1 + 34) * src[34]) else nm34;
def nm36 = if 36 <= length then (nm35 + (1 + 35) * src[35]) else nm35;
def nm37 = if 37 <= length then (nm36 + (1 + 36) * src[36]) else nm36;
def nm38 = if 38 <= length then (nm37 + (1 + 37) * src[37]) else nm37;
def nm39 = if 39 <= length then (nm38 + (1 + 38) * src[38]) else nm38;
def nm40 = if 40 <= length then (nm39 + (1 + 39) * src[39]) else nm39;
def nm41 = if 41 <= length then (nm40 + (1 + 40) * src[40]) else nm40;
def nm42 = if 42 <= length then (nm41 + (1 + 41) * src[41]) else nm41;
def nm43 = if 43 <= length then (nm42 + (1 + 42) * src[42]) else nm42;
def nm44 = if 44 <= length then (nm43 + (1 + 43) * src[43]) else nm43;
def nm45 = if 45 <= length then (nm44 + (1 + 44) * src[44]) else nm44;
def nm46 = if 46 <= length then (nm45 + (1 + 45) * src[45]) else nm45;
def nm47 = if 47 <= length then (nm46 + (1 + 46) * src[46]) else nm46;
def nm48 = if 48 <= length then (nm47 + (1 + 47) * src[47]) else nm47;
def nm49 = if 49 <= length then (nm48 + (1 + 48) * src[48]) else nm48;
def nm50 = if 50 <= length then (nm49 + (1 + 49) * src[49]) else nm49;
def nm51 = if 51 <= length then (nm50 + (1 + 50) * src[50]) else nm50;
def nm52 = if 52 <= length then (nm51 + (1 + 51) * src[51]) else nm51;
def nm53 = if 53 <= length then (nm52 + (1 + 52) * src[52]) else nm52;
def nm54 = if 54 <= length then (nm53 + (1 + 53) * src[53]) else nm53;
def nm55 = if 55 <= length then (nm54 + (1 + 54) * src[54]) else nm54;
def nm56 = if 56 <= length then (nm55 + (1 + 55) * src[55]) else nm55;
def nm57 = if 57 <= length then (nm56 + (1 + 56) * src[56]) else nm56;
def nm58 = if 58 <= length then (nm57 + (1 + 57) * src[57]) else nm57;
def nm59 = if 59 <= length then (nm58 + (1 + 58) * src[58]) else nm58;
def nm60 = if 60 <= length then (nm59 + (1 + 59) * src[59]) else nm59;
def nm61 = if 61 <= length then (nm60 + (1 + 60) * src[60]) else nm60;
def nm62 = if 62 <= length then (nm61 + (1 + 61) * src[61]) else nm61;
def nm63 = if 63 <= length then (nm62 + (1 + 62) * src[62]) else nm62;
def nm64 = if 64 <= length then (nm63 + (1 + 63) * src[63]) else nm63;
def nm65 = if 65 <= length then (nm64 + (1 + 64) * src[64]) else nm64;
def nm66 = if 66 <= length then (nm65 + (1 + 65) * src[65]) else nm65;
def nm67 = if 67 <= length then (nm66 + (1 + 66) * src[66]) else nm66;
def nm68 = if 68 <= length then (nm67 + (1 + 67) * src[67]) else nm67;
def nm69 = if 69 <= length then (nm68 + (1 + 68) * src[68]) else nm68;
def nm70 = if 70 <= length then (nm69 + (1 + 69) * src[69]) else nm69;
def nm71 = if 71 <= length then (nm70 + (1 + 70) * src[70]) else nm70;
def nm72 = if 72 <= length then (nm71 + (1 + 71) * src[71]) else nm71;
def nm73 = if 73 <= length then (nm72 + (1 + 72) * src[72]) else nm72;
def nm74 = if 74 <= length then (nm73 + (1 + 73) * src[73]) else nm73;
def nm75 = if 75 <= length then (nm74 + (1 + 74) * src[74]) else nm74;
def nm76 = if 76 <= length then (nm75 + (1 + 75) * src[75]) else nm75;
def nm77 = if 77 <= length then (nm76 + (1 + 76) * src[76]) else nm76;
def nm78 = if 78 <= length then (nm77 + (1 + 77) * src[77]) else nm77;
def nm79 = if 79 <= length then (nm78 + (1 + 78) * src[78]) else nm78;
def nm80 = if 80 <= length then (nm79 + (1 + 79) * src[79]) else nm79;
def nm81 = if 81 <= length then (nm80 + (1 + 80) * src[80]) else nm80;
def nm82 = if 82 <= length then (nm81 + (1 + 81) * src[81]) else nm81;
def nm83 = if 83 <= length then (nm82 + (1 + 82) * src[82]) else nm82;
def nm84 = if 84 <= length then (nm83 + (1 + 83) * src[83]) else nm83;
def nm85 = if 85 <= length then (nm84 + (1 + 84) * src[84]) else nm84;
def nm86 = if 86 <= length then (nm85 + (1 + 85) * src[85]) else nm85;
def nm87 = if 87 <= length then (nm86 + (1 + 86) * src[86]) else nm86;
def nm88 = if 88 <= length then (nm87 + (1 + 87) * src[87]) else nm87;
def nm89 = if 89 <= length then (nm88 + (1 + 88) * src[88]) else nm88;
def nm90 = if 90 <= length then (nm89 + (1 + 89) * src[89]) else nm89;
def nm91 = if 91 <= length then (nm90 + (1 + 90) * src[90]) else nm90;
def nm92 = if 92 <= length then (nm91 + (1 + 91) * src[91]) else nm91;
def nm93 = if 93 <= length then (nm92 + (1 + 92) * src[92]) else nm92;
def nm94 = if 94 <= length then (nm93 + (1 + 93) * src[93]) else nm93;
def nm95 = if 95 <= length then (nm94 + (1 + 94) * src[94]) else nm94;
def nm96 = if 96 <= length then (nm95 + (1 + 95) * src[95]) else nm95;
def nm97 = if 97 <= length then (nm96 + (1 + 96) * src[96]) else nm96;
def nm98 = if 98 <= length then (nm97 + (1 + 97) * src[97]) else nm97;
def nm99 = if 99 <= length then (nm98 + (1 + 98) * src[98]) else nm98;
def nm100 = if 100 <= length then (nm99 + (1 + 99) * src[99]) else nm99;

def dm1 = if 1 <= length then (dm0 + src[0]) else dm0;
def dm2 = if 2 <= length then (dm1 + src[1]) else dm1;
def dm3 = if 3 <= length then (dm2 + src[2]) else dm2;
def dm4 = if 4 <= length then (dm3 + src[3]) else dm3;
def dm5 = if 5 <= length then (dm4 + src[4]) else dm4;
def dm6 = if 6 <= length then (dm5 + src[5]) else dm5;
def dm7 = if 7 <= length then (dm6 + src[6]) else dm6;
def dm8 = if 8 <= length then (dm7 + src[7]) else dm7;
def dm9 = if 9 <= length then (dm8 + src[8]) else dm8;
def dm10 = if 10 <= length then (dm9 +  src[9]) else dm9;
def dm11 = if 11 <= length then (dm10 + src[10]) else dm10;
def dm12 = if 12 <= length then (dm11 + src[11]) else dm11;
def dm13 = if 13 <= length then (dm12 + src[12]) else dm12;
def dm14 = if 14 <= length then (dm13 + src[13]) else dm13;
def dm15 = if 15 <= length then (dm14 + src[14]) else dm14;
def dm16 = if 16 <= length then (dm15 + src[15]) else dm15;
def dm17 = if 17    <=    length    then    (dm16    +    src[16    ])    else    dm16;
def dm18 = if 18    <=    length    then    (dm17    +    src[17    ])    else    dm17;
def dm19 = if 19    <=    length    then    (dm18    +    src[18    ])    else    dm18;
def dm20 = if 20    <=    length    then    (dm19    +    src[19    ])    else    dm19;
def dm21 = if 21    <=    length    then    (dm20    +    src[20    ])    else    dm20;
def dm22 = if 22    <=    length    then    (dm21    +    src[    21    ])    else    dm21;
def dm23 = if 23    <=    length    then    (dm22    +    src[    22    ])    else    dm22;
def dm24 = if 24    <=    length    then    (dm23    +    src[    23    ])    else    dm23;
def dm25 = if 25    <=    length    then    (dm24    +    src[    24    ])    else    dm24;
def dm26 = if 26    <=    length    then    (dm25    +    src[    25    ])    else    dm25;
def dm27 = if 27    <=    length    then    (dm26    +    src[    26    ])    else    dm26;
def dm28 = if 28    <=    length    then    (dm27    +    src[    27    ])    else    dm27;
def dm29 = if 29    <=    length    then    (dm28    +    src[    28    ])    else    dm28;
def dm30 = if 30    <=    length    then    (dm29    +    src[    29    ])    else    dm29;
def dm31 = if 31    <=    length    then    (dm30    +    src[    30    ])    else    dm30;
def dm32 = if 32    <=    length    then    (dm31    +    src[    31    ])    else    dm31;
def dm33 = if 33    <=    length    then    (dm32    +    src[    32    ])    else    dm32;
def dm34 = if 34    <=    length    then    (dm33    +    src[    33    ])    else    dm33;
def dm35 = if 35    <=    length    then    (dm34    +    src[    34    ])    else    dm34;
def dm36 = if 36    <=    length    then    (dm35    +    src[    35    ])    else    dm35;
def dm37 = if 37    <=    length    then    (dm36    +    src[    36    ])    else    dm36;
def dm38 = if 38    <=    length    then    (dm37    +    src[    37    ])    else    dm37;
def dm39 = if 39    <=    length    then    (dm38    +    src[    38    ])    else    dm38;
def dm40 = if 40    <=    length    then    (dm39    +    src[    39    ])    else    dm39;
def dm41 = if 41    <=    length    then    (dm40    +    src[    40    ])    else    dm40;
def dm42 = if 42    <=    length    then    (dm41    +    src[    41    ])    else    dm41;
def dm43 = if 43    <=    length    then    (dm42    +    src[    42    ])    else    dm42;
def dm44 = if 44    <=    length    then    (dm43    +    src[    43    ])    else    dm43;
def dm45 = if 45    <=    length    then    (dm44    +    src[    44    ])    else    dm44;
def dm46 = if 46    <=    length    then    (dm45    +    src[    45    ])    else    dm45;
def dm47 = if 47    <=    length    then    (dm46    +    src[    46    ])    else    dm46;
def dm48 = if 48    <=    length    then    (dm47    +    src[    47    ])    else    dm47;
def dm49 = if 49    <=    length    then    (dm48    +    src[    48    ])    else    dm48;
def dm50 = if 50    <=    length    then    (dm49    +    src[    49    ])    else    dm49;
def dm51 = if 51    <=    length    then    (dm50    +    src[    50    ])    else    dm50;
def dm52 = if 52    <=    length    then    (dm51    +    src[    51    ])    else    dm51;
def dm53 = if 53    <=    length    then    (dm52    +    src[    52    ])    else    dm52;
def dm54 = if 54    <=    length    then    (dm53    +    src[    53    ])    else    dm53;
def dm55 = if 55    <=    length    then    (dm54    +    src[    54    ])    else    dm54;
def dm56 = if 56    <=    length    then    (dm55    +    src[    55    ])    else    dm55;
def dm57 = if 57    <=    length    then    (dm56    +    src[    56    ])    else    dm56;
def dm58 = if 58    <=    length    then    (dm57    +    src[    57    ])    else    dm57;
def dm59 = if 59    <=    length    then    (dm58    +    src[    58    ])    else    dm58;
def dm60 = if 60    <=    length    then    (dm59    +    src[59    ])    else    dm59;
def dm61 = if 61    <=    length    then    (dm60    +    src[60    ])    else    dm60;
def dm62 = if 62    <=    length    then    (dm61    +    src[61    ])    else    dm61;
def dm63 = if 63    <=    length    then    (dm62    +    src[62    ])    else    dm62;
def dm64 = if 64    <=    length    then    (dm63    +    src[63    ])    else    dm63;
def dm65 = if 65    <=    length    then    (dm64    +    src[64    ])    else    dm64;
def dm66 = if 66    <=    length    then    (dm65    +    src[65    ])    else    dm65;
def dm67 = if 67    <=    length    then    (dm66    +    src[66    ])    else    dm66;
def dm68 = if 68    <=    length    then    (dm67    +    src[67    ])    else    dm67;
def dm69 = if 69    <=    length    then    (dm68    +    src[68    ])    else    dm68;
def dm70 = if 70    <=    length    then    (dm69    +    src[69    ])    else    dm69;
def dm71 = if 71    <=    length    then    (dm70    +    src[70    ])    else    dm70;
def dm72 = if 72    <=    length    then    (dm71    +    src[71    ])    else    dm71;
def dm73 = if 73    <=    length    then    (dm72    +    src[72    ])    else    dm72;
def dm74 = if 74    <=    length    then    (dm73    +    src[73    ])    else    dm73;
def dm75 = if 75    <=    length    then    (dm74    +    src[74    ])    else    dm74;
def dm76 = if 76    <=    length    then    (dm75    +    src[75    ])    else    dm75;
def dm77 = if 77    <=    length    then    (dm76    +    src[76    ])    else    dm76;
def dm78 = if 78    <=    length    then    (dm77    +    src[77    ])    else    dm77;
def dm79 = if 79    <=    length    then    (dm78    +    src[78    ])    else    dm78;
def dm80 = if 80    <=    length    then    (dm79    +    src[79    ])    else    dm79;
def dm81 = if 81    <=    length    then    (dm80    +    src[80    ])    else    dm80;
def dm82 = if 82    <=    length    then    (dm81    +    src[81    ])    else    dm81;
def dm83 = if 83    <=    length    then    (dm82    +    src[82    ])    else    dm82;
def dm84 = if 84    <=    length    then    (dm83    +    src[83    ])    else    dm83;
def dm85 = if 85    <=    length    then    (dm84    +    src[84    ])    else    dm84;
def dm86 = if 86    <=    length    then    (dm85    +    src[85    ])    else    dm85;
def dm87 = if 87    <=    length    then    (dm86    +    src[86    ])    else    dm86;
def dm88 = if 88    <=    length    then    (dm87    +    src[87    ])    else    dm87;
def dm89 = if 89    <=    length    then    (dm88    +    src[88    ])    else    dm88;
def dm90 = if 90    <=    length    then    (dm89    +    src[89    ])    else    dm89;
def dm91 = if 91    <=    length    then    (dm90    +    src[90    ])    else    dm90;
def dm92 = if 92    <=    length    then    (dm91    +    src[91    ])    else    dm91;
def dm93 = if 93    <=    length    then    (dm92    +    src[92    ])    else    dm92;
def dm94 = if 94    <=    length    then    (dm93    +    src[93    ])    else    dm93;
def dm95 = if 95    <=    length    then    (dm94    +    src[94    ])    else    dm94;
def dm96 = if 96    <=    length    then    (dm95    +    src[95    ])    else    dm95;
def dm97 = if 97    <=    length    then    (dm96    +    src[96    ])    else    dm96;
def dm98 = if 98    <=    length    then    (dm97    +    src[97    ])    else    dm97;
def dm99 = if 99    <=    length    then    (dm98    +    src[98    ])    else    dm98;
def dm100 = if 100    <=    length    then    (dm99    +    src[99    ])    else    dm99;


def nm = nm100;
def dm = dm100;
def cg = If(dm != 0, -nm / dm + (length + 1) / 2.0, 0);
def maxc = Highest(cg, length);
def minc = Lowest(cg, length);
def v1 = If(maxc != minc, (cg - minc) / (maxc - minc), 0);
def v2_ = (4 * v1 + 3 * v1[1] + 2 * v1[2] + v1[3]) / 10.0;
#def v2_ = if isNaN(v22) then 0 else v22;
def v2 = 2 * (v2_ - 0.5);
def t = ( 0.96 * (v2[1]) + 0.02) ;

def duml = if HighlightLine then (if v2 > t then v2 else t) else na; # title="Dummy"
def cmil = v2; #, title="StochCGOsc", color=red)
plot tl = if IsNaN(v2) then na else t; #, title="Trigger",color=green)
plot zero = if last then na else 0;
plot u1 = if last then na else AbsValue(OverboughtOversoldLevel);
plot l1 = u1 * -1;
u1.SetDefaultColor(Color.GRAY);
l1.SetDefaultColor(Color.GRAY);
zero.SetDefaultColor(Color.DARK_GRAY);
tl.AssignValueColor(if cmil > tl then Color.GREEN else Color.RED);
AddCloud(duml, cmil, Color.RED);
AddCloud(duml, tl, Color.GREEN);

#  bar color
def bc = if v2 > v2[1] then (if v2 > 0 then 2 else 1) else
         if v2 < v2[1] then (if v2 > 0 then -1 else -2) else (if v2 > u1 then 2 else if v2 < l1 then -2 else 0);

AddCloud(if colorBackground and (bc==2 or bc[1]==2) then pos else na, neg, Color.DARK_GREEN);
AddCloud(if colorBackground and (bc==1 or bc[1]==1) then pos else na, neg, CreateColor(0, 61, 0));
AddCloud(if colorBackground and (bc==-2 or bc[1]==-2) then pos else na, neg, Color.DARK_RED);
AddCloud(if colorBackground and (bc==-1 or bc[1]==-1) then pos else na, neg, CreateColor(80, 0, 0));

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if bc == 2 then Color.GREEN else
                 if bc == 1 then Color.DARK_GREEN else
                 if bc == -2 then Color.RED else
                 if bc == -1 then Color.DARK_RED else Color.GRAY);


#== END of CODE
Hi Samer800,

Firstly, THANK YOU for ALL the wonderful work you do here!

Secondly, I, too, love a lot of Ehlers' work.

Finally, is there a simple way for me to 'invert' the coloring to show green 'on top' and the reddish 'on bottom' as in the tradingview version. It's not hyper-important, but sometimes my mind gets affixed to such patterns of flow (i.e., up-positive, down-negative) and it takes an extra bit of 'effort' to make the thought process complete. 😃 I'm a bit older. 🥴
 
Looks nice, Auto.... By any chance would you have it for TOS,,, and,,,, any scans for it? Thanks so much...
"B"

Good news, all scripts on the useThinkScript forum work on the ToS app:
https://usethinkscript.com/threads/...r-lazybear-for-thinkorswim.18862/#post-142346

No Scans, No Watchlists, No Conditional Orders for this indicator.
Schwab limits the amount of resources available in scans, watchlists, and conditional orders. This script's requirements exceeds the maximum resources available.
Meaning, this study is too complicated for use in any of the ToS widgets. It can only be used to plot on the chart.
 
Good news, all scripts on the useThinkScript forum work on the ToS app:
https://usethinkscript.com/threads/...r-lazybear-for-thinkorswim.18862/#post-142346

No Scans, No Watchlists, No Conditional Orders for this indicator.
Schwab limits the amount of resources available in scans, watchlists, and conditional orders. This script's requirements exceeds the maximum resources available.
Meaning, this study is too complicated for use in any of the ToS widgets. It can only be used to plot on the chart.
Thanks so much!
 
any scans for it?

I truncated the numerator and denominator elements to only ten within the code and then pasted it in a scan for tos, which works for, obviously, ten periods. But, I'm sure I'm losing some integrity of the indicator. You may probably go to twenty, but then you'd have to amend the code to twenty num/dem elements and like said above, it then becomes a question of Schwab's available resources to use it as a scan. Just my two cents!!
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
352 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top