Change chart's background based on thinkscript condition?

evanevans

Active member
Can the background color of a chart be changed under conditions of a ThinkScript? Or perhaps a full window cloud? It would be great to be able to do this, so I could know which of 100s of charts I monitor simultaneously all day, need my attention.

Something like this:

SJhgVT4.png


I want to create a ThinkScript that can color the background of the whole chart under a particular current condition. I already got this far:

AFyqxt3.png
 
Last edited by a moderator:

Pensar

Well-known member
VIP
Lifetime
@evanevans According to the pic, it looks like you want the background color to change based on the relationship between current price and the 20 day SMA. Check if this is right -

Code:
input length = 20;
input avg_type = averagetype.simple;
input agg = aggregationperiod.day;

def c = close(period = agg);
def sma = movingaverage(avg_type,c,length);

DefineGlobalColor("above",GetColor(1));
DefineGlobalColor("below",Color.BLACK);

AssignBackgroundColor(if close > sma
                      then GlobalColor("above")
                      else GlobalColor("below"));


When I started learning thinkscript, I went down many dead-end roads, and still do so frequently. Usually I'm overthinking the code.
 

evanevans

Active member
Awesome guys, thanks for all your help. I'm sure happy with this code, which I have completed:

Code:
#ChartAlert_SMA
#EvanEvans
#V1.0

input aggregationPeriod = AggregationPeriod.DAY;
input SMAPeriod = 20;
input SuperSMAPeriod = 50;
input averageType = AverageType.SIMPLE;
input AlertWhenPercentAboveSMA = 0.050;
input SuperAlertWhenPercentAboveSMA = 0.100;

def c = close(period = aggregationPeriod);
def sma = movingaverage(averageType,c,SMAperiod);
def SuperSMA = movingaverage(averageType,c,SuperSMAperiod);

DefineGlobalColor("SuperAbove",Color.Green);
DefineGlobalColor("Above",Color.Dark_Green);
DefineGlobalColor("Below",Color.Dark_Red);
DefineGlobalColor("SuperBelow",Color.Red);
DefineGlobalColor("default",Color.Current);

AssignBackgroundColor(if close > ((SuperAlertWhenPercentAboveSMA+1) * sma)
                      then GlobalColor("SuperAbove") else if close > ((AlertWhenPercentAboveSMA+1) * sma) then GlobalColor("Above")
                      else if close < SuperSMA then GlobalColor("SuperBelow") else if close < SMA then GlobalColor("Below") else GlobalColor("default"));

If price is 5% above the 20 sma chart changes to dark green
If price is 10% above the 20 sma chart changes to bright green
If price is below the 20 sma chart changes to dark red
If price is below the 50 sma chart changes to bright red

Example in action:
uT1aOE0.png
 

MichDopo

New member
Awesome guys, thanks for all your help. I'm sure happy with this code, which I have completed:

Code:
#ChartAlert_SMA
#EvanEvans
#V1.0

input aggregationPeriod = AggregationPeriod.DAY;
input SMAPeriod = 20;
input SuperSMAPeriod = 50;
input averageType = AverageType.SIMPLE;
input AlertWhenPercentAboveSMA = 0.050;
input SuperAlertWhenPercentAboveSMA = 0.100;

def c = close(period = aggregationPeriod);
def sma = movingaverage(averageType,c,SMAperiod);
def SuperSMA = movingaverage(averageType,c,SuperSMAperiod);

DefineGlobalColor("SuperAbove",Color.Green);
DefineGlobalColor("Above",Color.Dark_Green);
DefineGlobalColor("Below",Color.Dark_Red);
DefineGlobalColor("SuperBelow",Color.Red);
DefineGlobalColor("default",Color.Current);

AssignBackgroundColor(if close > ((SuperAlertWhenPercentAboveSMA+1) * sma)
                      then GlobalColor("SuperAbove") else if close > ((AlertWhenPercentAboveSMA+1) * sma) then GlobalColor("Above")
                      else if close < SuperSMA then GlobalColor("SuperBelow") else if close < SMA then GlobalColor("Below") else GlobalColor("default"));

If price is 5% above the 20 sma chart changes to dark green
If price is 10% above the 20 sma chart changes to bright green
If price is below the 20 sma chart changes to dark red
If price is below the 50 sma chart changes to bright red

Example in action:
uT1aOE0.png
To change this from SMA to EMA, what would be the change required?
 

Nari2007

Member
Can the background color of a chart be changed under conditions of a ThinkScript? Or perhaps a full window cloud? It would be great to be able to do this, so I could know which of 100s of charts I monitor simultaneously all day, need my attention.

Something like this:

SJhgVT4.png


I want to create a ThinkScript that can color the background of the whole chart under a particular current condition. I already got this far:

AFyqxt3.png
how do i use this, i really want to give it a try. can i have the colors change just at the cross overs not at percentages as that ,makes it harder for me to understand,,,i daytrade, 15mins is the higher time frame maybe go up to a hour, so what should i set this aggregation period be? i use 3 min as entry and 15 mins as my ht
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
how do i use this, i really want to give it a try. can i have the colors change just at the cross overs not at percentages as that ,makes it harder for me to understand,,,i daytrade, 15mins is the higher time frame maybe go up to a hour, so what should i set this aggregation period be? i use 3 min as entry and 15 mins as my ht
If you want to trigger for entry then the aggregation period would be 3min.
 

Similar threads

Top