I have the following code, but I would like the green/red horizontal lines extended all the way to the end of the chart for the whole day.
Played along with the plot condition, but it just messes up the chart. Thanks
Image example, see arrows:
Played along with the plot condition, but it just messes up the chart. Thanks
Image example, see arrows:
Code:
# | define a peak and plot it
input magnitude = 5;
def peak = high > Highest(high[1], magnitude) and high >= Highest(high[-magnitude], magnitude);
def peakValue = if peak then high else peakValue[1];
plot peakLine = peakValue;
peakLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
peakLine.SetDefaultColor(Color.green);
# | get the bar numbers for the most recent close
# | and the most recent peak
def lastBar = HighestAll(if IsNaN(close) then 0 else BarNumber());
def peakBar = if peak then BarNumber() else Double.NaN;
# | find the values of the most recent peak and the one before it
def lastPeakValue = GetValue(high, BarNumber() - HighestAll(peakBar));
def prevPeakValue = GetValue(peakValue[1], BarNumber() - HighestAll(peakBar));
# | find the value of the most recent close
def mostRecentClose = HighestAll(if BarNumber() == lastBar then close else 0);
# | define what is considered to be "in range" of the previous peak
input percent = 0.5;
def inRange = mostRecentClose > (prevPeakValue * (1 - percent / 100)) and mostRecentClose < (prevPeakValue * (1 + percent / 100));
# | extend the most recent peak
plot lastPeakExtension = if BarNumber() >= HighestAll(peakBar) then lastPeakValue else Double.NaN;
lastPeakExtension.SetDefaultColor(Color.light_green);
# | extend the previous peak only if the most recent close value is "in range"
plot prevPeakExtension = if BarNumber() >= HighestAll(peakBar) - 1 then prevPeakValue else Double.NaN;
prevPeakExtension.SetDefaultColor(Color.Dark_Orange);
prevPeakExtension.SetHiding(!inRange);
# | define a valley and plot it
def valley = low < lowest(low[1], magnitude) and low <= lowest(low[-magnitude], magnitude);
def valleyValue = if valley then low else valleyValue[1];
plot valleyLine = valleyValue;
valleyLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
valleyLine.SetDefaultColor(Color.red);
# | get the bar numbers for the most recent close
# | and the most recent valley
def valleyBar = if valley then BarNumber() else Double.NaN;
# | find the values of the most recent peak and the one before it
def lastvalleyValue = GetValue(low, BarNumber() - lowestAll(valleyBar));
def prevvalleyValue = GetValue(valleyValue[1], BarNumber() - lowestAll(valleyBar));
Last edited: