$tick study Color Assignment help

grapetux

Member
Hey there,

Im having trouble writing the proper code to differentiate between the different desired values I'd like displayed.
Below is the code Ive been working on thus far.
The bottom code in bold is what Ive been struggling with.
Everything works, I'd just like to have tick values that exceed +/- 700 paint a different color without negating the color assignment already in place.

Hope Ive explained this well enough, appreciate any help! Cheers.

##custom TICK indicator##

declare lower;
input hidecumtick = yes;
input hidemean = no;
input usetrend = { "No", default "Yes"};
input change_candle_colors = yes;
input symbol = "$TICK";
input period = 20;
input lookback = 4;

## Coding definitions ##
def p = period;
def i = BarNumber();
def na = Double.NaN;
def hi = high("$TICK");
def lo = low("$TICK");
def location = close;


## 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]));

def bull = if htick > avgh then htick - avgh else 0;
def bear = if ltick < avgl then ltick - avgl else 0;

def average_mean = if IsNaN(close) then na else (avgh + avgl) / 2;


def average_hi = if IsNaN(close) then na else avgh;
def average_lo = if IsNaN(close) then na else avgl;


plot hib = if hi < 0 then hi else na;
hib.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
hib.SetDefaultColor(Color.DARK_GRAY);
hib.SetLineWeight(3);

plot lob = if lo > 0 then lo else na;
lob.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
lob.SetDefaultColor(Color.DARK_GRAY);
lob.SetLineWeight(3);



####CROSSOVA WORKS####

def ema1 = ExpAverage(close, 50);
def aboveavg = hi > average_hi;
def belowavg= lo < average_lo;

plot phi = hi;
phi.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
phi.AssignValueColor(if aboveavg then Color.DARK_GREEN else Color.light_orange);

##if hi >700 then color.green##

plot plo = lo;
plo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plo.AssignValueColor(if belowavg then CreateColor(250,10, 10) else color.light_orange);

###if lo < -700 then color.white###

 
Solution
@grapetux why can't you just use color.CURRENT?
Ruby:
plot phi = hi;
phi.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
phi.AssignValueColor(if aboveavg then Color.DARK_GREEN else Color.current);
##if hi >700 then color.green##

plot plo = lo;
plo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plo.AssignValueColor(if belowavg then CreateColor(250,10, 10) else color.current);
###if lo < -700 then color.white###
Hey there,

Im having trouble writing the proper code to differentiate between the different desired values I'd like displayed.
Below is the code Ive been working on thus far.
The bottom code in bold is what Ive been struggling with.
Everything works, I'd just like to have tick values that exceed +/- 700 paint a different color without negating the color assignment already in place.

Hope Ive explained this well enough, appreciate any help! Cheers.

##custom TICK indicator##

declare lower;
input hidecumtick = yes;
input hidemean = no;
input usetrend = { "No", default "Yes"};
input change_candle_colors = yes;
input symbol = "$TICK";
input period = 20;
input lookback = 4;

## Coding definitions ##
def p = period;
def i = BarNumber();
def na = Double.NaN;
def hi = high("$TICK");
def lo = low("$TICK");
def location = close;


## 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]));

def bull = if htick > avgh then htick - avgh else 0;
def bear = if ltick < avgl then ltick - avgl else 0;

def average_mean = if IsNaN(close) then na else (avgh + avgl) / 2;


def average_hi = if IsNaN(close) then na else avgh;
def average_lo = if IsNaN(close) then na else avgl;


plot hib = if hi < 0 then hi else na;
hib.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
hib.SetDefaultColor(Color.DARK_GRAY);
hib.SetLineWeight(3);

plot lob = if lo > 0 then lo else na;
lob.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
lob.SetDefaultColor(Color.DARK_GRAY);
lob.SetLineWeight(3);



####CROSSOVA WORKS####

def ema1 = ExpAverage(close, 50);
def aboveavg = hi > average_hi;
def belowavg= lo < average_lo;

plot phi = hi;
phi.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
phi.AssignValueColor(if aboveavg then Color.DARK_GREEN else Color.light_orange);

##if hi >700 then color.green##

plot plo = lo;
plo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plo.AssignValueColor(if belowavg then CreateColor(250,10, 10) else color.light_orange);

###if lo < -700 then color.white###
I figure out somewhat of a workaround.. although it overrides the "average_hi and average_lo" which has used to calculate the value of the aboveavg / belowavg plot.

plot phi = hi;
phi.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#phi.AssignValueColor(if aboveavg then Color.DARK_GREEN else Color.light_orange); -------<original
phi.assignValueColor(if hi>600 then color.green else color.light_orange);---<new


plot plo = lo;
plo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#plo.AssignValueColor(if belowavg then CreateColor(250,10, 10) else color.light_orange); --------<original
plo.assignValueColor(if lo<-600 then color.red else color.light_orange)--<new

If anyone has an idea to incorporate all of the prior definitions while assigning a new color to tick values above +700 an below -700 that would be a huge help.
 

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

@grapetux why can't you just use color.CURRENT?
Ruby:
plot phi = hi;
phi.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
phi.AssignValueColor(if aboveavg then Color.DARK_GREEN else Color.current);
##if hi >700 then color.green##

plot plo = lo;
plo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plo.AssignValueColor(if belowavg then CreateColor(250,10, 10) else color.current);
###if lo < -700 then color.white###
 
Solution
@grapetux why can't you just use color.CURRENT?
Ruby:
plot phi = hi;
phi.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
phi.AssignValueColor(if aboveavg then Color.DARK_GREEN else Color.current);
##if hi >700 then color.green##

plot plo = lo;
plo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plo.AssignValueColor(if belowavg then CreateColor(250,10, 10) else color.current);
###if lo < -700 then color.white###
sorry for the late response and thanks for the help
when I tried to .current it changed all the previous candles to orange..
I ended up starting from scratch and came up with something that looks pretty good. Here's the full code of the study I'm using:
It's a histogram plot of tick values - great for following the trend intraday



#TICKSTER CUSTOM #

declare lower;
input hidecumtick = yes;
input hidemean = no;
input usetrend = { "No", default "Yes"};
input change_candle_colors = yes;
input symbol = "$TICK";
input period = 20;
input lookback = 4;
## Coding definitions ##
def p = period;
def i = BarNumber();
def na = Double.NaN;
def hi = high("$TICK");
def lo = low("$TICK");
def location = close;
## 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]));

plot zero = 0;
zero .SetDefaultColor(Color.black);
zero .SetLineWeight(1);
def average_hi = if IsNaN(close) then na else avgh;
def average_lo = if IsNaN(close) then na else avgl;

plot AskGray = if hi < 0 then hi else na;
AskGray.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
AskGray.SetDefaultColor(Color.DARK_GRAY);
AskGray.SetLineWeight(2);

plot BidGray = if lo > 0 then lo else na;
BidGray.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BidGray.SetDefaultColor(Color.DARK_GRAY);
BidGray.SetLineWeight(2);

####signals####

def ema1 = ExpAverage(close, 20);
input BuyPressureSignal = 1000;
plot BPsignal = if hi > 0 and hi > hi[1] and lo[2] < -600 and close < ema1 and close > open then BuyPressureSignal else Double.NaN;
BPsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BPsignal.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BPsignal.SetLineWeight(2);

input SellPressureSignal= 1000;
plot SPsignal = if lo < 0 and lo < lo[1] and hi[2] > 600 and close > ema1 and close < open then SellPressureSignal else Double.NaN;
SPsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SPsignal.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SPsignal.SetLineWeight(2);

input TickX = 800;
plot TickCross = if hi < 0 and hi[2] > 350 and close>emA1 then TickX else Double.NaN;
TickCross.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

#close > ema1

##main ask and bid bars###
plot Ask = hi;
Ask.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Ask.AssignValueColor(if hi > 400 then Color.GREEN else Color.LIGHT_ORANGE);
Ask.SetLineWeight(2);

plot Bid = lo;
Bid.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Bid.AssignValueColor(if lo < -400 then Color.RED else Color.LIGHT_ORANGE);
Bid.SetLineWeight(2);


