Yield curve label fails if chart symbol is changed


Category:
0
0

Hi Pete, i will like to create a label for yield curve using information from FRED. TOS allows us to input data from FRED and see their charts. Hence i have created a yield curve label. It actually works. But the issue is when the chart is showing another symbol e.g. SPY, the label will indicate N.A.

It seems the label will only display the right data when it is at the symbol from FRED. What do u think is wrong with my code? Thanks

Here is my code
input symbol3 = “DGS3MO:FRED”;
input symbol4 = “DGS10:FRED”;
def t1 = close(symbol3, period = AggregationPeriod.DAY);
def t2 = close(symbol4, period = AggregationPeriod.DAY);
def t3 = t2 – t1;

AddLabel(yes, Concat(“Yield Curve:”, (t3)), Color.VIOLET);

RESOLVED
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on November 24, 2022 9:15 am
7 views
0
Private answer

The symptom you describe is most commonly associated with a mismatch between the source data and the data for the symbol you have loaded on the chart. So that's where I began my investigation. Sure enough, we find the data for symbols "DGS3MO:FRED" and "DGS10:FRED" are posted one day behind the rest of the market. Since the data for those symbols is always one day behind, there is no data available for the current day.

How did I work this out? I loaded one of those ticker symbols on a daily chart. Then I loaded a regular stock ticker on another daily chart. The stock ticker shows the last candle on the chart is dated 11/23/22. However the chart for the "DGS3MO:FRED" ticker symbol shows the last candle on the chart is dated 11/22/22.

Your code is referencing the current bar. And when you try to read the current value for 11/23/22, ticker symbol "DGS3MO:FRED" has no data there to be read. So the label correctly reports N/A instead of a value.

The easiest solution is to update your code to read from the previous daily bar instead of the current. However this solution will now only report the correct value when you have loaded a stock, futures, or forex symbol on the chart.

input symbolOne = "DGS3MO:FRED";
input symbolTwo = "DGS10:FRED";
def yieldOne = close(symbolOne, period = AggregationPeriod.DAY);
def yieldTwo = close(symbolTwo, period = AggregationPeriod.DAY);
def yieldCurve = yieldTwo - yieldOne;
AddLabel(yes, Concat("Yield Curve:", (yieldCurve[1])), Color.VIOLET);

Notice I have also cleaned up the code to provide a more appropriate method for naming variables.

Marked as spam
Posted by (Questions: 37, Answers: 3932)
Answered on November 24, 2022 9:48 am
Ah...u added a "1".If u added a "2" it will be the last second candle. I understand now. Thanks a lot. Happy Thanksgiving
( at November 24, 2022 7:35 pm)