I added trend options you may check and test it. * working only during regular trading hours.
Author message:
The Tick Index is a short-term barometer of internal market strength.
It shows the number of stocks trading on an uptick minus the number of stocks trading on a downtick, and is used by day traders to view the overall market sentiment at a given point in time.
It's categorized as a Breadth Indicator because it analyzes the "Breadth and Scope" of an entire Index.
CODE: - Update - added option to change the trading hours
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © TheMas7er and bmistiaen
#indicator('TICK Grid (TheMas7er)', 'TICK Grid')
# Converted and mod by Sam4Cok@Samer800 - 12/2022
# update - option to enter the trading hours - 12/2022
declare lower;
#// Inputs
input startTime = 0930;
input endTime = 1600;
input index = {Nasdaq,default NYSE, Russell2000, SnP500, DJIA, All_US};
input barColor = no;
input EnableBackgroundColor = yes;
input showDynamicBand = yes;
input DynamicBandAgg = AggregationPeriod.DAY;
input ShowMaLine = yes;
input maType = AverageType.WEIGHTED;
input maLength = 53;
input smoothingType = AverageType.SIMPLE;
input trendLength = 10;
def na = Double.NaN;
def pos = if IsNaN(close) then na else Double.POSITIVE_INFINITY;
def neg = if IsNaN(close) then na else Double.NEGATIVE_INFINITY;
def RTH = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;
#--- Color
DefineGlobalColor("colorUp" , CreateColor(76, 175, 80));
DefineGlobalColor("colorDown", Color.DARK_GRAY);
#---
def indexH;
def indexL;
def _ticko;
def _tickh;
def _tickl;
def _tickc;
switch (index) {
case Nasdaq:
_ticko = Fundamental(FundamentalType.OPEN, "$TICK/Q");
_tickh = Fundamental(FundamentalType.HIGH, "$TICK/Q");
_tickl = Fundamental(FundamentalType.LOW, "$TICK/Q");
_tickc = Fundamental(FundamentalType.CLOSE, "$TICK/Q");
indexH = Fundamental(FundamentalType.HIGH, "$TICK/Q",DynamicBandAgg);
indexL = Fundamental(FundamentalType.LOW, "$TICK/Q",DynamicBandAgg);
case NYSE:
_ticko = Fundamental(FundamentalType.OPEN, "$TICK");
_tickh = Fundamental(FundamentalType.HIGH, "$TICK");
_tickl = Fundamental(FundamentalType.LOW, "$TICK");
_tickc = Fundamental(FundamentalType.CLOSE, "$TICK");
indexH = Fundamental(FundamentalType.HIGH, "$TICK",DynamicBandAgg);
indexL = Fundamental(FundamentalType.LOW, "$TICK",DynamicBandAgg);
case Russell2000:
_ticko = Fundamental(FundamentalType.OPEN, "$TIKRL");
_tickh = Fundamental(FundamentalType.HIGH, "$TIKRL");
_tickl = Fundamental(FundamentalType.LOW, "$TIKRL");
_tickc = Fundamental(FundamentalType.CLOSE, "$TIKRL");
indexH = Fundamental(FundamentalType.HIGH, "$TIKRL",DynamicBandAgg);
indexL = Fundamental(FundamentalType.LOW, "$TIKRL",DynamicBandAgg);
case SnP500:
_ticko = Fundamental(FundamentalType.OPEN, "$TIKSP");
_tickh = Fundamental(FundamentalType.HIGH, "$TIKSP");
_tickl = Fundamental(FundamentalType.LOW, "$TIKSP");
_tickc = Fundamental(FundamentalType.CLOSE, "$TIKSP");
indexH = Fundamental(FundamentalType.HIGH, "$TIKSP",DynamicBandAgg);
indexL = Fundamental(FundamentalType.LOW, "$TIKSP",DynamicBandAgg);
case DJIA:
_ticko = Fundamental(FundamentalType.OPEN, "$TIKI");
_tickh = Fundamental(FundamentalType.HIGH, "$TIKI");
_tickl = Fundamental(FundamentalType.LOW, "$TIKI");
_tickc = Fundamental(FundamentalType.CLOSE, "$TIKI");
indexH = Fundamental(FundamentalType.HIGH, "$TIKI",DynamicBandAgg);
indexL = Fundamental(FundamentalType.LOW, "$TIKI",DynamicBandAgg);
case All_US:
_ticko = Fundamental(FundamentalType.OPEN, "$TIKUS");
_tickh = Fundamental(FundamentalType.HIGH, "$TIKUS");
_tickl = Fundamental(FundamentalType.LOW, "$TIKUS");
_tickc = Fundamental(FundamentalType.CLOSE, "$TIKUS");
indexH = Fundamental(FundamentalType.HIGH, "$TIKUS",DynamicBandAgg);
indexL = Fundamental(FundamentalType.LOW, "$TIKUS",DynamicBandAgg);
}
#// Functions
##f_showLevel(_show, _level) =>
#script f_showLevel {
# input _show = yes;
# input _level = 1000;
# def level = if _show then if _level then _level else Double.NaN else Double.NaN;
# plot return = level;
#}
#// Levels
def hh = Average(highest(indexH,1),50);
def hl = Average(Lowest(indexH,2), 50);
def ll = Average(Lowest(indexl,1),50);
def lh = Average(highest(indexl,2),50);
def tickhi = if showDynamicBand then if RTH then hl else na else na;
def tickhi1 = if showDynamicBand then if RTH then hh else na else na;
def ticklo = if showDynamicBand then if RTH then lh else na else na;
def ticklo1 = if showDynamicBand then if RTH then ll else na else na;
def zeroAvg = (tickhi1 + ticklo1) / 2;
def ticko;
def tickh;
def tickl;
def tickc;
def avgo;
def avgh;
def avgl;
def avgc;
if RTH {
ticko = if isNaN(_ticko) then _ticko[1] else _ticko;
tickh = if isNaN(_tickh) then _tickh[1] else _tickh;
tickl = if isNaN(_tickl) then _tickl[1] else _tickl;
tickc = if isNaN(_tickc) then _tickc[1] else _tickc;
avgo = if isNaN(_ticko) then avgo[1] else _ticko;
avgh = if isNaN(_tickh) then avgh[1] else _tickh;
avgl = if isNaN(_tickl) then avgl[1] else _tickl;
avgc = if isNaN(_tickc) then avgc[1] else _tickc;
} else {
ticko = na;
tickh = na;
tickl = na;
tickc = na;
avgo = avgo[1];
avgh = avgh[1];
avgl = avgl[1];
avgc = avgc[1];
}
#// Plot Candles
def candleUp = tickc > ticko;
AddChart(high = if candleUp then tickh else na, low = tickl , open = tickc, close = ticko,
type = ChartType.CANDLE, growcolor = GlobalColor("colorUp"));
AddChart(high = if !candleUp then tickh else na , low = tickl , open = ticko, close = tickc,
type = ChartType.CANDLE, growcolor = GlobalColor("colorDown"));
#// Plot levels
#def count = (if(isNaN(tickh),0,1) + if(isNaN(tickl),0,1) + if(isNaN(tickc),0,1) + if(isNaN(ticko),0,1));
def inHigh = avgh;
def inLow = avgl;
def inClose = avgc;
def inOpen = avgo;
def ohlc = (inHigh + inLow + inClose + inOpen) / 4;
def tickMa = MovingAverage(maType,ohlc,maLength);
def maColor = MovingAverage(maType,tickMa,maLength);
def trendMa = MovingAverage(smoothingType,tickMa,trendLength);
plot Avg = if ShowMaLine and RTH then tickMa else na;
Avg.AssignValueColor(if Avg>maColor then Color.CYAN else
if Avg<maColor then Color.MAGENTA else Color.GRAY);
AddCloud(if RTH and tickMa>trendMa then pos else na, neg, Color.DARK_GREEN);
AddCloud(if RTH and tickMa<trendMa then pos else na, neg, Color.DARK_RED);
plot highTop = if !RTH then na else tickhi1;
highTop.SetDefaultColor(Color.GRAY);
plot highBot = if !RTH then na else tickhi;
highBot.SetDefaultColor(Color.GRAY);
highBot.SetStyle(Curve.SHORT_DASH);
plot ZeroLine = if !RTH then na else zeroAvg;
ZeroLine.SetDefaultColor(Color.GRAY);
ZeroLine.SetStyle(Curve.MEDIUM_DASH);
plot lowBot = if !RTH then na else ticklo1;
lowBot.SetDefaultColor(Color.GRAY);
plot lowTop = if !RTH then na else ticklo;
lowTop.SetDefaultColor(Color.GRAY);
lowTop.SetStyle(Curve.SHORT_DASH);
def extUp = tickMa>trendMa and tickMa>maColor;
def Up = tickMa>trendMa and tickMa<maColor;
def extDn = tickMa<trendMa and tickMa<maColor;
def Dn = tickMa<trendMa and tickMa>maColor;
AssignPriceColor(if !barColor then Color.CURRENT else
if extUp then Color.GREEN else
if up then Color.DARK_GREEN else
if extDn then Color.RED else
if Dn then Color.DARK_RED else Color.GRAY);
AssignBackgroundColor(if !EnableBackgroundColor then Color.CURRENT else if tickMa>trendMa then CreateColor(1,25,16) else if tickMa<trendMa then CreateColor(38,0,0) else Color.CURRENT);
# --- END CODE
Last edited: