Chart label for AdvanceDeclineCumulativeAvg status


Category:
0
0

Hi, i have the original code for the Advanced Decline Cumulative Average study on TOS. However, i will like to add a label to the upper study charts to indicate that the lines have crossed above or below. Is it possible? Thanks for your help

The code is as below

declare lower;

input exchange = {default NYSE, NASDAQ, AMEX};
input length = 252;

def advnDecnPctChg = 1000 * AdvanceDecline(type = “Advance/Decline Line (Daily)”, exchange = exchange);
def cumAdvnDecn = cumAdvnDecn[1] + if !IsNaN(advnDecnPctChg) then advnDecnPctChg else 0;

plot CumulAD = if !IsNaN(advnDecnPctChg) then cumAdvnDecn else Double.NaN;
plot AvgCumulAD = if !IsNaN(close) then Sum(if !IsNaN(CumulAD) then CumulAD else 0, length) / Sum(if !IsNaN(CumulAD) then 1 else 0, length) else Double.NaN;

CumulAD.DefineColor(“Above”, Color.UPTICK);
CumulAD.DefineColor(“Below”, Color.DOWNTICK);
CumulAD.AssignValueColor(if CumulAD > AvgCumulAD then CumulAD.Color(“Above”) else CumulAD.Color(“Below”));
AvgCumulAD.SetDefaultColor(GetColor(7));

 

 

 

 

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on November 18, 2022 9:40 pm
87 views
0
Private answer

The following solution places a chart label in the upper left corner of the chart. The label changes color to show whether the signal line is above or below the average.

input exchange = {default NYSE, NASDAQ, AMEX};
input length = 252;
def advnDecnPctChg = 1000 * AdvanceDecline(type = “Advance/Decline Line (Daily)”, exchange = exchange);
def cumAdvnDecn = cumAdvnDecn[1] + if !IsNaN(advnDecnPctChg) then advnDecnPctChg else 0;
def CumulAD = if !IsNaN(advnDecnPctChg) then cumAdvnDecn else Double.NaN;
def AvgCumulAD = if !IsNaN(close) then Sum(if !IsNaN(CumulAD) then CumulAD else 0, length) / Sum(if !IsNaN(CumulAD) then 1 else 0, length) else Double.NaN;
AddLabel(yes, "ADCA Status", if CumulAD > AvgCumulAD then Color.GREEN else Color.RED);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 19, 2022 1:15 pm
0
Hi Pete, the label works. i can also add the labels into the watchlist. I really appreciate your help. Thank You. Happy Sunday
( at November 20, 2022 1:13 am)
0
Hi Pete It seems that the label stopped working suddenly. If i click on a symbol that closes the day before, the labels will appear. If i click on a symbol that is live, as in futures symbols, the label will become black. I am thinking is this the same issue as you mentioned to me regarding the candles not being aligned with regards to the yield curve. https://www.hahn-tech.com/ans/yield-curve-label-fails-if-chart-symbol-is-changed/
( at November 25, 2022 5:18 am)
0
This is an entirely different issue. It is related to trying to read data from a today's regular session during the premarket. Which will never work. For futures contracts, this label can only be used on a chart during the regular session hours.
( at November 25, 2022 9:10 am)
0
Noted. Thanks a lot. I also realise the data is actually weekly which may explain why the data wont load on certain charts
( at November 28, 2022 6:25 am)