Cumulative TICK Trend[Pt] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
k8TxgeE.png

Author Message:
Cumulative TICK Trend indicator is a comprehensive trading tool that uses TICK data to define the market's cumulative trend. Trend is shown on ATR EMA bands (I added Bollinger band as well), which is overlaid on the price chart.
How it Works:

This indicator accumulates TICK data during market hours (9:30-16:00) as per the New York time zone and resets at the start of a new session or the end of the regular session. This cumulative TICK value is then used to determine the trend.

The trend is defined as bullish if the SMA of cumulative TICK is equal to or greater than zero and bearish if it's less than zero. Additionally, this indicator plots the ATR bands, which can be used as volatility measures. The Upper ATR Band and Lower ATR Band (I added Bollinger band as well), can be made smoother using the SMA, according to the trader's preference.

The plot includes two parts for each trend: a stronger color (Red for bear, Green for bull) when the trend is ongoing, and a lighter color when the trend seems to be changing.

Remember, this tool is intended to be used as part of a comprehensive trading strategy. Always ensure you are managing risk appropriately and consulting various data sources to make informed trading decisions.

CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © PtGambler
#indicator(title='Cumulative TICK Trend[Pt]', shorttitle='CumTICK-trend[Pt]', overlay=true)
# Converted and mod by Sam4Cok@Samer800    - 05/2023
input BarColor   = yes;
input ShowSignals = no;
input startTime  = 0930;
input endTime    = 1600;
input tick_src = {default NYSE, NASDAQ, "S&P 500","DOW Jones", "Russel 2000", AMEX, ARCA, "All US"};
input TickSource = {"Close", "Open", "High", "Low", "HL2", "OHLC4",Default "HLC3"};
input CumulativeTickSmoothing = no;    # "Apply Cum TICK Smoothing"
input SmoothingType = AverageType.SIMPLE;
input CumTickSmoothingLength = 5;      # Cum TICK Smoothing Length
input show_Band = no;        # 'Show Bands'
input ShowMidLine = yes;
input CalcMethod = {Default "ATR Trend","Bollinger Trend"};
input BandMovAvgType = AverageType.EXPONENTIAL;
input Source = close;         # 'Source'
input atrPeriod  = 10;        # 'ATR Period'
input BandPeriod = 10;        # 'EMA Period'
input Multiplier = 3.0;       # 'Multiplier'
input smoothBand = yes;       # 'Smooth Band'
input smoothBandLength = 5;   # 'Smoothing Length'

def na = Double.NaN;
def last = IsNaN(close);
def current = GetAggregationPeriod();
def intraDay = current < AggregationPeriod.DAY;
def t1 = SecondsTillTime(startTime) < 0 and SEcondsTillTime(endTime) > 0;
def atrTrend = CalcMethod==CalcMethod."ATR Trend";

#--- Color
DefineGlobalColor("up", Color.GREEN);
DefineGlobalColor("dup", Color.DARK_GREEN);
DefineGlobalColor("dn", Color.RED);
DefineGlobalColor("ddn",Color.DARK_RED);
#---
def tickH;
def tickL;
def tickO;
def tickC;
def tickHL2;
def tickOHLC4;
def tickHLC3;

switch (tick_src) {
case NASDAQ:
    tickH     = High (symbol= "$TICK/Q");
    tickL     = Low  (symbol= "$TICK/Q");
    tickO     = Open (symbol= "$TICK/Q");
    tickC     = Close(symbol= "$TICK/Q");
    tickHL2   = HL2  (symbol= "$TICK/Q");
    tickOHLC4 = OHLC4(symbol= "$TICK/Q");
    tickHLC3  = HLC3 (symbol= "$TICK/Q");
case NYSE:
    tickH     = High (symbol= "$TICK");
    tickL     = Low  (symbol= "$TICK");
    tickO     = Open (symbol= "$TICK");
    tickC     = Close(symbol= "$TICK");
    tickHL2   = HL2  (symbol= "$TICK");
    tickOHLC4 = OHLC4(symbol= "$TICK");
    tickHLC3  = HLC3 (symbol= "$TICK");
case "Russel 2000":
    tickH     = High (symbol= "$TIKRL");
    tickL     = Low  (symbol= "$TIKRL");
    tickO     = Open (symbol= "$TIKRL");
    tickC     = Close(symbol= "$TIKRL");
    tickHL2   = HL2  (symbol= "$TIKRL");
    tickOHLC4 = OHLC4(symbol= "$TIKRL");
    tickHLC3  = HLC3 (symbol= "$TIKRL");
case "S&P 500":
    tickH     = High (symbol= "$TIKSP");
    tickL     = Low  (symbol= "$TIKSP");
    tickO     = Open (symbol= "$TIKSP");
    tickC     = Close(symbol= "$TIKSP");
    tickHL2   = HL2  (symbol= "$TIKSP");
    tickOHLC4 = OHLC4(symbol= "$TIKSP");
    tickHLC3  = HLC3 (symbol= "$TIKSP");
case "DOW Jones":
    tickH     = High (symbol= "$TIKI");
    tickL     = Low  (symbol= "$TIKI");
    tickO     = Open (symbol= "$TIKI");
    tickC     = Close(symbol= "$TIKI");
    tickHL2   = HL2  (symbol= "$TIKI");
    tickOHLC4 = OHLC4(symbol= "$TIKI");
    tickHLC3  = HLC3 (symbol= "$TIKI");
case "All US":
    tickH     = High (symbol= "$TIKUS");
    tickL     = Low  (symbol= "$TIKUS");
    tickO     = Open (symbol= "$TIKUS");
    tickC     = Close(symbol= "$TIKUS");
    tickHL2   = HL2  (symbol= "$TIKUS");
    tickOHLC4 = OHLC4(symbol= "$TIKUS");
    tickHLC3  = HLC3 (symbol= "$TIKUS");
case AMEX:
    tickH     = High (symbol= "$TICKA");
    tickL     = Low  (symbol= "$TICKA");
    tickO     = Open (symbol= "$TICKA");
    tickC     = Close(symbol= "$TICKA");
    tickHL2   = HL2  (symbol= "$TICKA");
    tickOHLC4 = OHLC4(symbol= "$TICKA");
    tickHLC3  = HLC3 (symbol= "$TICKA");
case ARCA:
    tickH     = High (symbol= "$TICKAR");
    tickL     = Low  (symbol= "$TICKAR");
    tickO     = Open (symbol= "$TICKAR");
    tickC     = Close(symbol= "$TICKAR");
    tickHL2   = HL2  (symbol= "$TICKAR");
    tickOHLC4 = OHLC4(symbol= "$TICKAR");
    tickHLC3  = HLC3 (symbol= "$TICKAR");
}
def cumTICK_src;
switch (TickSource) {
case High:
    cumTICK_src = tickH;
case Low:
    cumTICK_src = tickL;
case Close:
    cumTICK_src = tickC;
case Open:
    cumTICK_src = tickO;
case hl2:
    cumTICK_src = tickHL2;
case ohlc4:
    cumTICK_src = tickOHLC4;
case hlc3:
    cumTICK_src = tickHLC3;
}
#// Calculation - Cumulative TICK ----

def cumTICK;

if !t1 or last {
    cumTICK = 0;
    } else {
    cumTICK =  cumTICK[1] + cumTICK_src;#cumTICK_;
}
    
def cumTICK_ma = if CumulativeTickSmoothing then MovingAverage(SmoothingType, cumTICK, CumTickSmoothingLength) else cumTICK;

def bull_trend = cumTICK_ma >= 0;
def bear_trend = cumTICK_ma < 0;

#// ATR Band --------

def nATR = ATR(LENGTH = atrPeriod);
def bbup = MovingAverage(BandMovAvgType, high,BandPeriod) + stdev(high,BandPeriod) * Multiplier;
def bbdn = MovingAverage(BandMovAvgType, low,BandPeriod)  - stdev(low,BandPeriod) * Multiplier;
def atrup = Source + nATR * Multiplier;
def atrdn = Source - nATR * Multiplier;
def up = if atrTrend then atrup else bbup;
def dn = if atrTrend then atrdn else bbdn;
def up_ma_   = MovingAverage(BandMovAvgType, up, BandPeriod);
def down_ma_ = MovingAverage(BandMovAvgType, dn, BandPeriod);

def up_ma;
def down_ma;
if smoothBand {
    up_ma = MovingAverage(SmoothingType, up_ma_, smoothBandLength);
    down_ma = MovingAverage(SmoothingType, down_ma_, smoothBandLength);
} else {
    up_ma = up_ma_;
    down_ma = down_ma_;
}
def mid_ma = (up_ma + down_ma) / 2;
#// Plotting

plot BearTrend = if !intraDay then up_ma else
                 if t1 and bear_trend and cumTICK_ma <= cumTICK_ma[1] then up_ma else na;    # 'Bear Trend'
BearTrend.SetLineWeight(2);
BearTrend.SetDefaultColor(GlobalColor("dn"));

plot BearTrend_ = if t1 and bear_trend and cumTICK_ma > cumTICK_ma[1] then up_ma else na;    # 'Bear Trend'
BearTrend_.SetDefaultColor(GlobalColor("ddn"));

plot BullTrend = if !intraDay then down_ma else
                if t1 and bull_trend and cumTICK_ma >= cumTICK_ma[1]  then down_ma else na; # 'Bull Trend'
BullTrend.SetLineWeight(2);
BullTrend.SetDefaultColor(GlobalColor("up"));

plot BullTrend_ = if t1 and bull_trend and cumTICK_ma < cumTICK_ma[1] then down_ma else na;  # 'Bull Trend'
BullTrend_.SetDefaultColor(GlobalColor("dup"));

plot UpperATR = if show_Band then up_ma else na;      # 'Upper ATR'
plot LowerATR = if show_Band then down_ma else na;    # 'Lower ATR'
UpperATR.SetDefaultColor(GlobalColor("ddn"));
LowerATR.SetDefaultColor(GlobalColor("dup"));

plot midLine = if ShowMidLine then mid_ma else na;
midLine.AssignValueColor(if mid_ma>mid_ma[1] then Color.WHITE else Color.DARK_GRAY);
#midLine.SetStyle(Curve.SHORT_DASH);

def midBar = OHLC4;
def BearBand = !isNaN(BearTrend) or !isNaN(BearTrend_);
def BullBand = !isNaN(BullTrend) or !isNaN(BullTrend_);
AddCloud(if BearBand then up_ma else na, midBar, Color.DARK_RED, Color.DARK_RED);
AddCloud(if BullBand then midBar else na, down_ma, Color.DARK_GREEN, Color.DARK_GREEN);

#-- Signal
def SigUp = t1[1] and BullBand and !BullBand[1];
def SigDn = t1[1] and BearBand and !BearBand[1];

AddChartBubble(ShowSignals and SigUp, low, "Buy", Color.GREEN, no);
AddChartBubble(ShowSignals and SigDn, high, "Sell", Color.REd, yes);

#-- Bar Color
def ExtUp = Source>mid_ma and BullBand;
def UpBar = BullBand;
def ExtDn = Source<mid_ma and BearBand;
def DnBar = BearBand;

AssignPriceColor(if !BarColor or !intraDay then Color.CURRENT else
                 if ExtUp then Color.GREEN else
                 if UpBar then Color.DARK_GREEN else
                 if ExtDn then Color.RED else
                 if DnBar then Color.DARK_RED else Color.GRAY);



# --- END CODE
 

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

hi,

Anyone able to convert following into TOS?

https://www.tradingview.com/script/h8gUCab1-Cumulative-TICK-Pt/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PtGambler

//@version=5
indicator(title='Cumulative TICK [Pt]', shorttitle='CumTICK[Pt]', overlay=false)

tick_src = input.string("USI:TICK", "TICK Source", options = ["USI:TICK", "USI:TICKQ", "USI:TICKI", "USI:TICKA"])
candle_src = input.string('Close', 'TICK Data', options = ['Close', 'Open', 'hl2', 'ohlc4', 'hlc3'])
show_ma = input.bool(false, "Apply SMA | length", inline = 'ma')
ma_len = input.int(5, '', inline = 'ma')

t1 = time(timeframe.period, "0930-1600:23456", "America/New_York")

//get TICK data
[tickO, tickH, tickL, tickC, tickHL2, tickOHLC4, tickHLC3] = request.security(tick_src, timeframe.period, [open, high, low, close, hl2, ohlc4, hlc3])

cumTICK_src = switch candle_src
'Close' => tickC
'Open' => tickO
'hl2' => tickHL2
'ohlc4' => tickOHLC4
'hlc3' => tickHLC3

// Cumulative TICK ----------------------------------

var cumTICK = 0.0

if t1
cumTICK += cumTICK_src
if not t1 or session.islastbar_regular
cumTICK := 0

cumTICK_ma = show_ma ? ta.sma(cumTICK, ma_len) : cumTICK

plot(cumTICK_ma, "Cumulative TICK", cumTICK_ma > 0 and cumTICK_ma < cumTICK_ma[1] ? color.new(color.green,80) : cumTICK_ma > 0 and cumTICK_ma >= cumTICK_ma[1] ? color.new(color.green,50) : cumTICK_ma < 0 and cumTICK_ma < cumTICK_ma[1] ? color.new(color.red, 50) : color.new(color.red, 80), style = plot.style_columns)

bgcolor(not t1 ? color.new(color.white,95) : na, title = 'After-hour Background Color')
 
hi,

Anyone able to convert following into TOS?

https://www.tradingview.com/script/h8gUCab1-Cumulative-TICK-Pt/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PtGambler

//@version=5
indicator(title='Cumulative TICK [Pt]', shorttitle='CumTICK[Pt]', overlay=false)

tick_src = input.string("USI:TICK", "TICK Source", options = ["USI:TICK", "USI:TICKQ", "USI:TICKI", "USI:TICKA"])
candle_src = input.string('Close', 'TICK Data', options = ['Close', 'Open', 'hl2', 'ohlc4', 'hlc3'])
show_ma = input.bool(false, "Apply SMA | length", inline = 'ma')
ma_len = input.int(5, '', inline = 'ma')

t1 = time(timeframe.period, "0930-1600:23456", "America/New_York")

//get TICK data
[tickO, tickH, tickL, tickC, tickHL2, tickOHLC4, tickHLC3] = request.security(tick_src, timeframe.period, [open, high, low, close, hl2, ohlc4, hlc3])

cumTICK_src = switch candle_src
'Close' => tickC
'Open' => tickO
'hl2' => tickHL2
'ohlc4' => tickOHLC4
'hlc3' => tickHLC3

// Cumulative TICK ----------------------------------

var cumTICK = 0.0

if t1
cumTICK += cumTICK_src
if not t1 or session.islastbar_regular
cumTICK := 0

cumTICK_ma = show_ma ? ta.sma(cumTICK, ma_len) : cumTICK

plot(cumTICK_ma, "Cumulative TICK", cumTICK_ma > 0 and cumTICK_ma < cumTICK_ma[1] ? color.new(color.green,80) : cumTICK_ma > 0 and cumTICK_ma >= cumTICK_ma[1] ? color.new(color.green,50) : cumTICK_ma < 0 and cumTICK_ma < cumTICK_ma[1] ? color.new(color.red, 50) : color.new(color.red, 80), style = plot.style_columns)

bgcolor(not t1 ? color.new(color.white,95) : na, title = 'After-hour Background Color')
yes here

https://usethinkscript.com/threads/cumulative-tick-trend-pt-for-thinkorswim.15551/
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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