Multiple % change chart labels


Category:
0
0

Hello Room, Hello Pete

I trying to convert this script from a trend indicator to a daily percent gainer to plot the Symbol, the price & the % change from the last close onto the chart. With this script, users can plug in multiple ticker symbols they want to watch and have the % change labels update (red/green) in real-time whether it be indices, stock or futures. What line of code would I add to make this possible?

declare lower;

input TLT_Trend_Length = 5;
def TLT = close(“TLT” );
def TLTtrend= Average(TLT[1], 1);
AddLabel(TLT > TLTtrend, “TLT: ” + Round(TLT, 2), Color.DARK_GREEN);
AddLabel(TLT <= TLTtrend, “TLT: ” + Round(TLT, 2), Color.RED);

input FXY_Trend_Length = 5;
def FXY = close(“FXY” );
def FXYtrend = Average(FXY[1], 1);
AddLabel(FXY > FXYtrend, “FXY: ” + Round(FXY, 2), Color.DARK_GREEN);
AddLabel(FXY <= FXYtrend, “FXY: ” + Round(FXY, 2), Color.RED);

input GLD_Trend_Length = 5;
def GLD = close(“GLD” );
def GLDtrend = Average(GLD[1], 1);
AddLabel(GLD> GLDtrend, “GLD: ” + Round(GLD, 2), Color.DARK_GREEN);
AddLabel(GLD <= GLDtrend, “GLD: ” + Round(GLD, 2), Color.RED);

input DIA_Trend_Length = 5;
def DIA = close(“DIA” );
def DIAtrend = Average(DIA[1], 1);
AddLabel(DIA > DIAtrend, “DIA: ” + Round(DIA, 2), Color.DARK_GREEN);
AddLabel(DIA <= DIAtrend, “DIA: ” + Round(DIA, 2), Color.RED);

input SPY_Trend_Length = 5;
def SPY = close(“SPY” );
def SPYtrend = Average(SPY[1], 1);
AddLabel(SPY > SPYtrend, “SPY: ” + Round(SPY, 2), Color.DARK_GREEN);
AddLabel(SPY <= SPYtrend, “SPY: ” + Round(SPY, 2), Color.RED);

input QQQ_Trend_Length = 5;
def QQQ = close(“QQQ” );
def QQQtrend = Average(QQQ[1], 1);
AddLabel(QQQ > QQQtrend, “QQQ: ” + Round(QQQ, 2), Color.DARK_GREEN);
AddLabel(QQQ <= QQQtrend, “QQQ: ” + Round(QQQ, 2), Color.RED);

input IWM_Trend_Length = 5;
def IWM = close(“IWM” );
def IWMtrend = Average(IWM[1], 1);
AddLabel(IWM > IWMtrend, “IWM: ” + Round(IWM, 2), Color.DARK_GREEN);
AddLabel(IWM <= IWMtrend, “IWM: ” + Round(IWM, 2), Color.RED);

 

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on June 30, 2018 1:39 pm
188 views
0
Private answer

This has already been asked and answered. Be sure to view the four links I provide in answering this post: https://www.hahn-tech.com/ans/add-chart-label-to-display-price-price-change-of-price-change-days-atr/

The very last of the four links will show how to display daily change for alternate ticker symbols. After viewing all four posts that are linked, you should be able to complete your request. Not to mention you will have new ideas on how to apply chart labels.

I am editing my answer to provide the full solution based on feedback recieved

I will take the code from this post: https://www.hahn-tech.com/ans/label-color-change-as-current-price-fluctuates/ and just replicate it over and over. Changing the symbol each time. The only thing to add is a computation for percent change:
def prctChng1 = Round(100 * (close(symbol = SYMB1)[1] / close(symbol = SYMB1) - 1), 1);

Notice it is rounded to the nearest 10th to remove excess digits.

Here is a fully functional example that includes 2 symbols. You can add as many symbols and labels as you like. Just follow the pattern of renaming input and variable names. Got that? So input SYMB1 gets replicated to input SYMB2. Likewise def AD1 gets replicated to def AD2. Finally, def prctChng1 gets replicated to def prctChng2

Here is the full code that includes two symbols:

input SYMB1 = “RUT”;
input SYMB2 = "SPX";
def AD1 = close (symbol = SYMB1);
def AD2 = close (symbol = SYMB2);
def prctChng1 = Round(100 * (close(symbol = SYMB1)[1] / close(symbol = SYMB1) - 1), 1);
def prctChng2 =Round(100 * (close(symbol = SYMB2)[1] / close(symbol = SYMB2) - 1), 1);
AddLabel(yes, SYMB1 + ": " + AD1 + ”: ” + prctChng1 + "%", if AD1 < AD1[1] then Color.RED else Color.GREEN);
AddLabel(yes, SYMB2 + ": " + AD2 + ”: ” + prctChng2 + "%", if AD2 < AD2[1] then Color.RED else Color.GREEN);

That should get you well on your way.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on June 30, 2018 3:06 pm
0

Yeah, I actually found this before I posted the question. It doesn’t show how to add the percent change to multiple symbol(s). No worries. I have other contacts who know Thinkscript well who can help me.

( at July 2, 2018 8:20 am)
0

Yeah, well that is super easy to do. Sorry I thought you were the one that wrote the code you posted in your question. From that I expected you were just trying to learn how to do this. I will update my answer to include the full solution.

( at July 2, 2018 9:04 am)