Charlotte NC
Experience: Advanced
Platform: Charts:TOS, execution:TOS
Broker: TOS
Trading: SPX, RUT. TQQQ, Stocks, /YM
Posts: 234 since Jul 2009
Thanks Given: 99
Thanks Received: 122
|
This code will plot different years of price action in the same screen using EOD data. This is an approximation. f you find a way to make the data more accurate please post.
plot LastYear = close[252];
plot TwoYearsAgo = close [2 * 252];
plot ThreeYearsAgo = close [3 * 252];
plot FourYearsAgo = close [4 *252];
plot FiveYearsAgo = close [5 * 252];
plot CombinedAvg = (LastYear + TwoYearsAgo +ThreeYearsAgo + fourYearsAgo + fiveYearsAgo) / 5;
CombinedAvg.SetDefaultColor(color.LIME);
def today = GetLastDay() == GetDay();
AddChartBubble(today, LastYear, "LY", Color.white);
AddChartBubble(today, TwoYearsAgo, "2Ya", Color.white);
AddChartBubble(today, ThreeYearsAgo, "3Ya", Color.white);
AddChartBubble(today, FourYearsAgo, "4Ya", Color.white);
AddChartBubble(today, FiveYearsAgo, "5Ya", Color.white);
To make it easier to read I run same idea with a 5 day SMA instead of EOD prices. I hope it helps.
input AvgLength = 5;
plot ThisYear = Average(close, AvgLength);
ThisYear.SetDefaultColor(Color.WHITE);
plot LastYear = Average(close[252], AvgLength);
LastYear.SetDefaultColor(Color.CYAN);
plot TwoYearsAgo = Average(close[2 * 252], AvgLength);
TwoYearsAgo.SetDefaultColor(Color.PINK);
plot ThreeYearsAgo = Average(close[3 * 252], AvgLength);
ThreeYearsAgo.SetDefaultColor(Color.LIGHT_GRAY);
plot FourYearsAgo = Average(close[4 * 252], AvgLength);
FourYearsAgo.SetDefaultColor(Color.YELLOW);
plot FiveYearsAgo = Average(close[5 * 252], AvgLength);
TwoYearsAgo.SetDefaultColor(Color.RED);
plot CombinedAvg = ( LastYear + TwoYearsAgo +ThreeYearsAgo + fourYearsAgo + fiveYearsAgo) / 5;
CombinedAvg.SetDefaultColor(color.LIME);
def today = GetLastDay() == GetDay();
AddChartBubble(today, CombinedAvg, "Avg", Color.LIME);
AddChartBubble(today, LastYear, "LY", Color.white);
AddChartBubble(today, TwoYearsAgo, "2Ya", Color.white);
AddChartBubble(today, ThreeYearsAgo, "3Ya", Color.white);
AddChartBubble(today, FourYearsAgo, "4Ya", Color.white);
AddChartBubble(today, FiveYearsAgo, "5Ya", Color.white);
|