Cumulative Tick "underlying" value changes when adding moving averages?

danwagnerco

New member
VIP
I was inspired by these two posts to create a "Cumulative Tick" signal:

(1) https://usethinkscript.com/threads/cumulative-tick-indicator-for-thinkorswim.603/post-4541
(2) https://usethinkscript.com/threads/...ick-indicator-for-thinkorswim.9211/post-84661

Except, instead of resetting the "Cumulative Tick" value each day, I would instead let it constantly accumulate to assess long-term trends. Using the TOS-provided documentation on these symbols as my guide:

https://tlc.thinkorswim.com/center/release/rel-07-20-2013

I decided to sum ALL of $TICK-style sources to take in a truly global view. Here is the super-basic code to accomplish that, with Labels added to easily assess the values of each signal:

Code:
# BenTen $TICK accumulator: https://usethinkscript.com/threads/cumulative-tick-indicator-for-thinkorswim.603/
# Mobius $TICK accumulator https://usethinkscript.com/threads/time-anchored-cumulative-tick-indicator-for-thinkorswim.9211/#post-84661

def TICK = close(Symbol = "$TICK");
def cumTICK = cumTICK[1] + TICK;
def TICKC = close(Symbol = "$TICKC");
def cumTICKC = cumTICKC[1] + TICKC;
def TICKA = close(Symbol = "$TICKA");
def cumTICKA = cumTICKA[1] + TICKA;
def TICKAC = close(Symbol = "$TICKAC");
def cumTICKAC = cumTICKAC[1] + TICKAC;
def TICKAR = close(Symbol = "$TICKAR");
def cumTICKAR = cumTICKAR[1] + TICKAR;
def TICKARC = close(Symbol = "$TICKARC");
def cumTICKARC = cumTICKARC[1] + TICKARC;
def TICK_Q = close(Symbol = "$TICK/Q");
def cumTICK_Q = cumTICK_Q[1] + TICK_Q;
def TICKC_Q = close(Symbol = "$TICKC/Q");
def cumTICKC_Q = cumTICKC_Q[1] + TICKC_Q;

AddLabel(yes, "$TICK=" + cumTICK, Color.YELLOW);
AddLabel(yes, "$TICKC=" + cumTICKC, Color.YELLOW);
AddLabel(yes, "$TICKA=" + cumTICKA, Color.YELLOW);
AddLabel(yes, "$TICKAC=" + cumTICKAC, Color.YELLOW);
AddLabel(yes, "$TICKAR=" + cumTICKAR, Color.YELLOW);
AddLabel(yes, "$TICKARC=" + cumTICKARC, Color.YELLOW);
AddLabel(yes, "$TICK_Q=" + cumTICK_Q, Color.YELLOW);
AddLabel(yes, "$TICKC_Q=" + cumTICKC_Q, Color.YELLOW);

def totalCumTick = cumTICK + cumTICKC + cumTICKA + cumTICKAC + cumTICKAR + cumTICKARC + cumTICK_Q + cumTICKC_Q;
AddLabel(yes, "CumulativeTick=" + totalCumTick, Color.WHITE);

plot tct = totalCumTick;
tct.SetLineWeight(2);
tct.SetPaintingStrategy(PaintingStrategy.LINE);
tct.AssignValueColor(Color.WHITE);

Here is the result:

cumulative_tick_1.png


OK, now that I have my signal, let's slap on some moving averages -- perhaps I can conclude that the market is short-term bullish or bearish when this "Cumulative Tick" value is above its 20-bar moving average / 50-bar moving average / 100-bar moving average etc. I will add those calculations and also add them as labels to the calculated values are easy to see:

Code:
# ... exact same code from above...
# Here is the new stuff:
def SMA_1 = MovingAverage(AverageType.Simple, totalCumTick, 20);
def SMA_2 = MovingAverage(AverageType.Simple, totalCumTick, 50);
def SMA_3 = MovingAverage(AverageType.Simple, totalCumTick, 100);

AddLabel(yes, "SMA_20=" + SMA_1, Color.GRAY);
AddLabel(yes, "SMA_50=" + SMA_2, Color.GRAY);
AddLabel(yes, "SMA_100=" + SMA_3, Color.GRAY);

plot sma1 = SMA_1;
sma1.SetLineWeight(1);
sma1.SetPaintingStrategy(PaintingStrategy.LINE);
sma1.AssignValueColor(Color.GRAY);
plot sma2 = SMA_2;
sma2.SetLineWeight(1);
sma2.SetPaintingStrategy(PaintingStrategy.LINE);
sma2.AssignValueColor(Color.GRAY);
plot sma3 = SMA_3;
sma3.SetLineWeight(1);
sma3.SetPaintingStrategy(PaintingStrategy.LINE);
sma3.AssignValueColor(Color.GRAY);

I save the updated Thinkscript and here are the results:

cumulative_tick_1_with_sma.png


ALL of the "underlying" signals, the raw $TICKXYZ values, have changed after adding these simple moving averages! This runs counter to years of programming experience -- I am writing this on Sunday Jul22 31st, at 10:45AM Chicago time, so all markets are closed and these values should not be changing.

Why has the addition of simple moving averages beyond the underlying signals changed the underlying signals?

Thank you so much in advance for your help here my friends as I feel like I'm taking crazy pills haha... -Dan

PS, for reference, the values before and after the addition of the simple moving averages:

Before:
$TICK=241_463
$TICKC=92_192
$TICKA=20_104
$TICKAC=668
$TICKAR=252_765
$TICKARC=176_460
$TICK/Q=206_212
$TICKC/Q=140_504
CumulativeTick=1_130_368

After:
$TICK=242_766 (+0.54% larger)
$TICKC=89_929 (-2.45% smaller)
$TICKA=17_205 (-14.42% smaller)
$TICKAC=920 (+37.72% larger)
$TICKAR=231_401 (-8.45% smaller)
$TICKARC=162_544 (-7.89% smaller)
$TICK/Q=196_428 (-4.74% smaller)
$TICKC/Q=146_730 (+4.43% larger)
CumulativeTick=1_087_923 (-3.75% smaller)
 
Solution
I was inspired by these two posts to create a "Cumulative Tick" signal:

(1) https://usethinkscript.com/threads/cumulative-tick-indicator-for-thinkorswim.603/post-4541
(2) https://usethinkscript.com/threads/...ick-indicator-for-thinkorswim.9211/post-84661

Except, instead of resetting the "Cumulative Tick" value each day, I would instead let it constantly accumulate to assess long-term trends. Using the TOS-provided documentation on these symbols as my guide:

https://tlc.thinkorswim.com/center/release/rel-07-20-2013

I decided to sum ALL of $TICK-style sources to take in a truly global view. Here is the super-basic code to accomplish that, with Labels added to easily assess the values of...

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

I was inspired by these two posts to create a "Cumulative Tick" signal:

(1) https://usethinkscript.com/threads/cumulative-tick-indicator-for-thinkorswim.603/post-4541
(2) https://usethinkscript.com/threads/...ick-indicator-for-thinkorswim.9211/post-84661

Except, instead of resetting the "Cumulative Tick" value each day, I would instead let it constantly accumulate to assess long-term trends. Using the TOS-provided documentation on these symbols as my guide:

https://tlc.thinkorswim.com/center/release/rel-07-20-2013

I decided to sum ALL of $TICK-style sources to take in a truly global view. Here is the super-basic code to accomplish that, with Labels added to easily assess the values of each signal:

Code:
# BenTen $TICK accumulator: https://usethinkscript.com/threads/cumulative-tick-indicator-for-thinkorswim.603/
# Mobius $TICK accumulator https://usethinkscript.com/threads/time-anchored-cumulative-tick-indicator-for-thinkorswim.9211/#post-84661

def TICK = close(Symbol = "$TICK");
def cumTICK = cumTICK[1] + TICK;
def TICKC = close(Symbol = "$TICKC");
def cumTICKC = cumTICKC[1] + TICKC;
def TICKA = close(Symbol = "$TICKA");
def cumTICKA = cumTICKA[1] + TICKA;
def TICKAC = close(Symbol = "$TICKAC");
def cumTICKAC = cumTICKAC[1] + TICKAC;
def TICKAR = close(Symbol = "$TICKAR");
def cumTICKAR = cumTICKAR[1] + TICKAR;
def TICKARC = close(Symbol = "$TICKARC");
def cumTICKARC = cumTICKARC[1] + TICKARC;
def TICK_Q = close(Symbol = "$TICK/Q");
def cumTICK_Q = cumTICK_Q[1] + TICK_Q;
def TICKC_Q = close(Symbol = "$TICKC/Q");
def cumTICKC_Q = cumTICKC_Q[1] + TICKC_Q;

AddLabel(yes, "$TICK=" + cumTICK, Color.YELLOW);
AddLabel(yes, "$TICKC=" + cumTICKC, Color.YELLOW);
AddLabel(yes, "$TICKA=" + cumTICKA, Color.YELLOW);
AddLabel(yes, "$TICKAC=" + cumTICKAC, Color.YELLOW);
AddLabel(yes, "$TICKAR=" + cumTICKAR, Color.YELLOW);
AddLabel(yes, "$TICKARC=" + cumTICKARC, Color.YELLOW);
AddLabel(yes, "$TICK_Q=" + cumTICK_Q, Color.YELLOW);
AddLabel(yes, "$TICKC_Q=" + cumTICKC_Q, Color.YELLOW);

