NexusFi: Find Your Edge


Home Menu

 





Changing bar colors on TOS charts, when conditions met.


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one mcamilapaez with 4 posts (0 thanks)
    2. looks_two rmejia with 3 posts (0 thanks)
    3. looks_3 meeks with 2 posts (0 thanks)
    4. looks_4 Drive with 1 posts (0 thanks)
    1. trending_up 28,228 views
    2. thumb_up 0 thanks given
    3. group 6 followers
    1. forum 11 posts
    2. attach_file 2 attachments




 
Search this Thread
  #1 (permalink)
mcamilapaez
San Jose, Costa Rica
 
Posts: 5 since May 2014
Thanks Given: 3
Thanks Received: 0

Does someone know how to change the color on TOS chart bars once two different conditions have been met?


Reply With Quote

 
  #2 (permalink)
 
rmejia's Avatar
 rmejia 
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 439

The candle color?

AssignPriceColor
https://toslc.thinkorswim.com/center/charting/thinkscript/reference/Functions/Look---Feel/AssignPriceColor


Reply With Quote
  #3 (permalink)
mcamilapaez
San Jose, Costa Rica
 
Posts: 5 since May 2014
Thanks Given: 3
Thanks Received: 0


Thanks!! I have already tried those instructios unsuccessfully.


Reply With Quote
  #4 (permalink)
 
rmejia's Avatar
 rmejia 
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 439

Post the code you are trying to edit to see what's up.


Reply With Quote
  #5 (permalink)
mcamilapaez
San Jose, Costa Rica
 
Posts: 5 since May 2014
Thanks Given: 3
Thanks Received: 0

What I want to do is find the price bar in which there is divergence between price and momentum(28) (over the last 60 perios). Once a divergence is present I want either the price bar to be colored (red for bear divergence/blue for bull) or highlight it somehow...
And it is not working correctly..

declare upper;
INPUT Price = CLOSE;
AssignBackgroundColor(Color.BLACK);
def mom28 = price-price[28];
def swinghigh=highest(60);
def swinglow=lowest(60);
def swingmomhigh=highest(mom28,60);
def swingmomlow=lowest(mom28,60);
def MOMBEAR=mom28<swingmomhigh;
def MOMBULL=mom28>swingmomlow;

Assignpricecolor(if swinghigh then (if MOMBEAR then color.red else color.white) else color.white);

Assignpricecolor(if swinglow then ( if MOMBULL then color.cyan else color.white) else color.white);


Thanks for your help!


Reply With Quote
  #6 (permalink)
 
rmejia's Avatar
 rmejia 
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 439

This is a code I have previously worked on; not sure if it is similar to what you are looking for regarding Momentum.

It is the default Momentum indicator with divergence. I set it to 28 length and bars back 60 for the image. The code is a mess, I have several experiments going on in it, have not cleaned it. Can be a starting point if similar to what you need.

 
Code
declare lower;

input length = 12;
input price = close;

Assert(length > 0, "'length' must be positive: " + length);

plot Momentum = price - price[length];
plot ZeroLine = 0;

#Momentum.SetDefaultColor(Color.Black);
Momentum.AssignValueColor(if Momentum > ZeroLine then Color.Green else Color.Red);
Momentum.setLineWeight(3);
#ZeroLine.SetDefaultColor(Color.Dark_Gray);
ZeroLine.AssignValueColor(if Momentum > ZeroLine then Color.Green else Color.Red);
ZeroLine.setLineWeight(2);


#AddCloud(Momentum, ZeroLine > 0, CreateColor(0, 80, 0), CreateColor(80, 0, 0));
AddCloud(Momentum, ZeroLine > 0, CreateColor(153,255,153), CreateColor(255,153,153));

input BarsBack = 60;
input MomAvgLength = 20;
input PaintBars = No;
plot MomAvg = ExpAverage(Momentum, MomAvgLength);
MomAvg.SetDefaultColor(CreateColor(51,51,51));
MomAvg.SetLineWeight(2);
MomAvg.SetStyle(Curve.Short_Dash);


plot DivergeTop = if Momentum>0 and Momentum<Momentum[1] and Momentum[1]>Momentum[2] and Momentum<highest(Momentum,BarsBack) and highest(Close,5)  > highest(Close[6],BarsBack) then highest(Momentum,barsBack) else double.nan;

plot DivergeBottom = if Momentum<0 and Momentum>Momentum[1] and Momentum[1]<Momentum[2] and Momentum>lowest(Momentum,BarsBack)and lowest(Close,5) < lowest(Close[6],BarsBack) then lowest(Momentum,BarsBack) else double.nan;

DivergeTop.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DivergeTop.SetLineWeight(5);
DivergeTop.SetDefaultColor(GetColor(5));

DivergeBottom.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DivergeBottom.SetLineWeight(5);
DivergeBottom.SetDefaultColor(GetColor(6));

AssignPriceColor (if !PaintBars then Color.CURRENT else if Momentum > 0 and Momentum < Momentum[1] and Momentum[1] > Momentum[2] and Momentum < Highest(Momentum, BarsBack) and Highest(close, 5)  > Highest(close[6], BarsBack) then color.Red else if Momentum < 0 and Momentum > Momentum[1] and Momentum[1] < Momentum[2] and Momentum > Lowest(Momentum, BarsBack) and Lowest(close, 5) < Lowest(close[6], BarsBack) then color.Cyan else Color.Current);

