$TICK Charts, Divergences, Labels, etc for ThinkorSwim

Trader_Vic

New member
VIP
Hi Guys! I joined this site a few months ago and this is such an amazing site for traders and coders to come together. I would need some help from someone who can write a code with this Strategy. I trade /ES on 5 Min & 1 Min Chart with $TICK as the bottom indicator. I usually draw lines every time there is a divergence or a flag formation for the TICKS to go Long or Short. I would need help from coders on this site to help me with the CODE.

vP6e5uS.png
 
Last edited by a moderator:
  • Like
Reactions: GOS
This indicator will show the NYSE $TICK index as a lower study in your ThinkorSwim. Great for anyone who wants to easily track the market internal while looking at the indices like SPY.
  • When TICK value is above 800 = market is considered overbought
  • When TICK value is below -800 = market is considered oversold
QSviJjg.png


thinkScript Code

Code:
# Simple TICK
# Assembled by BenTen at UseThinkScript.com

declare lower;

def value = close("$TICK");
plot tick = value;
plot ob1 = 800;
plot ob2 = 1000;
plot os1 = -800;
plot os2 = -1000;
tick.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
ob1.assignvaluecolor(color.light_red);
ob2.assignValueColor(color.red);
os1.assignvaluecolor(color.light_green);
os2.assignValueColor(color.green);
 
I found this, not sure if it's what you guys are looking for:

Code:
# $TICK Oscillator with Divergence
# Mobius
# V01.03.2020

declare lower;

input length = 5;
input AvgType = AverageType.HULL;

addLabel(1, "Green Line sloping up or red sloping down is divergence", color.white);
def o = open("$TICK");
def h = high("$TICK");
def l = low("$TICK");
def c = close("$TICK");
def x = BarNumber();
def nan = Double.NaN;
AddChart(h, l, c, o, ChartType.CANDLE, Color.YELLOW);
AddChart(h, l, o, c, ChartType.CANDLE, Color.CYAN);
def RTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
          GetTime() <= RegularTradingEnd(GetYYYYMMDD());
plot "0" = if !RTH then Double.NaN else 0;
     "0".SetDefaultColor(Color.MAGENTA);
     "0".HideBubble();
     "0".HideTitle();
plot avg = MovingAverage(AvgType, c, length);
     avg.AssignValueColor(if avg < 0
                          then color.red
                          else color.green);
     avg.HideBubble();
     avg.HideTitle();
addCloud(0, avg, color.red, color.green);
plot upArrow = if avg crosses above 0
               then l
               else double.nan;
     upArrow.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
     upArrow.SetDefaultColor(Color.Green);
     upArrow.SetLineWeight(3);
     upArrow.HideBubble();
     upArrow.HideTitle();
plot dnArrow = if avg crosses below 0
               then h
               else double.nan;
     dnArrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
     dnArrow.SetDefaultColor(Color.Red);
     dnArrow.SetLineWeight(3);
     dnArrow.HideBubble();
     dnArrow.HideTitle();
def hh = if avg crosses above 0
         then h
         else if avg > 0 and h > hh[1]
         then h
         else hh[1];
def xh = if h == hh
         then x
         else xh[1];
plot hp = if x == highestAll(xh)
          then hh
          else nan;
     hp.SetStyle(Curve.Points);
     hp.SetDefaultColor(Color.red);
     hp.SetLineWeight(3);
     hp.HideBubble();
     hp.HideTitle();
def xh1 = if !isNaN(dnArrow)
          then getValue(xh, 2)
          else xh1[1];
plot hp1 = if x == highestAll(xh1)
           then h
           else nan;
     hp1.SetStyle(Curve.Points);
     hp1.SetDefaultColor(Color.red);
     hp1.SetLineWeight(3);
     hp1.HideBubble();
     hp1.HideTitle();
plot hd = if x == highestAll(xh1)
          then h
          else if x == highestAll(xh)
          then h
          else nan;
     hd.EnableApproximation();
     hd.SetDefaultColor(Color.red);
     hd.HideBubble();
     hd.HideTitle();
def ll = if avg crosses below 0
         then l
         else if avg < 0 and l < ll[1]
         then l
         else ll[1];
def xl = if l == ll
         then x
         else xl[1];
plot lp = if x == highestAll(xl)
          then ll
          else nan;
     lp.SetStyle(Curve.Points);
     lp.SetDefaultColor(Color.green);
     lp.SetLineWeight(3);
     lp.HideBubble();
     lp.HideTitle();
def xl1 = if !isNaN(dnArrow)
          then xl[1]
          else xl1[1];
plot lp1 = if x == highestAll(xl1)
           then l
           else nan;
     lp1.SetStyle(Curve.Points);
     lp1.SetDefaultColor(Color.green);
     lp1.SetLineWeight(3);
     lp1.HideBubble();
     lp1.HideTitle();