def totalCumTick = cumTICK + cumTICKC + cumTICKA + cumTICKAC + cumTICKAR + cumTICKARC + cumTICK_Q + cumTICKC_Q;
AddLabel(yes, "CumulativeTick=" + totalCumTick, Color.WHITE);

plot tct = totalCumTick;
tct.SetLineWeight(2);
tct.SetPaintingStrategy(PaintingStrategy.LINE);
tct.AssignValueColor(Color.WHITE);

Here is the result:

cumulative_tick_1.png


OK, now that I have my signal, let's slap on some moving averages -- perhaps I can conclude that the market is short-term bullish or bearish when this "Cumulative Tick" value is above its 20-bar moving average / 50-bar moving average / 100-bar moving average etc. I will add those calculations and also add them as labels to the calculated values are easy to see:

Code:
# ... exact same code from above...
# Here is the new stuff:
def SMA_1 = MovingAverage(AverageType.Simple, totalCumTick, 20);
def SMA_2 = MovingAverage(AverageType.Simple, totalCumTick, 50);
def SMA_3 = MovingAverage(AverageType.Simple, totalCumTick, 100);

AddLabel(yes, "SMA_20=" + SMA_1, Color.GRAY);
AddLabel(yes, "SMA_50=" + SMA_2, Color.GRAY);
AddLabel(yes, "SMA_100=" + SMA_3, Color.GRAY);

plot sma1 = SMA_1;
sma1.SetLineWeight(1);
sma1.SetPaintingStrategy(PaintingStrategy.LINE);
sma1.AssignValueColor(Color.GRAY);
plot sma2 = SMA_2;
sma2.SetLineWeight(1);
sma2.SetPaintingStrategy(PaintingStrategy.LINE);
sma2.AssignValueColor(Color.GRAY);
plot sma3 = SMA_3;
sma3.SetLineWeight(1);
sma3.SetPaintingStrategy(PaintingStrategy.LINE);
sma3.AssignValueColor(Color.GRAY);

I save the updated Thinkscript and here are the results:

cumulative_tick_1_with_sma.png


ALL of the "underlying" signals, the raw $TICKXYZ values, have changed after adding these simple moving averages! This runs counter to years of programming experience -- I am writing this on Sunday Jul22 31st, at 10:45AM Chicago time, so all markets are closed and these values should not be changing.

Why has the addition of simple moving averages beyond the underlying signals changed the underlying signals?

Thank you so much in advance for your help here my friends as I feel like I'm taking crazy pills haha... -Dan

PS, for reference, the values before and after the addition of the simple moving averages:

Before:
$TICK=241_463
$TICKC=92_192
$TICKA=20_104
$TICKAC=668
$TICKAR=252_765
$TICKARC=176_460
$TICK/Q=206_212
$TICKC/Q=140_504
CumulativeTick=1_130_368

After:
$TICK=242_766 (+0.54% larger)
$TICKC=89_929 (-2.45% smaller)
$TICKA=17_205 (-14.42% smaller)
$TICKAC=920 (+37.72% larger)
$TICKAR=231_401 (-8.45% smaller)
$TICKARC=162_544 (-7.89% smaller)
$TICK/Q=196_428 (-4.74% smaller)
$TICKC/Q=146_730 (+4.43% larger)
CumulativeTick=1_087_923 (-3.75% smaller)

It appears that the 1st set of labels were not initalized. In the image below is chartbubbles that show the value of each tick per bar, plus the cumulative value so that you can see how the initalization seems to work in stabilizing the values.

Capture.jpg
Ruby:
def bar=barnumber();
def TICK = close(Symbol = "$TICK");
def cumTICK = if bar==1 then tick else cumTICK[1] + TICK;
plot xcumtick=cumtick;
xcumtick.setpaintingStrategy(paintingStrategy.VALUES_BELOW);