#AssignPriceColor (if !PaintBars then Color.CURRENT else if Momentum > 0 and Momentum < Momentum[1] and Momentum[1] > Momentum[2] and Momentum < Highest(Momentum, BarsBack) and Highest(close, 5)  > Highest(close[6], BarsBack) then color.Red else if Momentum < 0 and Momentum > Momentum[1] and Momentum[1] < Momentum[2] and Momentum > Lowest(Momentum, BarsBack) and Lowest(close, 5) < Lowest(close[6], BarsBack) then color.Green else if Momentum >= 0 then if Momentum > Momentum[1] then Color.Current else Color.Current else if Momentum < Momentum[1] then Color.Current else Color.Current);


Reply With Quote
  #7 (permalink)
mcamilapaez
San Jose, Costa Rica
 
Posts: 5 since May 2014
Thanks Given: 3
Thanks Received: 0

Thank you so much!
I will try it and Tell you then....


Reply With Quote
  #8 (permalink)
Drive
Bakersfield
 
Posts: 7 since Feb 2019
Thanks Given: 0
Thanks Received: 0

Im looking for something similar, instead I want my price candles to turn Green when the Slow Stochastic K period crosses above the D period, & Red when the K period crosses below the D period.


Reply With Quote
  #9 (permalink)
meeks
Cliffside Park, New Jersey
 
Posts: 2 since Jun 2020
Thanks Given: 0
Thanks Received: 0

Hello,
I'm trying to create a script where color of price bar is blue solely based on the time.

ie. on 30 min timeframe; 9:30AM - 10:00AM & 1:30PM - 2:00PM price bar is blue (regardless of price action), all else remain green/red (depending on price action).

Can anyone help with this?


Reply With Quote
  #10 (permalink)
 
lukeskywalker1's Avatar
 lukeskywalker1 
Los Angeles (CA)
 
Experience: Master
Platform: ThinkOrSwim
Trading: Currency Future, Stocks
Posts: 34 since Apr 2019
Thanks Given: 1
Thanks Received: 40



rmejia View Post
This is a code I have previously worked on; not sure if it is similar to what you are looking for regarding Momentum.

It is the default Momentum indicator with divergence. I set it to 28 length and bars back 60 for the image. The code is a mess, I have several experiments going on in it, have not cleaned it. Can be a starting point if similar to what you need.

 
Code
declare lower;

input length = 12;
input price = close;

Assert(length > 0, "'length' must be positive: " + length);

plot Momentum = price - price[length];
plot ZeroLine = 0;

#Momentum.SetDefaultColor(Color.Black);
Momentum.AssignValueColor(if Momentum > ZeroLine then Color.Green else Color.Red);
Momentum.setLineWeight(3);
#ZeroLine.SetDefaultColor(Color.Dark_Gray);
ZeroLine.AssignValueColor(if Momentum > ZeroLine then Color.Green else Color.Red);
ZeroLine.setLineWeight(2);


#AddCloud(Momentum, ZeroLine > 0, CreateColor(0, 80, 0), CreateColor(80, 0, 0));
AddCloud(Momentum, ZeroLine > 0, CreateColor(153,255,153), CreateColor(255,153,153));

input BarsBack = 60;
input MomAvgLength = 20;
input PaintBars = No;
plot MomAvg = ExpAverage(Momentum, MomAvgLength);
MomAvg.SetDefaultColor(CreateColor(51,51,51));
MomAvg.SetLineWeight(2);
MomAvg.SetStyle(Curve.Short_Dash);


plot DivergeTop = if Momentum>0 and Momentum<Momentum[1] and Momentum[1]>Momentum[2] and Momentum<highest(Momentum,BarsBack) and highest(Close,5)  > highest(Close[6],BarsBack) then highest(Momentum,barsBack) else double.nan;

plot DivergeBottom = if Momentum<0 and Momentum>Momentum[1] and Momentum[1]<Momentum[2] and Momentum>lowest(Momentum,BarsBack)and lowest(Close,5) < lowest(Close[6],BarsBack) then lowest(Momentum,BarsBack) else double.nan;

DivergeTop.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DivergeTop.SetLineWeight(5);
DivergeTop.SetDefaultColor(GetColor(5));

DivergeBottom.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DivergeBottom.SetLineWeight(5);
DivergeBottom.SetDefaultColor(GetColor(6));

AssignPriceColor (if !PaintBars then Color.CURRENT else if Momentum > 0 and Momentum < Momentum[1] and Momentum[1] > Momentum[2] and Momentum < Highest(Momentum, BarsBack) and Highest(close, 5)  > Highest(close[6], BarsBack) then color.Red else if Momentum < 0 and Momentum > Momentum[1] and Momentum[1] < Momentum[2] and Momentum > Lowest(Momentum, BarsBack) and Lowest(close, 5) < Lowest(close[6], BarsBack) then color.Cyan else Color.Current);

#AssignPriceColor (if !PaintBars then Color.CURRENT else if Momentum > 0 and Momentum < Momentum[1] and Momentum[1] > Momentum[2] and Momentum < Highest(Momentum, BarsBack) and Highest(close, 5)  > Highest(close[6], BarsBack) then color.Red else if Momentum < 0 and Momentum > Momentum[1] and Momentum[1] < Momentum[2] and Momentum > Lowest(Momentum, BarsBack) and Lowest(close, 5) < Lowest(close[6], BarsBack) then color.Green else if Momentum >= 0 then if Momentum > Momentum[1] then Color.Current else Color.Current else if Momentum < Momentum[1] then Color.Current else Color.Current);


Thank you mate so much!
I will try it as well


Visit my NexusFi Trade Journal Reply With Quote




Last Updated on June 18, 2020


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts