I have built an indicator when a candle changes trend. The plots work fairly well.
I am looking to have the lines extend all the way to the end of the chart and then have the lines stop or go dashed when a candle closes through (not on wicks) preferably a toggle if possible. Thanks in advance!
# Aggregation period for weekly levels
input aggPeriod = AggregationPeriod.WEEK;
# Define high, low, and close for the weekly timeframe
def weekOpen = open(period = aggPeriod);
def weekHigh = high(period = aggPeriod);
def weekLow = low(period = aggPeriod);
def weekClose = close(period = aggPeriod);
# Trend change conditions on the weekly timeframe
def weekDownToUp = weekClose > weekOpen and weekClose[1] < weekOpen[1];
def weekUpToDown = weekClose < weekOpen and weekClose[1] > weekOpen[1];
# Persistent Down-to-Up levels (extend until invalidated on the weekly timeframe)
rec weekDownToUpLevel1 =
if weekDownToUp then weekOpen
else if weekClose[1] <= weekDownToUpLevel1[1] then weekDownToUpLevel1[1]
else weekDownToUpLevel1[1];
rec weekDownToUpLevel2 =
if weekDownToUp and weekClose[1] <= weekDownToUpLevel1 then weekOpen
else if weekClose[1] <= weekDownToUpLevel2[1] then weekDownToUpLevel2[1]
else weekDownToUpLevel2[1];
rec weekDownToUpLevel3 =
if weekDownToUp and weekClose[1] <= weekDownToUpLevel2 then weekOpen
else if weekClose[1] <= weekDownToUpLevel3[1] then weekDownToUpLevel3[1]
else weekDownToUpLevel3[1];
# Persistent Up-to-Down levels (extend until invalidated on the weekly timeframe)
rec weekUpToDownLevel1 =
if weekUpToDown then weekOpen
else if weekClose[1] >= weekUpToDownLevel1[1] then weekUpToDownLevel1[1]
else weekUpToDownLevel1[1];
rec weekUpToDownLevel2 =
if weekUpToDown and weekClose[1] >= weekUpToDownLevel1 then weekOpen
else if weekClose[1] >= weekUpToDownLevel2[1] then weekUpToDownLevel2[1]
else weekUpToDownLevel2[1];
rec weekUpToDownLevel3 =
if weekUpToDown and weekClose[1] >= weekUpToDownLevel2 then weekOpen
else if weekClose[1] >= weekUpToDownLevel3[1] then weekUpToDownLevel3[1]
else weekUpToDownLevel3[1];
# Plot Down-to-Up levels
plot weekDownToUpPlot1 = weekDownToUpLevel1;
weekDownToUpPlot1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekDownToUpPlot1.SetDefaultColor(Color.GREEN);
plot weekDownToUpPlot2 = weekDownToUpLevel2;
weekDownToUpPlot2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekDownToUpPlot2.SetDefaultColor(Color.LIGHT_GREEN);
plot weekDownToUpPlot3 = weekDownToUpLevel3;
weekDownToUpPlot3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekDownToUpPlot3.SetDefaultColor(Color.DARK_GREEN);
# Plot Up-to-Down levels
plot weekUpToDownPlot1 = weekUpToDownLevel1;
weekUpToDownPlot1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekUpToDownPlot1.SetDefaultColor(Color.RED);
plot weekUpToDownPlot2 = weekUpToDownLevel2;
weekUpToDownPlot2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekUpToDownPlot2.SetDefaultColor(Color.PINK);
plot weekUpToDownPlot3 = weekUpToDownLevel3;
weekUpToDownPlot3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekUpToDownPlot3.SetDefaultColor(Color.DARK_RED);
I am looking to have the lines extend all the way to the end of the chart and then have the lines stop or go dashed when a candle closes through (not on wicks) preferably a toggle if possible. Thanks in advance!
# Aggregation period for weekly levels
input aggPeriod = AggregationPeriod.WEEK;
# Define high, low, and close for the weekly timeframe
def weekOpen = open(period = aggPeriod);
def weekHigh = high(period = aggPeriod);
def weekLow = low(period = aggPeriod);
def weekClose = close(period = aggPeriod);
# Trend change conditions on the weekly timeframe
def weekDownToUp = weekClose > weekOpen and weekClose[1] < weekOpen[1];
def weekUpToDown = weekClose < weekOpen and weekClose[1] > weekOpen[1];
# Persistent Down-to-Up levels (extend until invalidated on the weekly timeframe)
rec weekDownToUpLevel1 =
if weekDownToUp then weekOpen
else if weekClose[1] <= weekDownToUpLevel1[1] then weekDownToUpLevel1[1]
else weekDownToUpLevel1[1];
rec weekDownToUpLevel2 =
if weekDownToUp and weekClose[1] <= weekDownToUpLevel1 then weekOpen
else if weekClose[1] <= weekDownToUpLevel2[1] then weekDownToUpLevel2[1]
else weekDownToUpLevel2[1];
rec weekDownToUpLevel3 =
if weekDownToUp and weekClose[1] <= weekDownToUpLevel2 then weekOpen
else if weekClose[1] <= weekDownToUpLevel3[1] then weekDownToUpLevel3[1]
else weekDownToUpLevel3[1];
# Persistent Up-to-Down levels (extend until invalidated on the weekly timeframe)
rec weekUpToDownLevel1 =
if weekUpToDown then weekOpen
else if weekClose[1] >= weekUpToDownLevel1[1] then weekUpToDownLevel1[1]
else weekUpToDownLevel1[1];
rec weekUpToDownLevel2 =
if weekUpToDown and weekClose[1] >= weekUpToDownLevel1 then weekOpen
else if weekClose[1] >= weekUpToDownLevel2[1] then weekUpToDownLevel2[1]
else weekUpToDownLevel2[1];
rec weekUpToDownLevel3 =
if weekUpToDown and weekClose[1] >= weekUpToDownLevel2 then weekOpen
else if weekClose[1] >= weekUpToDownLevel3[1] then weekUpToDownLevel3[1]
else weekUpToDownLevel3[1];
# Plot Down-to-Up levels
plot weekDownToUpPlot1 = weekDownToUpLevel1;
weekDownToUpPlot1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekDownToUpPlot1.SetDefaultColor(Color.GREEN);
plot weekDownToUpPlot2 = weekDownToUpLevel2;
weekDownToUpPlot2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekDownToUpPlot2.SetDefaultColor(Color.LIGHT_GREEN);
plot weekDownToUpPlot3 = weekDownToUpLevel3;
weekDownToUpPlot3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekDownToUpPlot3.SetDefaultColor(Color.DARK_GREEN);
# Plot Up-to-Down levels
plot weekUpToDownPlot1 = weekUpToDownLevel1;
weekUpToDownPlot1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekUpToDownPlot1.SetDefaultColor(Color.RED);
plot weekUpToDownPlot2 = weekUpToDownLevel2;
weekUpToDownPlot2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekUpToDownPlot2.SetDefaultColor(Color.PINK);
plot weekUpToDownPlot3 = weekUpToDownLevel3;
weekUpToDownPlot3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
weekUpToDownPlot3.SetDefaultColor(Color.DARK_RED);