Hi all. I found this code:
The coding looks pretty complicated to me, but the creator included a lot of good description.
There are lots of options/descriptions within the settings to make adjustments which I really like.
Basically I'm hoping somebody could tell me what to add to the code to provide the following:
I want a setting for each 'Extreme' that I can turn on/off that controls the following:
An arrow/dot/etc. that I can control the color & width, that will appear in the Upper Chart either above or below the candle (above when + extreme is met / below when - extreme is met) when the value of green bar in the lower study reaches different values that I can also control manually (i.e. +/-300, +/-500, +/-1000).
I want this signal to show up in the upper study if the value is reached within the lower study bar value and remain there forever even if the candle closes and the value of the bar in the lower study changes.
Possibly using the settings label as Extreme1, Extreme2, Extreme3, Extreme4, Extreme5, Extreme6
I am in no way a coder. I have tried to accomplish this with no success. I can't quite understand how to have the ability to make value changes and also be able to control the look and type of indication in upper chart.
P.S The arrows that currently display within the lower plot called 'buy' & 'sell' appear when the "average_hi / average_lo" are reached. I want the above described indication in the upper chart with the value control ability.
Any help is greatly appreciated. An example of what I'm thinking is displayed in the below picture showing thick yellow arrows that are displayed in the upper chart for instance when the values +1000 & -500 are reached. I've been fooling with the code for days with no progress. If someone has a different indicator or easier solution to get what I'm looking for I'm all ears!
Thanks in Advance!
Original code:
https://usethinkscript.com/threads/cumulative-tick-indicator-for-thinkorswim.603/
https://tos.mx/x6xGEy9
declare lower;
input hidecumtick = yes; #hint hidecumtick: <b> Cumulative $TICK </b> \n\n Think of the Cumulative $TICK as a built in indicator that is showing the total accumulated value of TICK's today. \n If hidecumtick <b> "Yes" </b> then the cumulative tick lines will not show. \n\n Some ways that we use the Cumulative TICK include: \n When we have a likely trending day vs. when we expect choppy days \n When the trend has exhauste and we expect a reversal \n Zones that signify “extreme” Cumulative TICK readings \n This will hide the cumtick and the nettick plots.
input hidemean = no; #hint hidemean: <b> MEAN </b> \n\n The Mean dots are plotted for people who want to use the <b> Cumulative $TICK </b> \n If hidemean <b> "Yes" </b> then the MEAN dots will be turned off. \n Think of this as a seperate indicator showing the "average ticks" rather than the "tick by tick" value. \n This is calculating the "average Mean" and is taking the avg high value and adding it to the average low value before dividing that number by 2.
input usetrend = { "No", default "Yes"}; #HINT usetrend: This is a setting that is used with the <b> Cumulative $TICK </b> - not with the $TICK meter.
input change_candle_colors = yes; #HINT change_candle_colors: Recognizing when the market breadth is on your side is easier when bullish and bearish $TICK action is taking place. \n\n Change Color Candles: <b> "Yes" </b> will "gray out" the candles in the upper chart unless there is actionable market breadth - then the colors will turn red or green to indicate aggressive positive or negative market breath and indicating a buying or selling opportunity \n\n Change Color Candles:<b> "No" </b> will allow the upper candles to be the color set by your chart default colors.
input symbol = "$TICK"; #HINT symbol: Default SYMBOL is $TICK (New York Stock Exchange). This can be changed to see the tick values for the Russel 2000, the NASDAQ and many others.
input period = 20; #HINT period: This is used to determine where the "average" ticks are on the day. \n This is the lookback period used to plot the green & red dashed lines that show up "typically" near 300 & -300.
#input smooth = 5; #HINT smooth: this is just an internal smoothing value and should not be adjusted.
input lookback = 4; #HINT lookback: Lookback is used in the script a few places \n\n * Lookback is used to calculate the trade triggers (buy & sell) \n * Lookback is used to color the dots on the cumulative plot \n * Lookback is used to color the candles on the chart - shows the current chart candles in vivid color to highlight when aggressive buying or aggressive selling is taking place within the NYSE total market
## Coding definitions ##
def p = period;
def i = barNumber();
def na = double.nan;
def hi = high("$TICK");
def lo = low("$TICK");
## Code designed to record things at a specific place and time
rec htick = if IsNaN(high(symbol)) then htick[1] else high("$TICK") ;
rec ltick = if IsNaN(low(symbol)) then ltick[1] else low("$TICK");
rec avgh = if i == 1 then htick else Max(300, avgh[1] + 2 / (p + 1) * (htick - avgh[1]));
rec avgl = if i == 1 then ltick else Min(-300, avgl[1] + 2 / (p + 1) * (ltick - avgl[1]));
## Coding Definitions ##
# Now that the values have been recorded - we can defnie new parts of the indicator. Here, the code is defining what is "bullish" and what is "bearish".
def bull = if htick > avgh then htick - avgh else 0;
def bear = if ltick < avgl then ltick - avgl else 0;
## Last ##
# $TICK Value: This is the actual $TICK
plot Last = if IsNaN(close(symbol)[-1]) then close(symbol) else double.nan;
Last .SetDefaultColor(Color.white);
Last .SetPaintingStrategy(PaintingStrategy.POINTS);
## AMEAN ##
# This is "average Mean" and is taking the avg high value and adding it to the average low value before dividing that number by 2. When calculating a "average" we always use this math; add up all the things & then divide by that many things.
plot average_mean = if IsNaN(close) then na else (avgh + avgl) / 2;
average_mean .setHiding(hidemean);
average_mean .SetLineWeight(5);
average_mean .SetStyle(curve.POINTS);
## Coding Definitions ##
# The indicator needs to know when the mean is getting outside of "normal" levels - this definition is telling the indicator when to use the average mean and when not to use the average mean
def trendmean = if usetrend AND (htick > avgh OR ltick < avgl) then average_mean else 0;
rec ctick = if i == 1 then 0 else if IsNaN(htick) OR IsNaN(ltick) then ctick[1] else ctick[1] + bull + bear + trendmean;
## Coding Definitions ##
# this defines the "average" of the cumulative $TICK
def ctickavg = ExpAverage(ctick, 5);
#this is the plot of the 5-period exponential moving average of the cumulative $TICK
plot cumtick = if IsNaN(close) then na else ctickavg;
cumtick .setHiding(hidecumtick);
cumtick .AssignValueColor(if cumtick > cumtick[lookback] then color.green else color.red);
#This is where the average_mean lines get their color definitions.
average_mean .AssignValueColor(if cumtick > cumtick[lookback] then color.green else color.red);
#this is the plot of the cumulative $TICK
plot nettick = if IsNaN(close) then na else ctick;
nettick .setHiding(hidecumtick);
#this is the plot of the Zero Line
plot zero = 0;
zero .SetDefaultColor(color.gray);
zero .SetLineWeight(1);
## Price Color ##
# Price color is the coding used to color the candles on the "upper" chart.
AssignPriceColor( if change_candle_colors then
if cumtick > cumtick[lookback] AND ltick < avgl then
color.green else
if cumtick > cumtick[lookback] then color.gray else
if cumtick < cumtick[lookback] AND htick > avgh then
color.red else color.gray else color.current);
cumtick.SetLineWeight(2);
## Clouds on the Cumulative Plots ##
# this part of the code was designed to show clouds within the cumulative plot
def hcumtick=if !hidecumtick then cumtick else na;
def hzero=if !hidecumtick then zero else na;
AddCloud(hcumtick, hzero );
####### Trade Triggers ### BUY ######
# the BUY signal comes from a combination of two events.
# this "buy" signal is generated when
# the 5-period cumulative $TICK is higher than the 5-period cumulative $TICK from ("lookback") 4 periods back
# AND #
# when the $TICK drops below the average low.
plot buy = if
cumtick > cumtick[lookback] AND ltick < avgl then low - tickSize() else if cumtick > cumtick[lookback] then na else if
cumtick < cumtick[lookback] AND htick > avgh then na else na;
buy .SetDefaultColor(color.green);
buy .SetPaintingStrategy(paintingStrategy.ARROW_UP);
####### Trade Triggers ### SELL #####
# the SELL signal comes from a combination of two events.
# This "sell" signal is generated when
# the 5-period cumulative $TICK is lower than the 5-period cumulative $TICK from ("lookback") 4 periods back
# AND #
# When the $TICK pops above the average high
plot sell = if
cumtick > cumtick[lookback] AND ltick < avgl then na else if
cumtick > cumtick[lookback] then na else if
cumtick < cumtick[lookback] AND htick > avgh then
high + tickSize() else na;
sell .SetDefaultColor(color.red);
sell .SetPaintingStrategy(paintingStrategy.ARROW_DOWN);
# shows the 20 period "average" tick value as a dashed line
plot average_hi = if IsNaN(close) then na else avgh;
average_hi .SetDefaultColor(color.green);
average_hi .SetStyle(curve.SHORT_DASH);
# shows the 20 period "average" tick value as a dashed line
plot average_lo = if IsNaN(close) then na else avgl;
average_lo .SetDefaultColor(color.red);
average_lo .SetStyle(curve.SHORT_DASH);
# high plot
# the $TICK crosses above and below the zero line often - this plot helps identify when the "highest" part of the candle was below the zero line or when the lowest part of the candle was above the zero line (indicating that the entire $TICK for that candle was completely above or completely below the zero line. On a Black Chart - this would help to show what the tick actually was plotting
plot hib = if hi < 0 then hi else na;
hib.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
hib.SetDefaultColor(color.black);
hib.SetLineWeight(5);
plot lob = if lo > 0 then lo else na;
lob.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
lob.SetDefaultColor(color.black);
lob.SetLineWeight(5);
# phi #
# when the $TICK crosses the average high (the green dashed line "near" 300) this shows the bars as a green color
plot phi = hi;
# plo #
# when the $TICK crosses the average low (the red dashed line "near" -300) this shows the bars as a red color
plot plo = lo;
#
phi.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
phi.AssignValueColor(if hi > average_hi then color.dark_GREEN else color.gray);
phi.SetLineWeight(5);
plo.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
plo.AssignValueColor(if lo < average_lo then color.dark_red else color.gray);
plo.SetLineWeight(5);
#Hiding depending on if upper or lower
There are lots of options/descriptions within the settings to make adjustments which I really like.
Basically I'm hoping somebody could tell me what to add to the code to provide the following:
I want a setting for each 'Extreme' that I can turn on/off that controls the following:
An arrow/dot/etc. that I can control the color & width, that will appear in the Upper Chart either above or below the candle (above when + extreme is met / below when - extreme is met) when the value of green bar in the lower study reaches different values that I can also control manually (i.e. +/-300, +/-500, +/-1000).
I want this signal to show up in the upper study if the value is reached within the lower study bar value and remain there forever even if the candle closes and the value of the bar in the lower study changes.
Possibly using the settings label as Extreme1, Extreme2, Extreme3, Extreme4, Extreme5, Extreme6
I am in no way a coder. I have tried to accomplish this with no success. I can't quite understand how to have the ability to make value changes and also be able to control the look and type of indication in upper chart.
P.S The arrows that currently display within the lower plot called 'buy' & 'sell' appear when the "average_hi / average_lo" are reached. I want the above described indication in the upper chart with the value control ability.
Any help is greatly appreciated. An example of what I'm thinking is displayed in the below picture showing thick yellow arrows that are displayed in the upper chart for instance when the values +1000 & -500 are reached. I've been fooling with the code for days with no progress. If someone has a different indicator or easier solution to get what I'm looking for I'm all ears!
Thanks in Advance!
Original code:
https://usethinkscript.com/threads/cumulative-tick-indicator-for-thinkorswim.603/
https://tos.mx/x6xGEy9
declare lower;
input hidecumtick = yes; #hint hidecumtick: <b> Cumulative $TICK </b> \n\n Think of the Cumulative $TICK as a built in indicator that is showing the total accumulated value of TICK's today. \n If hidecumtick <b> "Yes" </b> then the cumulative tick lines will not show. \n\n Some ways that we use the Cumulative TICK include: \n When we have a likely trending day vs. when we expect choppy days \n When the trend has exhauste and we expect a reversal \n Zones that signify “extreme” Cumulative TICK readings \n This will hide the cumtick and the nettick plots.
input hidemean = no; #hint hidemean: <b> MEAN </b> \n\n The Mean dots are plotted for people who want to use the <b> Cumulative $TICK </b> \n If hidemean <b> "Yes" </b> then the MEAN dots will be turned off. \n Think of this as a seperate indicator showing the "average ticks" rather than the "tick by tick" value. \n This is calculating the "average Mean" and is taking the avg high value and adding it to the average low value before dividing that number by 2.
input usetrend = { "No", default "Yes"}; #HINT usetrend: This is a setting that is used with the <b> Cumulative $TICK </b> - not with the $TICK meter.
input change_candle_colors = yes; #HINT change_candle_colors: Recognizing when the market breadth is on your side is easier when bullish and bearish $TICK action is taking place. \n\n Change Color Candles: <b> "Yes" </b> will "gray out" the candles in the upper chart unless there is actionable market breadth - then the colors will turn red or green to indicate aggressive positive or negative market breath and indicating a buying or selling opportunity \n\n Change Color Candles:<b> "No" </b> will allow the upper candles to be the color set by your chart default colors.
input symbol = "$TICK"; #HINT symbol: Default SYMBOL is $TICK (New York Stock Exchange). This can be changed to see the tick values for the Russel 2000, the NASDAQ and many others.
input period = 20; #HINT period: This is used to determine where the "average" ticks are on the day. \n This is the lookback period used to plot the green & red dashed lines that show up "typically" near 300 & -300.
#input smooth = 5; #HINT smooth: this is just an internal smoothing value and should not be adjusted.
input lookback = 4; #HINT lookback: Lookback is used in the script a few places \n\n * Lookback is used to calculate the trade triggers (buy & sell) \n * Lookback is used to color the dots on the cumulative plot \n * Lookback is used to color the candles on the chart - shows the current chart candles in vivid color to highlight when aggressive buying or aggressive selling is taking place within the NYSE total market
## Coding definitions ##
def p = period;
def i = barNumber();
def na = double.nan;
def hi = high("$TICK");
def lo = low("$TICK");
## Code designed to record things at a specific place and time
rec htick = if IsNaN(high(symbol)) then htick[1] else high("$TICK") ;
rec ltick = if IsNaN(low(symbol)) then ltick[1] else low("$TICK");
rec avgh = if i == 1 then htick else Max(300, avgh[1] + 2 / (p + 1) * (htick - avgh[1]));
rec avgl = if i == 1 then ltick else Min(-300, avgl[1] + 2 / (p + 1) * (ltick - avgl[1]));
## Coding Definitions ##
# Now that the values have been recorded - we can defnie new parts of the indicator. Here, the code is defining what is "bullish" and what is "bearish".
def bull = if htick > avgh then htick - avgh else 0;
def bear = if ltick < avgl then ltick - avgl else 0;
## Last ##
# $TICK Value: This is the actual $TICK
plot Last = if IsNaN(close(symbol)[-1]) then close(symbol) else double.nan;
Last .SetDefaultColor(Color.white);
Last .SetPaintingStrategy(PaintingStrategy.POINTS);
## AMEAN ##
# This is "average Mean" and is taking the avg high value and adding it to the average low value before dividing that number by 2. When calculating a "average" we always use this math; add up all the things & then divide by that many things.
plot average_mean = if IsNaN(close) then na else (avgh + avgl) / 2;
average_mean .setHiding(hidemean);
average_mean .SetLineWeight(5);
average_mean .SetStyle(curve.POINTS);
## Coding Definitions ##
# The indicator needs to know when the mean is getting outside of "normal" levels - this definition is telling the indicator when to use the average mean and when not to use the average mean
def trendmean = if usetrend AND (htick > avgh OR ltick < avgl) then average_mean else 0;
rec ctick = if i == 1 then 0 else if IsNaN(htick) OR IsNaN(ltick) then ctick[1] else ctick[1] + bull + bear + trendmean;
## Coding Definitions ##
# this defines the "average" of the cumulative $TICK
def ctickavg = ExpAverage(ctick, 5);
#this is the plot of the 5-period exponential moving average of the cumulative $TICK
plot cumtick = if IsNaN(close) then na else ctickavg;
cumtick .setHiding(hidecumtick);
cumtick .AssignValueColor(if cumtick > cumtick[lookback] then color.green else color.red);
#This is where the average_mean lines get their color definitions.
average_mean .AssignValueColor(if cumtick > cumtick[lookback] then color.green else color.red);
#this is the plot of the cumulative $TICK
plot nettick = if IsNaN(close) then na else ctick;
nettick .setHiding(hidecumtick);
#this is the plot of the Zero Line
plot zero = 0;
zero .SetDefaultColor(color.gray);
zero .SetLineWeight(1);
## Price Color ##
# Price color is the coding used to color the candles on the "upper" chart.
AssignPriceColor( if change_candle_colors then
if cumtick > cumtick[lookback] AND ltick < avgl then
color.green else
if cumtick > cumtick[lookback] then color.gray else
if cumtick < cumtick[lookback] AND htick > avgh then
color.red else color.gray else color.current);
cumtick.SetLineWeight(2);
## Clouds on the Cumulative Plots ##
# this part of the code was designed to show clouds within the cumulative plot
def hcumtick=if !hidecumtick then cumtick else na;
def hzero=if !hidecumtick then zero else na;
AddCloud(hcumtick, hzero );
####### Trade Triggers ### BUY ######
# the BUY signal comes from a combination of two events.
# this "buy" signal is generated when
# the 5-period cumulative $TICK is higher than the 5-period cumulative $TICK from ("lookback") 4 periods back
# AND #
# when the $TICK drops below the average low.
plot buy = if
cumtick > cumtick[lookback] AND ltick < avgl then low - tickSize() else if cumtick > cumtick[lookback] then na else if
cumtick < cumtick[lookback] AND htick > avgh then na else na;
buy .SetDefaultColor(color.green);
buy .SetPaintingStrategy(paintingStrategy.ARROW_UP);
####### Trade Triggers ### SELL #####
# the SELL signal comes from a combination of two events.
# This "sell" signal is generated when
# the 5-period cumulative $TICK is lower than the 5-period cumulative $TICK from ("lookback") 4 periods back
# AND #
# When the $TICK pops above the average high
plot sell = if
cumtick > cumtick[lookback] AND ltick < avgl then na else if
cumtick > cumtick[lookback] then na else if
cumtick < cumtick[lookback] AND htick > avgh then
high + tickSize() else na;
sell .SetDefaultColor(color.red);
sell .SetPaintingStrategy(paintingStrategy.ARROW_DOWN);
# shows the 20 period "average" tick value as a dashed line
plot average_hi = if IsNaN(close) then na else avgh;
average_hi .SetDefaultColor(color.green);
average_hi .SetStyle(curve.SHORT_DASH);
# shows the 20 period "average" tick value as a dashed line
plot average_lo = if IsNaN(close) then na else avgl;
average_lo .SetDefaultColor(color.red);
average_lo .SetStyle(curve.SHORT_DASH);
# high plot
# the $TICK crosses above and below the zero line often - this plot helps identify when the "highest" part of the candle was below the zero line or when the lowest part of the candle was above the zero line (indicating that the entire $TICK for that candle was completely above or completely below the zero line. On a Black Chart - this would help to show what the tick actually was plotting
plot hib = if hi < 0 then hi else na;
hib.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
hib.SetDefaultColor(color.black);
hib.SetLineWeight(5);
plot lob = if lo > 0 then lo else na;
lob.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
lob.SetDefaultColor(color.black);
lob.SetLineWeight(5);
# phi #
# when the $TICK crosses the average high (the green dashed line "near" 300) this shows the bars as a green color
plot phi = hi;
# plo #
# when the $TICK crosses the average low (the red dashed line "near" -300) this shows the bars as a red color
plot plo = lo;
#
phi.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
phi.AssignValueColor(if hi > average_hi then color.dark_GREEN else color.gray);
phi.SetLineWeight(5);
plo.SetPaintingStrategy(paintingStrategy.HISTOGRAM);
plo.AssignValueColor(if lo < average_lo then color.dark_red else color.gray);
plo.SetLineWeight(5);
#Hiding depending on if upper or lower
Last edited by a moderator: