I'm trying to get the last value of a weighted moving average on a daily chart. I would like the last value to be represented graphically by a horizontal bar starting on the last day of the chart and then extending right.
The code below gives me an orange line for each day, but I want only the value of the last day.
# Define input parameters
input length = 20;
# Calculate moving average
plot ma = MovAvgWeighted(close, length);
# Get the last value of the moving average
def lastMAValue = GetValue(ma, 0);
# Plot the last value as a horizontal line
plot lastMAPlot = lastMAValue;
lastMAPlot.SetDefaultColor(Color.ORANGE);
lastMAPlot.SetLineWeight(2);
lastMAPlot.SetStyle(Curve.FIRM);
lastMAPlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Thanks for any suggestions.
The code below gives me an orange line for each day, but I want only the value of the last day.
# Define input parameters
input length = 20;
# Calculate moving average
plot ma = MovAvgWeighted(close, length);
# Get the last value of the moving average
def lastMAValue = GetValue(ma, 0);
# Plot the last value as a horizontal line
plot lastMAPlot = lastMAValue;
lastMAPlot.SetDefaultColor(Color.ORANGE);
lastMAPlot.SetLineWeight(2);
lastMAPlot.SetStyle(Curve.FIRM);
lastMAPlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Thanks for any suggestions.