thinkScript

#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 

Leave a Reply