ThinkScript

declare upper; #Inputs: input nFE = 8;#hint nFE: length for Fractal Energy calculation. Mobius default is 8 input Glength = 13;#hint Glength: length for Gaussian Price Filter. Mobius default is 13 input betaDev = 4;#hint BetaDev: length for ???. Mobius default is 4 input RSI_BullTrigger = 0.1; ## 10.13.2018 JQ added this input input RSI_BearTrigger = 0.9; ## 10.13.2018 JQ added this inpur input GaussianLinearity = 0.382; #hint GaussianLinearity: Default 0.382 input GaussianNonLinearity = .612; #hint GaussianNonLinearity: Default 0.612 input data = close; input AlertOn = no; def w = (2 * Double.Pi / Glength); def beta = (1 – Cos(w)) / (Power(1.414, 2.0 / betaDev) – 1 ); def alpha = (-beta + Sqrt(beta * beta + 2 * beta)); def Go = Power(alpha, 4) * open + 4 * (1 – alpha) * Go[1] – 6 * Power( 1 – alpha, 2 ) * Go[2] + 4 * Power( 1 – alpha, 3 ) * Go[3] – Power( 1 – alpha, 4 ) * Go[4]; def Gh = Power(alpha, 4) * high + 4 * (1 – alpha) * Gh[1] – 6 * Power( 1 – alpha, 2 ) * Gh[2] + 4 * Power( 1 – alpha, 3 ) * Gh[3] – Power( 1 – alpha, 4 ) * Gh[4]; def Gl = Power(alpha, 4) * low + 4 * (1 – alpha) * Gl[1] – 6 * Power( 1 – alpha, 2 ) * Gl[2] + 4 * Power( 1 – alpha, 3 ) * Gl[3] – Power( 1 – alpha, 4 ) * Gl[4]; def Gc = Power(alpha, 4) * data + 4 * (1 – alpha) * Gc[1] – 6 * Power( 1 – alpha, 2 ) * Gc[2] + 4 * Power( 1 – alpha, 3 ) * Gc[3] – Power( 1 – alpha, 4 ) * Gc[4]; # Variables: def o; def h; def l; def c; def CU1; def CU2; def CU; def CD1; def CD2; def CD; def L0; def L1; def L2; def L3; def RSI; #plot OS; #plot OB; #plot M; # Calculations o = (Go + Gc[1]) / 2; h = Max(Gh, Gc[1]); l = Min(Gl, Gc[1]); c = (o + h + l + Gc) / 4; def gamma = Log(Sum((Max(Gh, Gc[1]) – Min(Gl, Gc[1])), nFE) / (Highest(gh, nFE) – Lowest(Gl, nFE))) / Log(nFE); #gamma.SetDefaultColor(Color.Yellow); L0 = (1 – gamma) * Gc + gamma * L0[1]; L1 = -gamma * L0 + L0[1] + gamma * L1[1]; L2 = -gamma * L1 + L1[1] + gamma * L2[1]; L3 = -gamma * L2 + L2[1] + gamma * L3[1]; if L0 >= L1 then { CU1 = L0 – L1; CD1 = 0; } else { CD1 = L1 – L0; CU1 = 0; } if L1 >= L2 then { CU2 = CU1 + L1 – L2; CD2 = CD1; } else { CD2 = CD1 + L2 – L1; CU2 = CU1; } if L2 >= L3 then { CU = CU2 + L2 – L3; CD = CD2; } else { CU = CU2; CD = CD2 + L3 – L2; } # Plot RSI RSI = if CU + CD <> 0 then CU / (CU + CD) else 0; Alert(AlertOn and RSI crosses below RSI_BearTrigger, “”, Alert.BAR, Sound.Bell); # 10.13.2018 JQ swapped RSI_BearTrigger for 0.9 Alert(AlertOn and RSI crosses above RSI_BullTrigger, “”, Alert.BAR, Sound.Bell); # 10.132018 JQ swapped RSI_BullTrigger for 0.1 # Spaced arrow plots def Y_axisRange = highestall(high) – lowestall(low); #addlabel(1,”Y axis range: ” + y_axisRange, color.LIME); input AlertLineSpacer = .3; #hint AlertLineSpacer: paint line ? percent lower than Lowest Low Plot BullArrowLine = LowestAll(low) – (y_axisRange/100); BullArrowLine.hide(); plot CenterLine = BullArrowLine – (5.5 * y_axisRange/100); CenterLine.hide(); plot BearArrowLine = CenterLine – (5.5 * y_axisRange/100); BearArrowLine.hide(); plot BubbleLine = CenterLine – (4.5 * y_axisRange/100); BubbleLine.hide(); addchartbubble( barnumber() == 1, BubbleLine ,”G-RSI-L nFE:” + nfe + ” Glength:” + Glength + ” BetaDev:” + BetaDev + ” “,Color.WHITE,yes); plot RSIBullArrow = if RSI crosses above rsi_bullTrigger then BullArrowLine else double.NaN; RSIBullArrow.setPaintingStrategy(PaintingStrategy.ARROW_UP); RSIBullArrow.setDefaultColor(color.GREEN); RSIBullArrow.setlineWeight(5); plot RSIBull2 = if RSI >=rsi_bullTrigger and rsi >= rsi[1] and rsi[1] >= rsi[2] then Centerline else double.NaN; RSIBull2.setPaintingStrategy(PaintingStrategy.SQUARES); RSIBull2.assignValueColor(RSIBUllArrow.takevaluecolor()); RSIBull2.setlineWeight(3); plot RSIBearArrow = if RSI crosses below rsi_bearTrigger then BearArrowLine else double.NaN; RSIBearArrow.setPaintingStrategy(PaintingStrategy.ARROW_DOWN); RSIBearArrow.setDefaultColor(color.RED); RSIBearArrow.setlineWeight(5); plot BearLine2 = if RSI <= RSI_bearTrigger and rsi <= Rsi[1] and rsi[1] <= rsi[2] then Centerline else double.NaN; BearLine2.setPaintingStrategy(PaintingStrategy.SQUARES); BearLine2.assignValueColor(RSIBearArrow.takevaluecolor()); BearLine2.setlineWeight(3); ##rsilowerAlertLine2.hide(); #addverticalLine(if RSI crosses above rsi_BullTrigger then RSIlowerAlertLine3 else double.NaN, “Gaussian RSI-L”, #color.LIME, stroke = Curve.FIRM); #addverticalLine(if RSI crosses below rsi_bearTrigger then RSIlowerAlertLine3 else double.NaN, “Gaussian RSI-L”, #color.PINK, stroke = Curve.FIRM); # End Code RSI_Laguerre Self Adjusting with Fractal Energy
#Start Script# declare lower; input show_bubbles= no; input show_shadow= yes; input show_ema= no; input show_historical_chop= yes; input trade_in_squeeze= yes; input show_mini_studies= no; ##studies def value = MACD().”value”; def avg = MACD().”avg”; def dmiosc = DMI_Oscillator().”osc”; def vplus = VortexIndicator().”vi+”; def vminus = VortexIndicator().”vi-“; def squeezehist = TTM_Squeeze().”histogram”; def bbs = BollingerBandsSMA().”upperband”; def kelt = KeltnerChannels().”upper_band”; ##Normalizers script normalizePlot { input data = close; input newRngMin = 1; input newRngMax = 20; input vertdisp= 0; def hhData = HighestAll( data ); def llData = LowestAll( data ); plot nr = (((newRngMax – newRngMin) * (data – llData)) / (hhData – llData)) + newRngMin; } #mobiuschoppiness def chopLength = 14; def chopSignal = 3; input CIx = {default CIB, CIA}; def CIA = 100 * Log( Sum( TrueRange(high, close, low), chopLength)) / ( Highest(close[1], chopLength) – Lowest(close[1], chopLength)) / Log(chopLength); def CIB = ((Log(Sum(TrueRange(high, close, low), chopLength) / (Highest(if high >= close[1] then high else close[1], chopLength) – Lowest( if low <= close[1] then low else close[1], chopLength))) / Log(10)) / (Log(chopLength) / Log(10))) * 100; def CI = if CIx == CIx.CIB then CIB else CIA; #Grail ##Grail Inputs def showlastcrossover = yes; def lengthW = 2; def price = close; def lengthM = 3; def lengthM2 = 4; #Grail Calc’s and Cond’s def coeffW = lengthW * price * price – 2 * price * Sum(price, lengthW)[1] + Sum(price * price, lengthW)[1]; def coeffM = lengthM * price * price – 2 * price * Sum(price, lengthM)[1] + Sum(price * price, lengthM2)[1]; def EhlersWarrow = WildersAverage((Sum(coeffW * price, lengthW) / Sum(coeffW, lengthW)), lengthW); def EhlersMarrow = WildersAverage((ExpAverage((Sum(coeffM * price, lengthM) / Sum(coeffM, lengthM)), lengthM)), lengthM2); def conditionBELOW = Crosses(EhlersWarrow, EhlersMarrow, CrossingDirection.BELOW); def conditionABOVE = Crosses(EhlersWarrow, EhlersMarrow, CrossingDirection.ABOVE); ## Grail Plots plot down = if conditionBELOW == yes then 21 else Double.NaN; plot up = if conditionABOVE == yes then 21 else Double.NaN; down.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN); down.AssignValueColor(Color.YELLOW); down.SetLineWeight(2); up.SetPaintingStrategy(PaintingStrategy.ARROW_UP); up.AssignValueColor(Color.YELLOW); up.SetLineWeight(2); ##modifications def macdosc = value – avg; def vortexosc = vplus – vminus; def squeeze = if bbs < kelt then yes else no; def volosc = (Average(volume, 12) – Average(volume, 26)); ##conditions/plots plot volume = volosc; plot volume1 = 21; plot macd1= if trade_in_squeeze==no and squeeze==yes then double.nan else if macdosc > 0 then 18 else 16; plot macd2 = if trade_in_squeeze==no and squeeze==yes then double.nan else if macdosc < 0 then 18 else 16; plot dmi1 = if trade_in_squeeze==no and squeeze==yes then double.nan else if dmiosc > 0 then 14 else 12; plot dmi2 = if trade_in_squeeze==no and squeeze==yes then double.nan else if dmiosc < 0 then 14 else 12; plot vortex1 = if trade_in_squeeze==no and squeeze==yes then double.nan else if vortexosc > 0 then 10 else 8; plot vortex2 = if trade_in_squeeze==no and squeeze==yes then double.nan else if vortexosc <= 0 then 10 else 8; plot squeezehist1 = if trade_in_squeeze==no and squeeze==yes then double.nan else if squeezehist > 0 then 6 else 4; plot squeezehist2 = if trade_in_squeeze==no and squeeze==yes then double.nan else if squeezehist < 0 then 6 else 4; plot insqueeze = if squeeze == yes then yes else 1; plot chop = if show_historical_chop == yes then 1 else double.nan; ##styling ###Coloring volume.DefineColor(“Highest”, Color.GREEN); volume.DefineColor(“Lowest”, Color.LIGHT_RED); volume.AssignNormGradientColor(9, volume.Color(“Lowest”), volume.Color(“Highest”)); volume.Hide(); volume1.AssignValueColor(volume.TakeValueColor()); volume1.SetLineWeight(5); macd1.SetDefaultColor(Color.CYAN); macd2.SetDefaultColor(Color.CYAN); dmi1.SetDefaultColor(Color.CYAN); dmi2.SetDefaultColor(Color.CYAN); vortex1.SetDefaultColor(Color.CYAN); vortex2.SetDefaultColor(Color.CYAN); squeezehist1.SetDefaultColor(Color.CYAN); squeezehist2.SetDefaultColor(Color.CYAN); insqueeze.AssignValueColor(if squeeze == yes then Color.RED else Color.GREEN); insqueeze.SetPaintingStrategy(PaintingStrategy.POINTS); insqueeze.SetLineWeight(5); AddLabel(1, if CI <= 50 then “Trend Level: Trending” else if CI > 50 and CI <=68.2 then “Trend Level: Choppy” else “Trend Level: Very Choppy”, if CI <= 50 then Color.GREEN else if CI > 50 and CI <=68.2 then Color.YELLOW else Color.RED); chop.assignValueColor(if ci<=50 then color.dark_green else if ci>50 and ci<68.2 then color.yellow else color.dark_red); chop.setpaintingstrategy(PaintingStrategy.SQUARED_HISTOGRAM); ###clouds AddCloud(macd1, macd2, Color.GREEN, Color.RED); AddCloud(dmi1, dmi2, Color.GREEN, Color.RED); AddCloud(vortex1, vortex2, Color.GREEN, Color.RED); AddCloud(squeezehist1, squeezehist2, Color.GREEN, Color.RED); #special cloud #AddCloud(macd1, macd2, Color.GREEN, Color.RED); ###chartbubbles AddChartBubble(BarNumber() % 150 == 0 and show_bubbles==yes, 15, “MACD”, Color.YELLOW); AddChartBubble(BarNumber() % 150 == 0 and show_bubbles==yes, 11, “DMI”, Color.YELLOW); AddChartBubble(BarNumber() % 150 == 0 and show_bubbles==yes, 7, “Vortex”, Color.YELLOW); AddChartBubble(BarNumber() % 150 == 0 and show_bubbles==yes, 3, “Histogram”, Color.YELLOW); ##Signal def allignedlong = if macd1 == 18 and dmi1 == 14 and vortex1 == 10 and squeezehist1 == 6 then 18 else if show_shadow==yes then 4 else double.nan; def allignedshort = if macd2 == 18 and dmi2 == 14 and vortex2 == 10 and squeezehist2 == 6 then 18 else if show_shadow == yes then 4 else double.nan; AddCloud(allignedlong, allignedshort, Color.GREEN, Color.RED); ##T3 EMA Knot def n = 7; def n1 = 10; def n2 = 14; def n3 = 21; def vf = 0.7; def c = rsiwilder(); def a = (Inertia(c, n) * (1 + vf)) – (Inertia(Inertia(c, n), n) * vf); def GD = ExpAverage(a, n ); def T1 = ExpAverage(GD, n1); def T2 = ExpAverage(T1, n2); def T3 = ExpAverage(T2, n3); def data = NormalizePlot(GD,1,20); def data1 = NormalizePlot(t1,1,20); def data2 = NormalizePlot(t2,1,20); def data3 = NormalizePlot(t3,1,20); def knot1= if data>data1 then 1 else -1; def knot2= if data1>data2 then 1 else -1; def knot3= if data2>data3 then 1 else -1; def knot4= if data1>data3 then 1 else -1; def knot= knot1+knot2+knot3+knot4; #EMA Plots plot ema = if show_ema==yes then data else double.nan; plot ema1 = if show_ema==yes then data1 else Double.NaN; plot ema2 = if show_ema==yes then data2 else Double.NaN; plot ema3 = if show_ema==yes then data3 else Double.Nan; addlabel(1, if between(knot, -1, 1) then “Knot Level: Knotted” else if between(knot, -2, 2) then “Knot Level: Loose” else if knot>2 then “Knot Level: Long” else “Knot Level: Short”, if between(knot, -1, 1) then color.gray else if knot==2 then color.dark_green else if knot==-2 then color.dark_red else if knot==3 or knot==4 then color.green else color.red); #addlabel(1, knot, color.white); #Mini studies #plot minimacd1= normalizeplot(value,18,16); #plot minimacd2= normalizeplot(avg,18,16); plot minimacd= if show_mini_studies==yes then normalizeplot(macdosc * -1,19,15) else double.nan; plot minidmi= if show_mini_studies==yes then normalizeplot(dmiosc * -1,15,11) else double.nan; plot minivortex= if show_mini_studies==yes then normalizeplot(vortexosc * -1,11,7) else double.nan; plot minisqueeze= if show_mini_studies==yes then normalizeplot(squeezehist * -1,7,3) else double.nan; plot minimacdzero= if show_mini_studies==yes then 17 else double.nan; plot minidmizero= if show_mini_studies==yes then 13 else double.nan; plot minivortexzero= if show_mini_studies==yes then 9 else double.nan; plot minisqueezezero=if show_mini_studies==yes then 5 else double.nan; #miniplots minimacd.setdefaultcolor(color.magenta); minidmi.setdefaultcolor(color.magenta); minivortex.setdefaultcolor(color.magenta); minisqueeze.setdefaultcolor(color.magenta); minimacdzero.setdefaultcolor(color.white); minidmizero.setdefaultcolor(color.white); minivortexzero.setdefaultcolor(color.white); minisqueezezero.setdefaultcolor(color.white); #End script
declare lower; input length = 14; input trendSpeed = 25; input thresholdLine = 20; plot Threshold = thresholdLine; Threshold.setDefaultColor(color.green); Threshold.setStyle(curve.FIRM); Threshold.setLineWeight(2); plot Bullish_Power = DiPlus(length = length); Bullish_Power.setPaintingStrategy(paintingStrategy.HISTOGRAM); Bullish_Power.setLineWeight(5); Bullish_Power.setDefaultColor(color.white); plot Bearish_Power = DiMinus(length = length); Bearish_Power.setPaintingStrategy(paintingStrategy.HISTOGRAM); Bearish_Power.setLineWeight(5); Bearish_Power.setDefaultColor(color.red); plot Trend_Speed = ADX(length = length); Trend_Speed.setDefaultColor(color.yellow); Trend_Speed.setLineWeight(5); alert(crosses(Bullish_Power, Bearish_Power, CrossingDirection.ABOVE), “Power Shift Bullish”, Alert.BAR, sound.Ring); alert(crosses(Bullish_Power, Bearish_Power, CrossingDirection.BELOW), “Power Shift Bearish”, Alert.BAR, sound.Ring); alert(crosses(Trend_Speed, Threshold, CrossingDirection.ABOVE), “Trending”, Alert.BAR, sound.Ring); alert(crosses(Trend_Speed, Threshold, CrossingDirection.BELOW), “Choppy”, Alert.BAR, sound.Ring); # end
# Input Declarations: AssignBackgroundColor(CreateColor(8, 0, 15)); input extendhighway = yes; input gobubbleposition = 3; input showvaluearea = yes; input mult = 1.0; #Multiple of Average True Range to use input length = 10; #Average True Range period # # Input to select Close or High/Low for switching: # input Style = {default Close, HighLow}; input tickdecimal = 2; def type; switch (Style){ case Close: type = 1; case HighLow: type = 0; } # # Set parameters based on switch selection: # def uu = if type then close else high; def ll = if type then close else low; def na = Double.NaN; # # Calculate average range for volatility: # def atr = ExpAverage(high – low, length); # # Calculate initial short and long volatility stop values: # def svs = low + Ceil(mult * atr / TickSize()) * TickSize(); def lvs = high – Ceil(mult * atr / TickSize()) * TickSize(); # # Set up the trailing stop logic: # rec shortvs = if IsNaN(shortvs[1]) then svs else if uu > shortvs[1] then svs else Min(svs, shortvs[1]); rec longvs = if IsNaN(longvs[1]) then lvs else if ll < longvs[1] then lvs else Max(lvs, longvs[1]); # # Detect if we breached the trailing stop (close or high/low): # def longswitch = if uu >= shortvs[1] and uu[1] < shortvs[1] then 1 else 0; def shortswitch = if ll <= longvs[1] and ll[1] > longvs[1] then 1 else 0; # # This logic remembers the direction and changes when needed: # rec direction = CompoundValue(1, if IsNaN(direction[1]) then 0 else if direction[1] <= 0 and longswitch then 1 else if direction[1] >= 0 and shortswitch then -1 else direction[1], 0); # # Set up the two plots. “na” makes the current value disappear # if we?re trading in the opposite direction: # # # Alerts: # def alerttrigger = if direction[1] <= 0 and longswitch then 1 else if direction[1] >= 0 and shortswitch then 1 else 0; input alerttext = “Alert Text”; # BLOCK CODE BELOW input UseAlerts = {false, default true}; input AlertType = {default “BAR”, “ONCE”, “TICK”}; def at = AlertType; input AlertSound = {“Bell”, “Chimes”, default “Ding”, “NoSound”, “Ring”}; Alert(alerttrigger and UseAlerts, alerttext, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound); def short = if direction > 0 then na else shortvs; def long = if direction < 0 then na else longvs; plot bestradelong = if long then long else Double.NaN; # # Formatting: # bestradelong.SetDefaultColor(Color.GREEN); bestradelong.SetStyle(Curve.POINTS); bestradelong.SetLineWeight(2); bestradelong.HideBubble(); plot bestradeshort = if short then short else Double.NaN; bestradeshort.SetDefaultColor(Color.RED); bestradeshort.SetStyle(Curve.POINTS); bestradeshort.SetLineWeight(2); bestradeshort.HideBubble(); input brackets = 4; rec shortexit3 = short – atr; rec shortentry = short – (atr / brackets); rec shortentry1 = short – 2 * (atr / brackets); rec shortentry2 = short – 3 * (atr / brackets); rec longexit3 = long + atr; rec longentry = long + (atr / brackets); rec longentry1 = long + 2 * (atr / brackets); rec longentry2 = long + 3 * (atr / brackets); AddLabel(long, “Entry ” + Round(long, tickdecimal), Color.GREEN); AddLabel(long, “Exit ” + Round(longexit3, tickdecimal), Color.RED); AddLabel(long, ” ATR = ” + Round(atr, tickdecimal), Color.CYAN); AddLabel(long, “Slow Lane ” + Round(longentry, tickdecimal), Color.GREEN); AddLabel(long, “Cruising ” + Round(longentry1, tickdecimal), Color.GREEN); AddLabel(long, “Fast Lane ” + Round(longentry2, tickdecimal), Color.GREEN); AddLabel(short, “Entry ” + Round(short, tickdecimal), Color.RED); AddLabel(short, “Exit ” + Round(shortexit3, tickdecimal), Color.GREEN); AddLabel(short, ” ATR = ” + Round(atr, tickdecimal), Color.CYAN); AddLabel(short, “Slow Lane ” + Round(shortentry, tickdecimal), Color.RED); AddLabel(short, “Cruising ” + Round(shortentry1, tickdecimal), Color.RED); AddLabel(short, “Fast Lane ” + Round(shortentry2, tickdecimal), Color.RED); def longexitdot = if long then longexit3 else Double.NaN; def shortexitdot = if short then shortexit3 else Double.NaN; plot longexitdot1 = if long then longexitdot else Double.NaN; longexitdot1.SetDefaultColor(Color.RED); longexitdot1.SetStyle(Curve.POINTS); longexitdot1.SetLineWeight(1); longexitdot1.HideBubble(); plot shortexitdot1 = if short then shortexitdot else Double.NaN; shortexitdot1.SetDefaultColor(Color.GREEN); shortexitdot1.SetStyle(Curve.POINTS); shortexitdot1.SetLineWeight(1); shortexitdot1.HideBubble(); # Clouds #AddCloud(shortexitdot1, bestradeshort); #AddCloud(longexitdot1, bestradelong); AddCloud(shortexitdot1, bestradeshort, color1 = Color.WHITE, color2 = CreateColor(174, 74, 189)); AddCloud(longexitdot1, bestradelong, color1 = Color.YELLOW, color2 = Color.GREEN); plot longentry14 = if long then longentry else Double.NaN; longentry14.SetDefaultColor(Color.CYAN); longentry14.SetStyle(Curve.SHORT_DASH); longentry14.SetLineWeight(1); longentry14.HideBubble(); plot halflongentry = if long then longentry1 else Double.NaN; halflongentry.SetDefaultColor(Color.CYAN); halflongentry.SetStyle(Curve.SHORT_DASH); halflongentry.SetLineWeight(1); halflongentry.HideBubble(); plot longentry34 = if long then longentry2 else Double.NaN; longentry34.SetDefaultColor(Color.CYAN); longentry34.SetStyle(Curve.SHORT_DASH); longentry34.SetLineWeight(1); longentry34.HideBubble(); plot shortentry14 = if short then shortentry else Double.NaN; shortentry14.SetDefaultColor(Color.CYAN); shortentry14.SetStyle(Curve.SHORT_DASH); shortentry14.SetLineWeight(1); shortentry14.HideBubble(); plot shorthalfentry = if short then shortentry1 else Double.NaN; shorthalfentry.SetDefaultColor(Color.CYAN); shorthalfentry.SetStyle(Curve.SHORT_DASH); shorthalfentry.SetLineWeight(1); shorthalfentry.HideBubble(); plot shortentry34 = if short then shortentry2 else Double.NaN; shortentry34.SetDefaultColor(Color.CYAN); shortentry34.SetStyle(Curve.SHORT_DASH); shortentry34.SetLineWeight(1); shortentry34.HideBubble(); input showarrows = yes; input arrowoffset = 1; plot longtrendarrow = showarrows and long – TickSize() * arrowoffset; longtrendarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); longtrendarrow.SetDefaultColor(Color.GREEN); longtrendarrow.SetLineWeight(1); longtrendarrow.HideBubble(); plot shorttrendarrow = showarrows and short + TickSize() * arrowoffset; ; shorttrendarrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); shorttrendarrow.SetDefaultColor(Color.RED); shorttrendarrow.SetLineWeight(1); shorttrendarrow.HideBubble(); #Bubbles # set right expansion to 10; input bubbledisplace = .05; def bubbledisplace1 = bubbledisplace * 2; def bubbledisplace2 = bubbledisplace * 3; def bubbledisplace3 = bubbledisplace * 4; input lanebubbleposition = 0; def n = lanebubbleposition; def n1 = n + 1; input showbubbles = yes; def q = gobubbleposition; def q1 = q + 1; input lineposition = 0.75; def r = lineposition; def r1 = r + 1; input showlines = yes; def longticks = longexit3 – close; def shorticks = close – shortexit3; def longloss = long – close; def shortloss = close – short; AddChartBubble(showbubbles and !IsNaN(close[q1]) and IsNaN(close[q]) and long[q1], close[q1], if close[q1] < longentry[q1] then “Go” + “\n” + “Long!” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(longticks[q1], tickdecimal) + ” \nL: ” + Round(longloss[q1], tickdecimal) else if close[q1] < longentry1[q1] then “Long” + “\n” + “Slow” + “\n” + “Lane” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(longticks[q1], tickdecimal) + ” \nL: ” + Round(longloss[q1], tickdecimal) else if close[q1] < longentry2[q1] then “Long” + “\n” + ” Cruising” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(longticks[q1], tickdecimal) + ” \nL: ” + Round(longloss[q1], tickdecimal) else if close[q1] < longexitdot[q1] then “Long” + “\n” + ” Fast” + “\n” + ” Lane” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(longticks[q1], tickdecimal) + ” \nL: ” + Round(longloss[q1], tickdecimal) else “Exit” + “\n” + “Long” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(longticks[q1], tickdecimal) + ” \nL: ” + Round(longloss[q1], tickdecimal), if close[q1] < longentry[q1] then CreateColor(51, 255, 51) else if close[q1] < longentry1[q1] then CreateColor(0, 255, 0) else if close[q1] < longentry2[q1] then CreateColor(0, 204, 0) else Color.RED); plot golongline = if showlines and !IsNaN(close[q1]) and IsNaN(close[q]) and long[q1] then close[q1] else Double.NaN; golongline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); golongline.SetDefaultColor(Color.GREEN); golongline.HideBubble(); AddChartBubble(showbubbles and !IsNaN(close[q1]) and IsNaN(close[q]) and short[q1], close[q1], if close[q1] > shortentry[q1] then “Go” + “\n” + “Short!” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(shorticks[q1], tickdecimal) + ” \nL: ” + Round(shortloss[q1], tickdecimal) else if close[q1] > shortentry1[q1] then “Short” + “\n” + “Slow” + “\n” + “Lane” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(shorticks[q1], tickdecimal) + ” \nL: ” + Round(shortloss[q1], tickdecimal) else if close[q1] > shortentry2[q1] then “Short” + “\n” + “Cruising” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(shorticks[q1], tickdecimal) + ” \nL: ” + Round(shortloss[q1], tickdecimal) else if close[q1] > shortexitdot[q1] then “Short” + “\n” + “Fast” + “\n” + “Lane” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(shorticks[q1], tickdecimal) + ” \nL: ” + Round(shortloss[q1], tickdecimal) else “Exit” + “\n” + “Short” + “\n ” + Round(close[q1], tickdecimal) + ” \nP: ” + Round(shorticks[q1], tickdecimal) + ” \nL: ” + Round(shortloss[q1], tickdecimal), if close[q1] > shortentry[q1] then CreateColor(255, 102, 102) else if close[q1] > shortentry1[q1] then Color.RED else if close[q1] > shortentry2[q1] then Color.RED else Color.GREEN); plot goshortline = if showlines and !IsNaN(close[q1]) and IsNaN(close[q]) and short[q1] then close[q1] else Double.NaN; goshortline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); goshortline.SetDefaultColor(Color.RED); goshortline.HideBubble(); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1] , short[n1] + bubbledisplace, “ATR = ” + Round(atr[n1], tickdecimal), Color.CYAN); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1], long[n1] – bubbledisplace, “ATR = ” + Round(atr[n1], tickdecimal), Color.CYAN); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1], long[n1], “Entry ” + Round(long[n1], tickdecimal), CreateColor(102, 255, 102)); def longentrylinevalue = if IsNaN(close) then longentrylinevalue[1] else long; plot longentryline = if !IsNaN(close) then Double.NaN else longentrylinevalue; longentryline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); longentryline.SetDefaultColor(Color.GREEN); longentryline.HideBubble(); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1] , longentry[n1], ” Slow Lane: ” + Round(longentry[n1], tickdecimal), Color.GREEN); def longentry14value = if IsNaN(close) then longentry14value[1] else longentry; plot longentryline14 = if !IsNaN(close) then Double.NaN else longentry14value; longentryline14.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); longentryline14.SetDefaultColor(Color.GREEN); longentryline14.HideBubble(); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1], longentry1[n1], ” Cruising: ” + Round(longentry1[n1], tickdecimal), Color.GREEN); def longentry12value = if IsNaN(close) then longentry12value[1] else longentry1; plot longentryline12 = if !IsNaN(close) then Double.NaN else longentry12value; longentryline12.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); longentryline12.SetDefaultColor(Color.GREEN); longentryline12.HideBubble(); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1], longentry2[n1], ” Fast Lane: ” + Round(longentry2[n1], tickdecimal), Color.DARK_GREEN); def longentry34value = if IsNaN(close) then longentry34value[1] else longentry2; plot longentryline34 = if !IsNaN(close) then Double.NaN else longentry34value; longentryline34.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); longentryline34.SetDefaultColor(Color.GREEN); longentryline34.HideBubble(); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and long[n1], longexit3[n1], “Exit: ” + Round(longexit3[n1], tickdecimal), Color.RED); def longexitlinevalue = if IsNaN(close) then longexitlinevalue[1] else longexitdot; plot longexitline = if !IsNaN(close) then Double.NaN else longexitlinevalue; longexitline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); longexitline.SetDefaultColor(Color.RED); longexitline.HideBubble(); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1] , short[n1], “Entry ” + Round(short[n1], tickdecimal), Color.RED); def shortentrylinevalue = if IsNaN(close) then shortentrylinevalue[1] else short; plot shortentryline = if !IsNaN(close) then Double.NaN else shortentrylinevalue; shortentryline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); shortentryline.SetDefaultColor(Color.RED); shortentryline.HideBubble(); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1] , shortexit3[n1], “Exit ” + Round(shortexit3[n1], tickdecimal), Color.GREEN); def shortexitlinevalue = if IsNaN(close) then shortexitlinevalue[1] else shortexit3; plot shortexitline = if !IsNaN(close) then Double.NaN else shortexitlinevalue; shortexitline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); shortexitline.SetDefaultColor(Color.GREEN); shortexitline.HideBubble(); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1] , shortentry[n1], ” Slow Lane: ” + Round(shortentry[n1], tickdecimal), Color.RED); def shortentryline14value = if IsNaN(close) then shortentryline14value[1] else shortentry; plot shortentryline14 = if !IsNaN(close) then Double.NaN else shortentryline14value; shortentryline14.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); shortentryline14.SetDefaultColor(Color.RED); shortentryline14.HideBubble(); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1] , shortentry1[n1], ” Cruising: ” + Round(shortentry1[n1], tickdecimal), Color.RED); def shortentryline12value = if IsNaN(close) then shortentryline12value[1] else shortentry1; plot shortentryline12 = if !IsNaN(close) then Double.NaN else shortentryline12value; shortentryline12.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); shortentryline12.SetDefaultColor(Color.RED); shortentryline12.HideBubble(); AddChartBubble(showbubbles and !IsNaN(close[n1]) and IsNaN(close[n]) and short[n1] , shortentry2[n1], ” Fast Lane: ” + Round(shortentry2[n1], tickdecimal), Color.DARK_RED); def shortentryline34value = if IsNaN(close) then shortentryline34value[1] else shortentry2; plot shortentryline34 = if !IsNaN(close) then Double.NaN else shortentryline34value; shortentryline34.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); shortentryline34.SetDefaultColor(Color.RED); shortentryline34.HideBubble(); input trendbubbledisplace = .10; input chartbubbleoffset = 1; input trendlabel = no; AddChartBubble(trendlabel and long[1] and short , high + TickSize() * chartbubbleoffset , ” Downtrend “, Color.RED); AddChartBubble(trendlabel and short[1] and long , low – TickSize() * chartbubbleoffset, ” Uptrend “, Color.GREEN, no); # Extension Plot # rec ssf = if !IsNaN(SuperSmootherFilter) then SuperSmootherFilter else ssf[1] + (ssf[1] – ssf[2]); #plot ssfextension = if(extendssf) then ssf else double.NaN; rec highwayextshort = if !IsNaN(shortexitdot1) then shortexitdot1 else highwayextshort[1] + (highwayextshort[1] – highwayextshort[2]); plot highwayextensionshort = if (extendhighway) and !isNan (shortexitdot1[2]) then highwayextshort else Double.NaN; rec highwayextshort1 = if !IsNaN(bestradeshort) then bestradeshort else highwayextshort1[1] + (highwayextshort1[1] – highwayextshort1[2]); plot highwayextensionshort1 = if (extendhighway) and !isNan (bestradeshort[2]) then highwayextshort1 else Double.NaN; rec highwayextlong = if !IsNaN(longexitdot1) then longexitdot1 else highwayextlong[1] + (highwayextlong[1] – highwayextlong[2]); plot highwayextensionlong = if (extendhighway) and !isNan(longexitdot1[2]) then highwayextlong else Double.NaN; rec highwayextlong1 = if !IsNaN(bestradelong) then bestradelong else highwayextlong1[1] + (highwayextlong1[1] – highwayextlong1[2]); plot highwayextensionlong1 = if (extendhighway) and !isNan(bestradelong[2]) then highwayextlong1 else Double.NaN; #Cloud Extension AddCloud(highwayextensionshort, highwayextensionshort1, color1 = Color.red, color2 = color.red); AddCloud(highwayextensionlong1, highwayextensionlong, color1 = Color.green, color2 = color.green);
declare lower; input audioalarm=yes; input Price = hlc3; input RsqLength = 5; input RsqLimit = .5; input SmiLimit = 30; input chopband2= 70; input smibarbufr = 4; def overbought = SmiLimit; def oversold = -SmiLimit; def percentDLength = 4; def percentKLength = 5; #Stochastic momentum index (SMI) def min_low = Lowest(low, percentKLength); def max_high = Highest(high, percentKLength); def rel_diff = close – (max_high + min_low) / 2; def diff = max_high – min_low; def avgrel = ExpAverage(ExpAverage(rel_diff, percentDLength), percentDLength); def avgdiff = ExpAverage(ExpAverage(diff, percentDLength), percentDLength); plot chopband = if IsNaN(close) then Double.NaN else 0; plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0; #SMI.SetDefaultColor(Color.BLUE); smi.DefineColor(“Up”, CreateColor(0, 153, 51)); smi.definecolor(“weak”, color.light_gray); smi.DefineColor(“Down”, Color.RED); smi.AssignValueColor(if smi > smi[1] then smi.Color(“Up”) else if smi < smi[1] then smi.color(“down”) else smi.Color(“weak”)); smi.SetLineWeight(2); SMI.SetStyle(Curve.SHORT_DASH); SMI.SetLineWeight(3); PLOT AvgSMI = ExpAverage(SMI, percentDLength); AVGsmi.DefineColor(“Up”, CreateColor(0, 153, 51)); avgsmi.definecolor(“weak”, color.light_gray); AVGsmi.DefineColor(“Down”, Color.RED); avgsmi.AssignValueColor(if avgsmi > avgsmi[1] then avgsmi.Color(“Up”) else if avgsmi < avgsmi[1] then avgsmi.color(“down”) else avgsmi.Color(“weak”)); AVGsmi.SetLineWeight(3); #smi1.SetPaintingStrategy(PaintingStrategy.DASHES); plot smiBAR = AvgSMI; smiBAR.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); smiBAR.SetLineWeight(3); smiBAR.DefineColor(“upstrong”, CreateColor (0, 255, 0)); smiBAR.DefineColor(“weak”, Color.LIGHT_GRAY); smiBAR.DefineColor(“downstrong”, CreateColor(255, 51, 51)); smiBAR.AssignValueColor (if (smi + smibarbufr) >= smi[1] and smi > -SmiLimit then smiBAR.Color(“upstrong”) else if (smi – smibarbufr) <= smi[1] and smi < SmiLimit then smiBAR.Color(“downstrong”) else smiBAR.Color(“weak”)); #r-Square centerline indicator #def sma = Average(close, RsqLength); #def RSq = Sqr(WMA(close, RsqLength) – sma) / (Average(Sqr(close), RsqLength) – Sqr(sma)) * 3 * (RsqLength + 1) / (RsqLength – 1); chopband.HideBubble(); chopband.SetLineWeight(5); chopband.DefineColor(“Trade”, createColor(0, 150,200)); chopband.DefineColor(“Hold”, Color.orange); chopband.AssignValueColor(if smi > -smiLimit and smi < smilimit then chopband.Color(“hold”) else chopband.Color(“trade”)); #Chop Cloud plot upper= smilimit; plot lower= -smilimit; upper.setDefaultColor(color.GRAY); lower.setDefaultColor(color.gRAY); def choplimits = SmiLimit; #input choplimits= 1; AddCloud(choplimits, -choplimits,createColor(210,210,210)); #addcloud(-choplimits,-chopband2,createcolor(175,175,175)); #addcloud(chopband2,choplimits,createcolor(175,175,175)); #Labels #AddLabel(yes, “SMI Legend: “, Color.BLACK); #AddLabel(yes, “BULLISH”, Color.UPTICK); #AddLabel(yes, “BEARISH”, Color.DOWNTICK); #AddLabel(yes, “changing”, Color.GRAY); #AddLabel(yes, “MidLine: “, Color.BLACK); #AddLabel(yes, “Trending”, createColor(0,150,200)); #AddLabel(yes, “in ChopZone”, Color.ORANGE); #AddLabel(yes, ” SmiLimit= ” + SmiLimit, Color.DARK_GRAY); alert (audioalarm and smi crosses avgsmi and smi <= -smilimit or SMI CROSSes AVGSMI AND Smi >= smilimit,”SMI CROSS”, alert.bar, sound.ring);
declare lower; input threeX_K_period = 21; input threeX_D_period = 9; input threeXsmoothing = 3; input oneX_K_period = 14; input oneX_D_period = 3; input oneXsmoothing = 3; input smoothing_type = AverageType.SIMPLE; input threeXstochType = { FAST, default SLOW }; input oneXstochType = { FAST, default SLOW }; input over_bought = 75; input over_sold = 25; input maxLookback = 3; def BarNum = if IsNaN( close ) then Double.NaN else BarNumber(); def aggPer = getAggregationPeriod(); def adjAggPer = if aggPer == AggregationPeriod.MIN then AggregationPeriod.THREE_MIN else if aggPer == AggregationPeriod.TWO_MIN then AggregationPeriod.FIVE_MIN else if aggPer == AggregationPeriod.THREE_MIN then AggregationPeriod.TEN_MIN else if aggPer == AggregationPeriod.FOUR_MIN then AggregationPeriod.TEN_MIN else if aggPer == AggregationPeriod.FIVE_MIN then AggregationPeriod.FIFTEEN_MIN else if aggPer == AggregationPeriod.TEN_MIN then AggregationPeriod.THIRTY_MIN else if aggPer == AggregationPeriod.FIFTEEN_MIN then AggregationPeriod.HOUR else if aggPer == AggregationPeriod.TWENTY_MIN then AggregationPeriod.HOUR else if aggPer == AggregationPeriod.THIRTY_MIN then AggregationPeriod.TWO_HOURS else if aggPer == AggregationPeriod.HOUR then AggregationPeriod.FOUR_HOURS else if aggPer == AggregationPeriod.TWO_HOURS then AggregationPeriod.DAY else if aggPer == AggregationPeriod.FOUR_HOURS then AggregationPeriod.DAY else if aggPer == AggregationPeriod.DAY then AggregationPeriod.THREE_DAYS else if aggPer == AggregationPeriod.TWO_DAYS then AggregationPeriod.WEEK else if aggPer == AggregationPeriod.THREE_DAYS then AggregationPeriod.WEEK else if aggPer == AggregationPeriod.FOUR_DAYS then AggregationPeriod.MONTH else if aggPer == AggregationPeriod.WEEK then AggregationPeriod.MONTH else if aggPer == AggregationPeriod.MONTH then AggregationPeriod.MONTH else Double.NaN; def _kPeriod = threeX_K_period; def _dPeriod = threeX_D_period; def _threeXsmoothing = threeXsmoothing; def threeXhighestHigh = highest( high( period = adjAggPer ), _kPeriod ); def threeXlowestLow = lowest( low( period = adjAggPer ), _kPeriod ); def threeXfastK = if ( threeXhighestHigh – threeXlowestLow ) <= 0 then 0 else 100 * ( close( period = adjAggPer ) – threeXlowestLow ) / ( threeXhighestHigh – threeXlowestLow ); def threeXfastD = MovingAverage( smoothing_type, threeXfastK, _dPeriod ); def threeXslowK = threeXfastD; def threeXslowD = MovingAverage( smoothing_type, threeXslowK, _dPeriod ); def oneXfastK = if ( highest( high, oneX_K_period ) – lowest( low, oneX_K_period ) ) <= 0 then 0 else 100 * ( close – lowest( low, oneX_K_period ) ) / ( highest( high, oneX_K_period ) – lowest( low, oneX_K_period ) ); def oneXfastD = MovingAverage( smoothing_type, oneXfastK, oneX_D_period ); def oneXslowK = oneXfastD ; def oneXslowD = MovingAverage( smoothing_type, oneXslowK , oneX_D_Period ); #—Stochastic plot ThreeX_Momentum = if threeXstochType == threeXstochType.FAST then threeXfastD else threeXslowD; plot OneX_Trend = if oneXstochType == oneXstochType.FAST then oneXfastD else oneXslowD; #—Reference lines plot OverBought = over_bought; plot OverSold = over_sold; def state = { default init, up, down }; switch( state[1] ) { case init: if barNum == 1 then { state = state.init; } else { state = if ThreeX_Momentum > ThreeX_Momentum[1] then state.up else if ThreeX_Momentum < ThreeX_Momentum[1] then state.down else state.init; } case up: state = if ThreeX_Momentum >= ThreeX_Momentum[1] then state.up else state.down; case down: state = if ThreeX_Momentum <= ThreeX_Momentum[1] then state.down else state.up; } #===============================[ Look & Feel ]================================ ThreeX_Momentum.SetPaintingStrategy( PaintingStrategy.LINE_VS_POINTS ); ThreeX_Momentum.AssignValueColor( if state == state.up then Color.DARK_GREEN else if state == state.down then Color.DARK_RED else Color.GRAY ); ThreeX_Momentum.HideBubble(); OneX_Trend.SetPaintingStrategy( PaintingStrategy.LINE ); OneX_Trend.AssignValueColor( if OneX_Trend >= OneX_Trend[1] then Color.GREEN else if OneX_Trend < OneX_Trend[1] then Color.RED else Color.GRAY ); OneX_Trend.HideBubble(); OverBought.SetDefaultColor( Color.LIGHT_GRAY ); OverBought.HideTitle(); OverSold.SetDefaultColor( Color.DARK_GRAY ); OverSold.HideTitle(); def Hundred = 100; AddCloud( OverBought, Hundred, Color.LIGHT_GRAY, Color.LIGHT_GRAY ); def Zero = 0; AddCloud( OverSold, Zero, Color.DARK_GRAY, Color.DARK_GRAY );
declare upper; input indicator = { T1, T2, default T3, T4, T5, T6 }; input price = close; input period = 10; input volumeFactor = 0.70; input sign = { default plus, minus }; script _gd { input _price = close; input _period = 10; input _v = 0.70; input _sign = { default plus, minus }; def _ema = ExpAverage( _price, _period ); plot _gd = ( _ema * ( 1 + _v ) ) – ( ExpAverage( _ema, _period ) * _v ); } def _t1 = _gd( price, period, volumeFactor, sign ); def _t2 = _gd( _t1, period, volumeFactor, sign ); def _t3 = _gd( _t2, period, volumeFactor, sign ); def _t4 = _gd( _t3, period, volumeFactor, sign ); def _t5 = _gd( _t4, period, volumeFactor, sign ); def _t6 = _gd( _t5, period, volumeFactor, sign ); plot T3; switch( indicator ) { case T1: T3 = _t1; case T2: T3 = _t2; case T3: T3 = _t3; case T4: T3 = _t4; case T5: T3 = _t5; case T6: T3 = _t6; } T3.DefineColor(“Up”, GetColor(1)); T3.DefineColor(“Down”, GetColor(0)); T3.AssignValueColor(if T3 > T3[1] then T3.color(“Up”) else T3.color(“Down”)); T3.DefineColor(“Up”, GetColor(1)); T3.DefineColor(“Down”, GetColor(0)); T3.AssignValueColor(if T3 > T3[1] then T3.color(“Up”) else T3.color(“Down”));

Thinkorswim Indicators Stock Markets, Business News, Financials, Stock Charts