#####extreme and high tick values Repaint######

input ExtremeAsk = 1400;
plot Ask1000above = if hi >= 1000 then ExtremeAsk else Double.NaN;
Ask1000above.SetPaintingStrategy(PaintingStrategy.line);

#Ask1000above.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Ask1000above.AssignValueColor(if Ask1000above then Color.magenta else Color.CURRENT);

input ExtremeBid = -1400;
plot Bid1000below = if lo <= -1000 then ExtremeBid else Double.NaN;
Bid1000below.SetPaintingStrategy(PaintingStrategy.line);

#Bid900below.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Bid900below.AssignValueColor(if Bid900below then Color.white else Color.CURRENT);




#input HighBid = -950;
#plot Bid700below = if lo < -700 and lo > -900 then HighBid else Double.NaN;
#Bid700below.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Bid700below.AssignValueColor(if Bid700below then Color.BLACK else Color.CURRENT);

#input HighAsk = 950;
#plot Ask700above = if hi > 700 and hi < 900 then HighAsk else Double.NaN;
#Ask700above.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Ask700above.AssignValueColor(if Ask700above then Color.BLACK else Color.CURRENT);

input UpperBoundary = 1500;
plot Upperlevel= if hi>0 then UpperBoundary else Double.NaN;
upperlevel.SetPaintingStrategy(PaintingStrategy.linE);
upperlevel.AssignValueColor(if upperlevel then Color.green else Color.CURRENT);
upperlevel.setLineWeight(4);

input LowerBoundary = -1500;
plot Lowerlevel = if lo<0 then LowerBoundary else double.NaN;
lowerlevel.SetPaintingStrategy(PaintingStrategy.line);
lowerlevel.AssignValueColor(if lowerlevel then Color.red else Color.current);
lowerlevel.setLineWeight(4);
 
Thats pretty cool. Much easier to see than the standard bars. Can you explain how you intend the colors to be used? Like the BPsignal triggers when the low from 2 periods back was under -600, close was under ema1 but over the open, and making a new high. How did you come about that calculation and intend to use it?

Also, I think you left the period input out of the ema and mean to use this.
def ema1 = ExpAverage(close, period);

Thanks for doing this!
 
Found another one. I think you mean for the bpsignal to be an arrow, but the paint as histogram takes over and paints the bar to +/-1000
Hey there , I actually meant for that to plot a histogram bar but feel free to change it to your liking.
As far as my thought process with the codes for the signals, Im still in the trial and error phase watching how the signals react with the price action. I turned off the buy pressure signal because it seemed like the signals were a little redundant. My thinking on the sell pressure was finding areas where there was an extreme reading above the zero line and then followed by tick reading below the zero line, indicating selling pressure coming into the market. Im still tweaking the code and will put any updates in here that are worthwhile. Feel free to share any ideas, cheers
-N
 
sorry for the late response and thanks for the help
when I tried to .current it changed all the previous candles to orange..
I ended up starting from scratch and came up with something that looks pretty good. Here's the full code of the study I'm using:
It's a histogram plot of tick values - great for following the trend intraday



#TICKSTER CUSTOM #

declare lower;
input hidecumtick = yes;
input hidemean = no;
input usetrend = { "No", default "Yes"};
input change_candle_colors = yes;
input symbol = "$TICK";
input period = 20;
input lookback = 4;
## Coding definitions ##
def p = period;
def i = BarNumber();
def na = Double.NaN;
def hi = high("$TICK");
def lo = low("$TICK");
def location = close;
## 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]));

plot zero = 0;
zero .SetDefaultColor(Color.black);
zero .SetLineWeight(1);
def average_hi = if IsNaN(close) then na else avgh;
def average_lo = if IsNaN(close) then na else avgl;

plot AskGray = if hi < 0 then hi else na;
AskGray.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
AskGray.SetDefaultColor(Color.DARK_GRAY);
AskGray.SetLineWeight(2);

plot BidGray = if lo > 0 then lo else na;
BidGray.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BidGray.SetDefaultColor(Color.DARK_GRAY);
BidGray.SetLineWeight(2);

####signals####

def ema1 = ExpAverage(close, 20);
input BuyPressureSignal = 1000;
plot BPsignal = if hi > 0 and hi > hi[1] and lo[2] < -600 and close < ema1 and close > open then BuyPressureSignal else Double.NaN;
BPsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BPsignal.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
BPsignal.SetLineWeight(2);

input SellPressureSignal= 1000;
plot SPsignal = if lo < 0 and lo < lo[1] and hi[2] > 600 and close > ema1 and close < open then SellPressureSignal else Double.NaN;
SPsignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SPsignal.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SPsignal.SetLineWeight(2);

input TickX = 800;
plot TickCross = if hi < 0 and hi[2] > 350 and close>emA1 then TickX else Double.NaN;
TickCross.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

#close > ema1

##main ask and bid bars###
plot Ask = hi;
Ask.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Ask.AssignValueColor(if hi > 400 then Color.GREEN else Color.LIGHT_ORANGE);
Ask.SetLineWeight(2);

plot Bid = lo;
Bid.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Bid.AssignValueColor(if lo < -400 then Color.RED else Color.LIGHT_ORANGE);
Bid.SetLineWeight(2);


#####extreme and high tick values Repaint######

input ExtremeAsk = 1400;
plot Ask1000above = if hi >= 1000 then ExtremeAsk else Double.NaN;
Ask1000above.SetPaintingStrategy(PaintingStrategy.line);

#Ask1000above.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Ask1000above.AssignValueColor(if Ask1000above then Color.magenta else Color.CURRENT);

input ExtremeBid = -1400;
plot Bid1000below = if lo <= -1000 then ExtremeBid else Double.NaN;
Bid1000below.SetPaintingStrategy(PaintingStrategy.line);

#Bid900below.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Bid900below.AssignValueColor(if Bid900below then Color.white else Color.CURRENT);




#input HighBid = -950;
#plot Bid700below = if lo < -700 and lo > -900 then HighBid else Double.NaN;
#Bid700below.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Bid700below.AssignValueColor(if Bid700below then Color.BLACK else Color.CURRENT);

#input HighAsk = 950;
#plot Ask700above = if hi > 700 and hi < 900 then HighAsk else Double.NaN;
#Ask700above.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#Ask700above.AssignValueColor(if Ask700above then Color.BLACK else Color.CURRENT);

input UpperBoundary = 1500;
plot Upperlevel= if hi>0 then UpperBoundary else Double.NaN;
upperlevel.SetPaintingStrategy(PaintingStrategy.linE);
upperlevel.AssignValueColor(if upperlevel then Color.green else Color.CURRENT);
upperlevel.setLineWeight(4);

input LowerBoundary = -1500;
plot Lowerlevel = if lo<0 then LowerBoundary else double.NaN;
lowerlevel.SetPaintingStrategy(PaintingStrategy.line);
lowerlevel.AssignValueColor(if lowerlevel then Color.red else Color.current);
lowerlevel.setLineWeight(4);
@grapetux why can't you just use color.CURRENT?
Ruby:
plot phi = hi;
phi.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
phi.AssignValueColor(if aboveavg then Color.DARK_GREEN else Color.current);
##if hi >700 then color.green##

plot plo = lo;
plo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
plo.AssignValueColor(if belowavg then CreateColor(250,10, 10) else color.current);
###if lo < -700 then color.white###
I figured out the code for the question I was originally asking about

plot Ask = hi;
Ask.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Ask.AssignValueColor(if hi > 1200 then Color.BLACK else if hi < 1200 and hi >= 950 then Color.MAGENTA else if aboveavg then Color.GREEN else Color.LIGHT_ORANGE);
Ask.SetLineWeight(2);


plot Bid = lo;
Bid.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Bid.AssignValueColor(if lo < -1200 then Color.BLACK else if lo > -1200 and lo <= -950 then Color.MAGENTA else if belowavg then Color.RED else Color.LIGHT_ORANGE);
Bid.SetLineWeight(2);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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