plot ld = if x == highestAll(xl1)
          then l
          else if x == highestAll(xl)
          then l
          else nan;
     ld.EnableApproximation();
     ld.SetDefaultColor(Color.green);
     ld.HideBubble();
     ld.HideTitle();
# End Code TICK Oscillator with Divergence


# AI Adds

def lastHP = if x == highestAll(xh)
then xh else lastHP[1];
def lastHP1 =  if x == highestAll(xh1)
then xh1 else lastHP[1];
def lastLP = if x == highestAll(xl)
then xl else lastLP[1];
def lastLP1 =  if x == highestAll(xl1)
then xl1 else lastLP1[1];

Addlabel(lastHP1<lastHP,"Divergent",color.red);
Addlabel(lastLP1>lastLP,"Divergent",color.green);
 
Wow! this is great! Thanks @BenTen !!!. I'm not the original poster but this is what I'm looking for. Can't speak for Trader_Vic. I really appreciate you finding this and for Mobius creating this.
 
have a slightly different way of plotting tick, figured I'd post it here, also includes alerts when tick reaches specified threshold (default +/- 1000) and plots a vertical line when threshold is reached, plus labels for breadth ratio, put/call ratio, and vix:
X2pPKNV.png

the labels are dark due to markets being closed, but the blue represents the tick high, orange is tick low and green or red depends on if it closes above or below zeroline. I find it easier to see the slope of the $tick trend this way.
Code:
#[email protected]
declare lower;

input alerttype = Alert.BAR;
input alertsound = Sound.DING;
input alertThreshold = 1000;

plot zeroline = 0;
plot tick500 = 500;
plot tick500m = -500;
plot tick1000 = 1000;
plot tick1000m = -1000;

DefineGlobalColor("Vertical Line Color", Color.WHITE);

def NA = Double.NaN;
def ticko = open("$TICK");
plot tickc = close("$TICK");
plot tickh = high("$TICK");
plot tickl = low("$TICK");

def tickh1000test = tickh >= alertThreshold;
def tickl1000test = tickl <= -alertThreshold;
Alert(tickh1000test, " >+1000 $TICK", alerttype, alertsound);
Alert(tickl1000test, " <-1000 $TICK", alerttype, alertsound);
AddVerticalLine(tickh1000test, "+"+alertThreshold, GlobalColor("Vertical Line Color"));
AddVerticalLine(tickl1000test, "-"+alertThreshold, GlobalColor("Vertical Line Color"));

def PCALL = Round(close("$PCALL"),2);
def NYSEUVOL = close("$UVOL");
def NYSEDVOL = close("$DVOL");

def BR = Round(if NYSEUVOL >= NYSEDVOL then NYSEUVOL / NYSEDVOL else -(NYSEDVOL/NYSEUVOL),2);
AddLabel(1,"$TICK: "+ tickc, if tickc > 0 then Color.GREEN else Color.RED);
AddLabel(1,"BR: " + BR ,if BR > 0 then Color.GREEN else Color.RED);
AddLabel(1,"$PCALL: " + PCALL, Color.GRAY);
AddLabel(1, "VIX: "+ close("VIX"), Color.GRAY);

zeroline.SetDefaultColor(Color.BLACK);
tick500.SetDefaultColor(Color.GRAY);
tick500m.SetDefaultColor(Color.GRAY);
tick1000.SetDefaultColor(Color.GRAY);
tick1000m.SetDefaultColor(Color.GRAY);
tick1000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
tick1000m.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
tick1000.SetLineWeight(2);
tick1000m.SetLineWeight(2);

tickh.SetPaintingStrategy(PaintingStrategy.Squared_HISTOGRAM);
tickh.SetDefaultColor(CreateColor(0,100,200));
tickl.SetPaintingStrategy(PaintingStrategy.Squared_HISTOGRAM);
tickl.SetDefaultColor(Color.DARK_ORANGE);
tickc.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
tickc.AssignValueColor(if tickc > 0 then color.green else color.red);
 
Last edited:
Code:
# AD, TICK Study
# Mobius

declare lower;
def RTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
          GetTime() <= RegularTradingEnd(GetYYYYMMDD());

def x = if RTH and !RTH[1]
        then 1
        else if RTH then x[1] + 1
        else x[1];
def o = if RTH and !RTH[1]
        then open(symbol = "$ADSPD")
        else o[1];
def h = if RTH and !RTH[1]
        then high(symbol = "$ADSPD")
        else if high(symbol = "$ADSPD") > h[1]
             then high(symbol = "$ADSPD")
             else h[1];
def l = if RTH and !RTH[1]
        then low(symbol = "$ADSPD")
        else if low(symbol = "$ADSPD") < l[1]
             then low(symbol = "$ADSPD")
             else l[1];
def c = if IsNaN(close(symbol = "$ADSPD"))
        then c[1]
        else close(symbol = "$ADSPD");
def sumC = if RTH and !RTH[1]
           then c
           else if RTH
                then sumC[1] + c
                else sumC[1];

plot cumC = if RTH and !IsNaN(close)
            then sumC / x
            else Double.NaN;
     cumC.SetStyle(Curve.FIRM);
     cumC.AssignValueColor(if cumC > cumC[1]
                           then Color.GREEN
                           else Color.RED);
     cumC.SetLineWeight(1);
     cumC.HideBubble();
     cumC.HideTitle();

plot AD = if RTH and !IsNaN(close)
          then Round(Inertia(c, 13), 0)
          else Double.NaN;
     AD.SetStyle(Curve.FIRM);
     AD.SetLineWeight(2);
     AD.AssignValueColor(if AD > cumC and AD > AD[1]
                         then Color.DARK_GREEN
                         else if AD > cumC and AD < AD[1]
                              then Color.GREEN
                              else if AD < cumC and AD < AD[1]
                                   then Color.DARK_RED
                         else Color.RED);

AddLabel(1, "AD open = " + o +
          "  high = " + h +
          "  low = " + l +
          "  close = " + c, if AD < AD[1]
                              then Color.RED
                              else Color.GREEN);

def t = if IsNaN(close(symbol = "$TICK"))
        then t[1]
        else close(symbol = "$TICK");
def sumT = if RTH and !RTH[1]
           then t
           else if RTH
                then sumT[1] + t
                else sumT[1];
plot cumT = if RTH and !IsNaN(close)
            then sumT / x
            else Double.NaN;
     cumT.SetStyle(Curve.FIRM);
     cumT.AssignValueColor(if cumT > cumT[1]
                           then Color.BLUE
                          else Color.YELLOW);
     cumT.SetLineWeight(2);
     cumT.HideBubble();
     cumT.HideTitle();

plot avg_t = if RTH and !IsNaN(close)
             then Round(Inertia(t, 10), 0)
             else Double.NaN;
     avg_t.SetLineWeight(2);
     avg_t.AssignValueColor(if avg_t > cumT then Color.BLUE else Color.YELLOW);

plot zero = if RTH and !IsNaN(close("$TICK"))
            then 0
            else Double.NaN;
     zero.SetStyle(Curve.LONG_DASH);
     zero.SetDefaultColor(Color.Gray);
     zero.SetLineWeight(2);
AddCloud(cumC,  AD,  Color.RED,  Color.GREEN);
AddCloud(cumT, avg_t, Color.YELLOW, Color.BLUE);
AddCloud(0, if AD < cumC and AD > 0
            then AD
            else double.nan, Color.light_gray, color.light_gray);
AddLabel(1, "TICK = " + t, if avg_t > avg_t[1] then Color.GREEN else Color.RED);
Alert(t >= 1000, "", Alert.BAR, Sound.Ring);
Alert(t <= -1000, "", Alert.BAR, Sound.Bell);
AddVerticalLine(t crosses above 1000, "TICK 1000", Color.GREEN);
AddVerticalLine(t crosses below -1000, "TICK -1000", Color.RED);
# End Code


Does anyone know how to use this study? I could not find instruction in the onedrive. Thank you!

Edit: so after reviewing the code more the blue and yellow are attached to $ADSPD still not exactly sure what the Green and red are following. maybe lagging price on a longer period?
 
Last edited by a moderator:
Can someone code the following so when the edge of the line is sloping up its green, sloping down is red, and straight horizontal yellow? I'm trying to get a sense of all 4 indices if they are having positive or negatives ticks before I enter in a trade. Any other ideas greatly appreciated.

Code:
# Mobius Dev
# V03.25.2017

declare lower;

input closeTime = 1555;
input labelOffset = 5;
input showFloatingLabels = yes;

def openTime = 0930;
def rawTickData1 = hlc3("$TICK");
def rawTickData2 = hlc3("$TIKRL");
def rawTickData3 = hlc3("$TIKSP");
def rawTickData4 = hlc3("$TICK/Q");
def maxTick1 = close("$ADVN") + close("$DECN") + close("$UNCN");
def maxTick2 = close("$ADVRL") + close("$DECLRL") + close("$UNCHRL");
def maxTick3 =  close("$ADVSP") + close("$DECLSP") + close("$UNCHSP");
def maxTick4 =  close("$ADVN/Q") + close("$DECN/Q") + close("$UNCN/Q");
def TickData1 = rawTickData1 / maxTick1;
def TickData2 = rawTickData2 / maxTick2;
def TickData3 = rawTickData3 / maxTick3;
def TickData4 = rawTickData4 / maxTick4;
def CT1 = if GetDay() != GetDay()[1]
          then 0
          else if SecondsTillTime(openTime) <= 0 and
                  SecondsTillTime(closeTime) >= 0
               then CT1[1] + TickData1
               else 0;
plot cumulativeTick1 = if !IsNaN(TickData1) and
                           CT1 <> 0
                       then CT1
                       else Double.NaN;
def CT2 = if GetDay() != GetDay()[1]
          then 0
          else if SecondsTillTime(openTime) <= 0 and
                  SecondsTillTime(closeTime) >= 0
               then CT2[1] + TickData2
               else 0;
plot cumulativeTick2 = if !IsNaN(TickData2) and
                           CT2 <> 0 
                       then CT2
                       else Double.NaN;
def CT3 = if GetDay() != GetDay()[1]
          then 0
          else if SecondsTillTime(openTime) <= 0 and
                  SecondsTillTime(closeTime) >= 0
               then CT3[1] + TickData3
               else 0;
plot cumulativeTick3 = if !IsNaN(TickData3) and
                           CT3 <> 0
                       then CT3
                       else Double.NaN;
def CT4 = if GetDay() != GetDay()[1]
          then 0
          else if SecondsTillTime(openTime) <= 0 and
                  SecondsTillTime(closeTime) >= 0
               then CT4[1] + TickData4
               else 0;
plot cumulativeTick4 = if !IsNaN(TickData4) and
                           CT4 <> 0
                       then CT4
                       else Double.NaN;
plot CT1DownTick = if cumulativeTick1 < cumulativeTick1[1]
                   then cumulativeTick1
                   else Double.NaN;
CT1DownTick.SetPaintingStrategy(PaintingStrategy.Points);
CT1DownTick.SetDefaultColor( color.white);
CT1DownTick.SetLineWeight(1);
CT1DownTick.HideBubble();
plot CT2DownTick = if cumulativeTick2 < cumulativeTick2[1]
                   then cumulativeTick2
                   else Double.NaN;
CT2DownTick.SetPaintingStrategy(PaintingStrategy.Points);
CT2DownTick.SetDefaultColor( color.white);
CT2DownTick.SetLineWeight(1);
CT2DownTick.HideBubble();
plot CT3DownTick = if cumulativeTick3 < cumulativeTick3[1]
                   then cumulativeTick3
                   else Double.NaN;
CT3DownTick.SetPaintingStrategy(PaintingStrategy.Points);
CT3DownTick.SetDefaultColor( color.white);
CT3DownTick.SetLineWeight(1);
CT3DownTick.HideBubble();

plot CT4DownTick = if cumulativeTick4 < cumulativeTick4[1]
                   then cumulativeTick4
                   else Double.NaN;
CT4DownTick.SetPaintingStrategy(PaintingStrategy.Points);
CT4DownTick.SetDefaultColor( color.white);
CT4DownTick.SetLineWeight(1);
CT4DownTick.HideBubble();
cumulativeTick1.SetDefaultColor(Color.MAGENTA);
cumulativeTick1.SetLineWeight(5);
cumulativeTick2.SetDefaultColor(Color.Dark_green);
cumulativeTick2.SetLineWeight(5);
cumulativeTick3.SetDefaultColor(Color.DARK_RED);
cumulativeTick3.SetLineWeight(5);
cumulativeTick4.SetDefaultColor(Color.BLUE);
cumulativeTick4.SetLineWeight(5);
cumulativeTick1.HideBubble();
cumulativeTick2.HideBubble();
cumulativeTick3.HideBubble();
cumulativeTick4.HideBubble();
plot allUp = if cumulativeTick1 > cumulativeTick1[1] and
                cumulativeTick2 > cumulativeTick2[1] and
                cumulativeTick3 > cumulativeTick3[1] and
                cumulativeTick4 > cumulativeTick4[1]
             then 0
             else Double.NaN;
allUp.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
allUp.SetDefaultColor(Color.green);
allUp.setLineWeight(5);
allup.HideBubble();
plot allDown = if cumulativeTick1 < cumulativeTick1[1] and
                  cumulativeTick2 < cumulativeTick2[1] and
                  cumulativeTick3 < cumulativeTick3[1] and
                  cumulativeTick4 < cumulativeTick4[1]
               then 0
               else Double.NaN;
allDown.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
allDown.SetDefaultColor(Color.red);
allDown.SetLineWeight(5);
allDown.HideBubble();
plot zero = if isNaN(close) then double.nan else 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();
AddVerticalLine(SecondsTillTime(openTime) == 0 or (GetDay() != GetDay()[1] and (SecondsTillTime(0000) > 0)), "", Color.GRAY, 1);
AddLabel(!showFloatingLabels, "NYSE", Color.MAGENTA);
AddLabel(!showFloatingLabels, "NASDAQ", Color.BLUE);
AddLabel(!showFloatingLabels, "SP500", Color.DARK_RED);
AddLabel(!showFloatingLabels, "R2000", Color.Dark_green);
AddChartBubble(IsNaN(close[labelOffset - 1]) and !IsNaN(close[labelOffset]) and showFloatingLabels, cumulativeTick1[labelOffset], "NYSE", Color.MAGENTA, yes);
AddChartBubble(IsNaN(close[labelOffset - 1]) and !IsNaN(close[labelOffset]) and showFloatingLabels, cumulativeTick4[labelOffset], "NASDAQ", Color.BLUE, yes);
AddChartBubble(IsNaN(close[labelOffset - 1]) and !IsNaN(close[labelOffset]) and showFloatingLabels, cumulativeTick3[labelOffset], "SP500", Color.DARK_RED, yes);
AddChartBubble(IsNaN(close[labelOffset - 1]) and !IsNaN(close[labelOffset]) and showFloatingLabels, cumulativeTick2[labelOffset], "R2000", Color.DARK_GREEN, yes);

# End Code
 
Can anyone recommend a tick divergence indicator that you've had luck with. I trade ES and looking to improve my entries.
 
Can you add an alert for everytime it crosses 1000 or -1000 please. i know that i can manually input the alerts, but onces it goes off, i have to reset if i remember to. or reset it everyday.
 
@3_Buddah_Bottom Add this to the bottom of your existing script:

Code:
def condition1 = tick > ob2;
def condition2 = tick < os2;

# Alerts
Alert(condition1, " ", Alert.Bar, Sound.Chimes);
Alert(condition2, " ", Alert.Bar, Sound.Bell);
 
Would it be possible to make this TickQ Oscillator and the Cummulative tick to work on Extended hours?


# $TICK/Q Oscillator with Divergence
# Mobius
# V01.03.2020

declare lower;

input length = 5;
input AvgType = AverageType.HULL;

def o = open("$TICK/Q ");
def h = high("$TICK/Q ");
def l = low("$TICK/Q ");
def c = close("$TICK/Q ");
def x = BarNumber();
def nan = Double.NaN;
AddChart(h, l, c, o, ChartType.CANDLE, Color.YELLOW);
AddChart(h, l, o, c, ChartType.CANDLE, Color.CYAN);
def RTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
GetTime() <= RegularTradingEnd(GetYYYYMMDD());
plot "0" = if !RTH then Double.NaN else 0;
"0".SetDefaultColor(Color.MAGENTA);
"0".HideBubble();
"0".HideTitle();
plot avg = MovingAverage(AvgType, c, length);
avg.AssignValueColor(if avg < 0
then color.red
else color.green);
avg.HideBubble();
avg.HideTitle();
addCloud(0, avg, color.red, color.green);
plot upArrow = if avg crosses above 0
then l
else double.nan;
upArrow.SetPaintingStrategy(PaintingStrategy.Arrow_UP);
upArrow.SetDefaultColor(Color.Green);
upArrow.SetLineWeight(3);
upArrow.HideBubble();
upArrow.HideTitle();
plot dnArrow = if avg crosses below 0
then h
else double.nan;
dnArrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
dnArrow.SetDefaultColor(Color.Red);
dnArrow.SetLineWeight(3);
dnArrow.HideBubble();
dnArrow.HideTitle();
def hh = if avg crosses above 0
then h
else if avg > 0 and h > hh[1]
then h
else hh[1];
def xh = if h == hh
then x
else xh[1];
plot hp = if x == highestAll(xh)
then hh
else nan;
hp.SetStyle(Curve.Points);
hp.SetDefaultColor(Color.red);
hp.SetLineWeight(3);
hp.HideBubble();
hp.HideTitle();
def xh1 = if !isNaN(dnArrow)
then getValue(xh, 2)
else xh1[1];
plot hp1 = if x == highestAll(xh1)
then h
else nan;
hp1.SetStyle(Curve.Points);
hp1.SetDefaultColor(Color.red);
hp1.SetLineWeight(3);
hp1.HideBubble();
hp1.HideTitle();
plot hd = if x == highestAll(xh1)
then h
else if x == highestAll(xh)
then h
else nan;
hd.EnableApproximation();
hd.SetDefaultColor(Color.red);
hd.HideBubble();
hd.HideTitle();
def ll = if avg crosses below 0
then l
else if avg < 0 and l < ll[1]
then l
else ll[1];
def xl = if l == ll
then x
else xl[1];
plot lp = if x == highestAll(xl)
then ll
else nan;
lp.SetStyle(Curve.Points);
lp.SetDefaultColor(Color.green);
lp.SetLineWeight(3);
lp.HideBubble();
lp.HideTitle();
def xl1 = if !isNaN(dnArrow)
then xl[1]
else xl1[1];
plot lp1 = if x == highestAll(xl1)
then l
else nan;
lp1.SetStyle(Curve.Points);
lp1.SetDefaultColor(Color.green);
lp1.SetLineWeight(3);
lp1.HideBubble();
lp1.HideTitle();
plot ld = if x == highestAll(xl1)
then l
else if x == highestAll(xl)
then l
else nan;
ld.EnableApproximation();
ld.SetDefaultColor(Color.green);
ld.HideBubble();
ld.HideTitle();
# End Code TICK/Q Oscillator with Divergence

========================================================================
========================================================================

#CummulativeTick

#hint: The CumulativeTick indicator is designed to be run on a 20 day 5 minute chart of the /ES, /NQ, /TF, or /YM. Running the chart on other instruments may result in the loss of the average lines.

declare lower;
declare once_per_bar;

def openTime = 0930;
def pivot1 = 1030;
def pivot2 = 1200;
def pivot3 = 1330;
def pivot4 = 1500;
input closeTime = 1600;

def tickData = hlc3("$TICK");
rec CT = if GetDay() != GetDay()[1] then 0 else if SecondsTillTime(openTime) <= 0 and SecondsTillTime(closeTime) >= 0 then CT[1] + tickData else 0;
plot cumulativeTick = if !IsNaN(tickData) then CT else Double.NaN;
cumulativeTick.SetStyle(curve.POINTS);

plot zero = 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();

cumulativeTick.AssignValueColor(if cumulativeTick < cumulativeTick [1] then Color.MAGENTA
else Color.CYAN);
cumulativeTick.SetLineWeight(1);

rec ticksAtPivot1 = if SecondsTillTime(pivot1) <= 0 and SecondsTillTime(pivot1)[1] > 0 then cumulativeTick else ticksAtPivot1[1];
rec ticksAtPivot2 = if SecondsTillTime(pivot2) <= 0 and SecondsTillTime(pivot2)[1] > 0 then cumulativeTick else ticksAtPivot2[1];
rec ticksAtPivot3 = if SecondsTillTime(pivot3) <= 0 and SecondsTillTime(pivot3)[1] > 0 then cumulativeTick else ticksAtPivot3[1];
rec ticksAtPivot4 = if SecondsTillTime(pivot4) <= 0 and SecondsTillTime(pivot4)[1] > 0 then cumulativeTick else ticksAtPivot4[1];
rec ticksAtClose = if SecondsTillTime(closeTime) <= 0 and SecondsTillTime(closeTime)[1] > 0 then cumulativeTick else ticksAtClose[1];

def positiveDay = if (SecondsTillTime(closeTime) <= 0 and SecondsTillTime(closeTime)[1] > 0) and cumulativeTick > 0 then 1 else 0;

def negativeDay = if SecondsTillTime(closeTime) <= 0 and SecondsTillTime(closeTime)[1] > 0 and cumulativeTick < 0 then 1 else 0;

def positiveDayTicksAtPivot1 = if positiveDay then ticksAtPivot1 else 0;
def positiveDayTicksAtPivot2 = if positiveDay then ticksAtPivot2 else 0;
def positiveDayTicksAtPivot3 = if positiveDay then ticksAtPivot3 else 0;
def positiveDayTicksAtPivot4 = if positiveDay then ticksAtPivot4 else 0;

def negativeDayTicksAtPivot1 = if negativeDay then ticksAtPivot1 else 0;
def negativeDayTicksAtPivot2 = if negativeDay then ticksAtPivot2 else 0;
def negativeDayTicksAtPivot3 = if negativeDay then ticksAtPivot3 else 0;
def negativeDayTicksAtPivot4 = if negativeDay then ticksAtPivot4 else 0;

rec totalPDTAP1 = if !IsNaN(cumulativeTick) then if positiveDay then totalPDTAP1[1] + positiveDayTicksAtPivot1 else totalPDTAP1[1] else totalPDTAP1[1];
rec totalPDTAP2 = if !IsNaN(cumulativeTick) then if positiveDay then totalPDTAP2[1] + positiveDayTicksAtPivot2 else totalPDTAP2[1] else totalPDTAP2[1];
rec totalPDTAP3 = if !IsNaN(cumulativeTick) then if positiveDay then totalPDTAP3[1] + positiveDayTicksAtPivot3 else totalPDTAP3[1] else totalPDTAP3[1];
rec totalPDTAP4 = if !IsNaN(cumulativeTick) then if positiveDay then totalPDTAP4[1] + positiveDayTicksAtPivot4 else totalPDTAP4[1] else totalPDTAP4[1];

rec totalNDTAP1 = if !IsNaN(cumulativeTick) then if negativeDay then totalNDTAP1[1] + negativeDayTicksAtPivot1 else totalNDTAP1[1] else totalNDTAP1[1];
rec totalNDTAP2 = if !IsNaN(cumulativeTick) then if negativeDay then totalNDTAP2[1] + negativeDayTicksAtPivot2 else totalNDTAP2[1] else totalNDTAP2[1];
rec totalNDTAP3 = if !IsNaN(cumulativeTick) then if negativeDay then totalNDTAP3[1] + negativeDayTicksAtPivot3 else totalNDTAP3[1] else totalNDTAP3[1];
rec totalNDTAP4 = if !IsNaN(cumulativeTick) then if negativeDay then totalNDTAP4[1] + negativeDayTicksAtPivot4 else totalNDTAP4[1] else totalNDTAP4[1];


rec positiveDays = if !IsNaN(cumulativeTick) then if positiveDay then positiveDays[1] + 1 else positiveDays[1] else positiveDays[1];
rec negativeDays = if !IsNaN(cumulativeTick) then if negativeDay then negativeDays[1] + 1 else negativeDays[1] else negativeDays[1];


plot avePosTickAtPivot1 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalPDTAP1 / positiveDays else Double.NaN);
plot avePosTickAtPivot2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalPDTAP2 / positiveDays else Double.NaN);
plot avePosTickAtPivot3 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalPDTAP3 / positiveDays else Double.NaN);
plot avePosTickAtPivot4 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalPDTAP4 / positiveDays else Double.NaN);

plot aveNegTickAtPivot1 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalNDTAP1 / negativeDays else Double.NaN);
plot aveNegTickAtPivot2 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalNDTAP2 / negativeDays else Double.NaN);
plot aveNegTickAtPivot3 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalNDTAP3 / negativeDays else Double.NaN);
plot aveNegTickAtPivot4 = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then totalNDTAP4 / negativeDays else Double.NaN);

avePosTickAtPivot1.SetDefaultColor(Color.DARK_GRAY);
avePosTickAtPivot2.SetDefaultColor(Color.DARK_GRAY);
avePosTickAtPivot3.SetDefaultColor(Color.DARK_GRAY);
avePosTickAtPivot4.SetDefaultColor(Color.DARK_GRAY);
aveNegTickAtPivot1.SetDefaultColor(Color.DARK_GRAY);
aveNegTickAtPivot2.SetDefaultColor(Color.DARK_GRAY);
aveNegTickAtPivot3.SetDefaultColor(Color.DARK_GRAY);
aveNegTickAtPivot4.SetDefaultColor(Color.DARK_GRAY);

avePosTickAtPivot1.SetStyle(Curve.FIRM);
avePosTickAtPivot2.SetStyle(Curve.FIRM);
avePosTickAtPivot3.SetStyle(Curve.FIRM);
avePosTickAtPivot4.SetStyle(Curve.FIRM);
aveNegTickAtPivot1.SetStyle(Curve.FIRM);
aveNegTickAtPivot2.SetStyle(Curve.FIRM);
aveNegTickAtPivot3.SetStyle(Curve.FIRM);
aveNegTickAtPivot4.SetStyle(Curve.FIRM);
avePosTickAtPivot1.HideBubble();
avePosTickAtPivot2.HideBubble();
avePosTickAtPivot3.HideBubble();
avePosTickAtPivot4.HideBubble();
aveNegTickAtPivot1.HideBubble();
aveNegTickAtPivot2.HideBubble();
aveNegTickAtPivot3.HideBubble();
aveNegTickAtPivot4.HideBubble();

avePosTickAtPivot1.HideTitle();
avePosTickAtPivot2.HideTitle();
avePosTickAtPivot3.HideTitle();
avePosTickAtPivot4.HideTitle();
aveNegTickAtPivot1.HideTitle();
aveNegTickAtPivot2.HideTitle();
aveNegTickAtPivot3.HideTitle();
aveNegTickAtPivot4.HideTitle();


#AddChartBubble( SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), avePosTickAtPivot1, "+10:30", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), avePosTickAtPivot2, "+12:00", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), avePosTickAtPivot3, "+13:30", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), avePosTickAtPivot4, "+15:00", Color.DARK_GRAY, yes);

#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), aveNegTickAtPivot1, "-10:30", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), aveNegTickAtPivot2, "-12:00", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), aveNegTickAtPivot3, "-13:30", Color.DARK_GRAY, yes);
#AddChartBubble(SecondsTillTime(openTime) == 0 and GetDay() == GetLastDay(), aveNegTickAtPivot4, "-15:00", Color.DARK_GRAY, yes);

AddVerticalLine(SecondsTillTime(openTime) == 0 or (GetDay() != GetDay()[1] and (SecondsTillTime(0000) > 0)), "", Color.GRAY, 1);
# AI Adds

def lastHP = if x == highestAll(xh)
then xh else lastHP[1];
def lastHP1 = if x == highestAll(xh1)
then xh1 else lastHP[1];
def lastLP = if x == highestAll(xl)
then xl else lastLP[1];
def lastLP1 = if x == highestAll(xl1)
then xl1 else lastLP1[1];

Addlabel(lastHP1<lastHP,"Divergent",color.red);
Addlabel(lastLP1>lastLP,"Divergent",color.green);
 
Would like to know how to code this to create a painted display of the $Tick. Not sure how to use the aggregation value. ?????
Here is some of the code.

def tickData = close(symbol = "$TICK");

def RTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
GetTime() <= RegularTradingEnd(GetYYYYMMDD());

def n = if RTH and !RTH[1] then 1 else if RTH then n[1] + 1 else n[1];

def ap = AggregationPeriod.MIN; ??????

def TD = (fold i = 0 to n
with s
do s + GetValue(tickData, i)) / n;

plot TPlot = ( close - TD ) ;

AddCloud(0, TPlot, Color.RED, Color.GREEN);
 
have a slightly different way of plotting tick, figured I'd post it here, also includes alerts when tick reaches specified threshold (default +/- 1000) and plots a vertical line when threshold is reached, plus labels for breadth ratio, put/call ratio, and vix:
X2pPKNV.png

the labels are dark due to markets being closed, but the blue represents the tick high, orange is tick low and green or red depends on if it closes above or below zeroline. I find it easier to see the slope of the $tick trend this way.
Code:
#[email protected]
declare lower;

input alerttype = Alert.BAR;
input alertsound = Sound.DING;
input alertThreshold = 1000;

plot zeroline = 0;
plot tick500 = 500;
plot tick500m = -500;
plot tick1000 = 1000;
plot tick1000m = -1000;

DefineGlobalColor("Vertical Line Color", Color.WHITE);

def NA = Double.NaN;
def ticko = open("$TICK");
plot tickc = close("$TICK");
plot tickh = high("$TICK");
plot tickl = low("$TICK");

def tickh1000test = tickh >= alertThreshold;
def tickl1000test = tickl <= -alertThreshold;
Alert(tickh1000test, " >+1000 $TICK", alerttype, alertsound);
Alert(tickl1000test, " <-1000 $TICK", alerttype, alertsound);
AddVerticalLine(tickh1000test, "+"+alertThreshold, GlobalColor("Vertical Line Color"));
AddVerticalLine(tickl1000test, "-"+alertThreshold, GlobalColor("Vertical Line Color"));

def PCALL = Round(close("$PCALL"),2);
def NYSEUVOL = close("$UVOL");
def NYSEDVOL = close("$DVOL");

def BR = Round(if NYSEUVOL >= NYSEDVOL then NYSEUVOL / NYSEDVOL else -(NYSEDVOL/NYSEUVOL),2);
AddLabel(1,"$TICK: "+ tickc, if tickc > 0 then Color.GREEN else Color.RED);
AddLabel(1,"BR: " + BR ,if BR > 0 then Color.GREEN else Color.RED);
AddLabel(1,"$PCALL: " + PCALL, Color.GRAY);
AddLabel(1, "VIX: "+ close("VIX"), Color.GRAY);

zeroline.SetDefaultColor(Color.BLACK);
tick500.SetDefaultColor(Color.GRAY);
tick500m.SetDefaultColor(Color.GRAY);
tick1000.SetDefaultColor(Color.GRAY);
tick1000m.SetDefaultColor(Color.GRAY);
tick1000.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
tick1000m.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
tick1000.SetLineWeight(2);
tick1000m.SetLineWeight(2);

tickh.SetPaintingStrategy(PaintingStrategy.Squared_HISTOGRAM);
tickh.SetDefaultColor(CreateColor(0,100,200));
tickl.SetPaintingStrategy(PaintingStrategy.Squared_HISTOGRAM);
tickl.SetDefaultColor(Color.DARK_ORANGE);
tickc.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
tickc.AssignValueColor(if tickc > 0 then color.green else color.red);
Any idea on why I cannot get this one to work?

Nothing displays.
 
Any idea on why I cannot get this one to work?

Nothing displays.
UsiphFz.png

The script that was referenced in your post seems "to work".

As you didn't provide any information about what you did or didn't do; providing further help is not possible.
When making future posts, it is important to understand what you did and where you did it.
It is requested that a DETAILED post of the steps taken be provided.
To better understand the issue, it is necessary to see what is being encountered.
Therefore, it is requested that the following be posted:
  • Always provide the code that was copied and pasted. Even if it is thought to be the same as the one on the forum, it still needs to be seen. There may be a missing part of the code that is causing the issue.
  • If you provide a chart link, members will be able to see what you are seeing (directions below).
  • Always provide a screenshot of the problem. Annotate the image, highlighting which widget you are working in, along with a more detailed written explanation. This will help others to better understand the question and provide more specific information to work with.
How To Create A Shared Chart Link
https://usethinkscript.com/threads/how-to-share-a-chart-in-thinkorswim.14221/


If unsure of how to upload screenshots to the forum, easy-to-follow directions are available at https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-58714
 
Last edited:

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
314 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