P/C Ratio label


Hello Pete,

How do I display a chart label in TOS for symbol $PCALL as of current period along with value of 10 day SMA. Also make the label color green is the value is below 0.8 and color gray if the value is between 0.8 to 1 and color red if value is above 1.0.

So label should look something like “P/C Ratio = 0.92 / 10 Day Avg : 0.95” along with its color based on 10 Day Avg.

Thank you

Marked as spam
Posted by (Questions: 6, Answers: 5)
Asked on August 23, 2019 6:57 am
Private answer

I think this should do it. You didn't make it clear that the value you wanted was the P/C ratio divided by the sma of the P/C ratio. So I took a guess that is what you wanted and wrote the code accordingly.

As to your request for: "...along with its color based on 10 Day Avg..." This is for any time frame you want to select for the chart. The values are NOT based on daily time frame. They will change as you select a different time frame for the chart. So if you truly want the 10 day average of the P/C ratio you will need to set the chart to a daily time frame.

I shortened the text in the labels and rounded the values to nearest 10th to reduce the size of the label.

def pcClose = close(symbol = "$PCALL");
def pcSMA = Average(pcClose, 10);
def value = pcClose / pcSMA;
AddLabel(yes, Concat(Concat(Concat("P/C: ", Round(pcClose, 2)), " SMA: "), Round(pcSMA, 2)), if value > 1.0 then Color.RED else if value > 0.8 then Color.GRAY else Color.GREEN);

Marked as spam
Posted by (Questions: 36, Answers: 2022)
Answered on August 23, 2019 9:31 am