|
Josh McCormick
2020-11-24 17:21:11
|
|
I'm banging my head against the wall on this one. I'm wanting to average the current symbol's closing price over the past six years. But to start, I'm just trying to plot the current closing price, the previous year's closing price, and so on. But I can't seem to come up with the function which says, "take the current date, subtract a year, and plot the close on that date". How should I be coding this?
// Plots the stock price of the current year and the past five years.
Y0_close=close;
Y1_close=ValueOn (close,Day(),Month(),Year()-1);
Y2_close=ValueOn (close,Day(),Month(),Year()-2);
Y3_close=ValueOn (close,Day(),Month(),Year()-3);
Y4_close=ValueOn (close,Day(),Month(),Year()-4);
Y5_close=valuewhen(stringequal(date(), month()."/".day()."/".year()-5), close);
Plot (Y0_close,"Year 0",colorBlack,ChartSmoothLine,StyleWidth2);
Plot (Y1_close,"Year -1",colorRed,ChartSmoothLine,StyleWidth2);
Plot (Y2_close,"Year -2",colorOrange,ChartSmoothLine,StyleWidth2);
Plot (Y3_close,"Year -3",colorGreen,ChartSmoothLine,StyleWidth2);
Plot (Y4_close,"Year -4",colorBlue,ChartSmoothLine,StyleWidth2);
Plot (Y5_close,"Year -5",colorViolet,ChartSmoothLine,StyleWidth2);
|
|