def TICKC = close(Symbol = "$TICKC");
def cumTICKC = if bar==1 then tickc else  cumTICKC[1] + TICKC;
def TICKA = close(Symbol = "$TICKA");
def cumTICKA = if bar==1 then ticka else  cumTICKA[1] + TICKA;
def TICKAC = close(Symbol = "$TICKAC");
def cumTICKAC =  if bar==1 then tickac else cumTICKAC[1] + TICKAC;
def TICKAR = close(Symbol = "$TICKAR");
def cumTICKAR =  if bar==1 then tickar else cumTICKAR[1] + TICKAR;
def TICKARC = close(Symbol = "$TICKARC");
def cumTICKARC =  if bar==1 then tickarc else cumTICKARC[1] + TICKARC;
def TICK_Q = close(Symbol = "$TICK/Q");
def cumTICK_Q =  if bar==1 then tick_q else cumTICK_Q[1] + TICK_Q;
def TICKC_Q = close(Symbol = "$TICKC/Q");
def cumTICKC_Q =  if bar==1 then tickc_q else cumTICKC_Q[1] + TICKC_Q;
The following code is shown in the lower panel and includes the above and your desired SMAs and you can see there is no effect on the initalized set of values by the inclusion of the SMAs.
Ruby:
# BenTen $TICK accumulator: https://usethinkscript.com/threads/cumulative-tick-indicator-for-thinkorswim.603/
# Mobius $TICK accumulator https://usethinkscript.com/threads/time-anchored-cumulative-tick-indicator-for-thinkorswim.9211/#post-84661
def bar=barnumber();
def TICK = close(Symbol = "$TICK");
def cumTICK = if bar==1 then tick else cumTICK[1] + TICK;
addchartBubble(1,low-20,tick+"\n"+cumtick,color.gray,no);

def TICKC = close(Symbol = "$TICKC");
def cumTICKC = if bar==1 then tickc else  cumTICKC[1] + TICKC;
def TICKA = close(Symbol = "$TICKA");
def cumTICKA = if bar==1 then ticka else  cumTICKA[1] + TICKA;
def TICKAC = close(Symbol = "$TICKAC");
def cumTICKAC =  if bar==1 then tickac else cumTICKAC[1] + TICKAC;
def TICKAR = close(Symbol = "$TICKAR");
def cumTICKAR =  if bar==1 then tickar else cumTICKAR[1] + TICKAR;
def TICKARC = close(Symbol = "$TICKARC");
def cumTICKARC =  if bar==1 then tickarc else cumTICKARC[1] + TICKARC;
def TICK_Q = close(Symbol = "$TICK/Q");
def cumTICK_Q =  if bar==1 then tick_q else cumTICK_Q[1] + TICK_Q;
def TICKC_Q = close(Symbol = "$TICKC/Q");
def cumTICKC_Q =  if bar==1 then tickc_q else cumTICKC_Q[1] + TICKC_Q;

AddLabel(yes, "$TICK=" + cumTICK, Color.YELLOW);
AddLabel(yes, "$TICKC=" + cumTICKC, Color.YELLOW);
AddLabel(yes, "$TICKA=" + cumTICKA, Color.YELLOW);
AddLabel(yes, "$TICKAC=" + cumTICKAC, Color.YELLOW);
AddLabel(yes, "$TICKAR=" + cumTICKAR, Color.YELLOW);
AddLabel(yes, "$TICKARC=" + cumTICKARC, Color.YELLOW);
AddLabel(yes, "$TICK_Q=" + cumTICK_Q, Color.YELLOW);
AddLabel(yes, "$TICKC_Q=" + cumTICKC_Q, Color.YELLOW);

def totalCumTick = cumTICK + cumTICKC + cumTICKA + cumTICKAC + cumTICKAR + cumTICKARC + cumTICK_Q + cumTICKC_Q;
AddLabel(yes, "CumulativeTick=" + totalCumTick, Color.WHITE);

plot tct = totalCumTick;
tct.SetLineWeight(2);
tct.SetPaintingStrategy(PaintingStrategy.LINE);
tct.AssignValueColor(Color.WHITE);

def SMA_1 = MovingAverage(AverageType.SIMPLE, totalCumTick, 20);
def SMA_2 = MovingAverage(AverageType.SIMPLE, totalCumTick, 50);
def SMA_3 = MovingAverage(AverageType.SIMPLE, totalCumTick, 100);

AddLabel(yes, "SMA_20=" + SMA_1, Color.GRAY);
AddLabel(yes, "SMA_50=" + SMA_2, Color.GRAY);
AddLabel(yes, "SMA_100=" + SMA_3, Color.GRAY);

plot sma1 = SMA_1;
sma1.SetLineWeight(1);
sma1.SetPaintingStrategy(PaintingStrategy.LINE);
sma1.AssignValueColor(Color.GRAY);
plot sma2 = SMA_2;
sma2.SetLineWeight(1);
sma2.SetPaintingStrategy(PaintingStrategy.LINE);
sma2.AssignValueColor(Color.GRAY);
plot sma3 = SMA_3;
sma3.SetLineWeight(1);
sma3.SetPaintingStrategy(PaintingStrategy.LINE);
sma3.AssignValueColor(Color.GRAY);
 
Solution
It appears that the 1st set of labels were not initalized. In the image below is chartbubbles that show the value of each tick per bar, plus the cumulative value so that you can see how the initalization seems to work in stabilizing the values.

Thank you so much for the recommendation -- this adjustment stabilized the calculation exactly as you described.

Problem solved! -Dan
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
359 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