I am trying to write a simple indicator that automatically draws the midpoint for either the previous bar or the current bar. I see the correct plot bubble, but no plot. What am I missing / doing wrong? TIA for the help!
# Automatically draws the midpoint for either the previous bar or the current bar
#declare once_per_bar;
input Mode = {default Current, Previous};
def barNumber = barNumber();
def mostRecentBarIndex = HighestAll(if(close > 0, barNumber(), Double.NaN));
def plotBarNumber;
def barOpen;
def barHigh;
def barLow;
def barClose;
# Please pick only one approach at a time in order to avoid compiler errors...
# Approach 1: displays OHLC in the label for Current and Previous and the plot bubble for each, but no plot!
if(barNumber == mostRecentBarIndex)
{
switch (Mode)
{
case Current:
plotBarNumber = barNumber;
barOpen = open;
barHigh = high;
barLow = low;
barClose = close;
case Previous:
plotBarNumber = barNumber - 1;
barOpen = open[1];
barHigh = high[1];
barLow = low[1];
barClose = close[1];
}
}
else
{
plotBarNumber = Double.NaN;
barOpen = Double.NaN;
barHigh = Double.NaN;
barLow = Double.NaN;
barClose = Double.NaN;
}
# Approach 2: displays OHLC in the label for Current but not Previous (as expected) and the plot bubble for each, but no plot!
if(((Mode == Mode.Current) AND (barNumber == mostRecentBarIndex)) OR ((Mode == Mode.Previous) AND (barNumber == mostRecentBarIndex - 1)))
{
plotBarNumber = barNumber;
barOpen = open;
barHigh = high;
barLow = low;
barClose = close;
}
else
{
plotBarNumber = Double.NaN;
barOpen = Double.NaN;
barHigh = Double.NaN;
barLow = Double.NaN;
barClose = Double.NaN;
}
Plot mid = (barHigh + barLow) / 2;
mid.AssignValueColor(Color.Cyan);
mid.SetLineWeight(2);
mid.SetPaintingStrategy(PaintingStrategy.LINE);
mid.SetStyle(Curve.MEDIUM_DASH);
AddLabel(yes, "Mode: " + Mode + ", mostRecentBarIndex: " + mostRecentBarIndex + ", barNumber: " + barNumber + ", plotBarNumber: " + plotBarNumber + ", barOpen: " + barOpen + ", barHigh: " + barHigh + ", barLow: " + barLow + ", barClose: " + barClose + ", mid: " + mid, Color.LIGHT_GREEN);
# Automatically draws the midpoint for either the previous bar or the current bar
#declare once_per_bar;
input Mode = {default Current, Previous};
def barNumber = barNumber();
def mostRecentBarIndex = HighestAll(if(close > 0, barNumber(), Double.NaN));
def plotBarNumber;
def barOpen;
def barHigh;
def barLow;
def barClose;
# Please pick only one approach at a time in order to avoid compiler errors...
# Approach 1: displays OHLC in the label for Current and Previous and the plot bubble for each, but no plot!
if(barNumber == mostRecentBarIndex)
{
switch (Mode)
{
case Current:
plotBarNumber = barNumber;
barOpen = open;
barHigh = high;
barLow = low;
barClose = close;
case Previous:
plotBarNumber = barNumber - 1;
barOpen = open[1];
barHigh = high[1];
barLow = low[1];
barClose = close[1];
}
}
else
{
plotBarNumber = Double.NaN;
barOpen = Double.NaN;
barHigh = Double.NaN;
barLow = Double.NaN;
barClose = Double.NaN;
}
# Approach 2: displays OHLC in the label for Current but not Previous (as expected) and the plot bubble for each, but no plot!
if(((Mode == Mode.Current) AND (barNumber == mostRecentBarIndex)) OR ((Mode == Mode.Previous) AND (barNumber == mostRecentBarIndex - 1)))
{
plotBarNumber = barNumber;
barOpen = open;
barHigh = high;
barLow = low;
barClose = close;
}
else
{
plotBarNumber = Double.NaN;
barOpen = Double.NaN;
barHigh = Double.NaN;
barLow = Double.NaN;
barClose = Double.NaN;
}
Plot mid = (barHigh + barLow) / 2;
mid.AssignValueColor(Color.Cyan);
mid.SetLineWeight(2);
mid.SetPaintingStrategy(PaintingStrategy.LINE);
mid.SetStyle(Curve.MEDIUM_DASH);
AddLabel(yes, "Mode: " + Mode + ", mostRecentBarIndex: " + mostRecentBarIndex + ", barNumber: " + barNumber + ", plotBarNumber: " + plotBarNumber + ", barOpen: " + barOpen + ", barHigh: " + barHigh + ", barLow: " + barLow + ", barClose: " + barClose + ", mid: " + mid, Color.LIGHT_GREEN);