Can you please help here.
1. Can you add MTF capability.
2. Can you add green vertical line for bull ( SlowK > 50 && RSI > 50 && MACD > 0 ) and red vertical lines for bear (SlowK > 50 && RSI > 50 && MACD > 0), giving me an option to limit number of lines to be shown.
Thanks in advance
Try this. Not 100% sure if this is what you had in mind but to do a MTF option I am not sure that is possible. This allows HTF
# === Inputs ===
input useMTF = yes;
input higherTF = AggregationPeriod.HOUR;
input rsiLength = 14;
input slowKLength = 14;
input slowDLength = 3;
input macdFastLength = 12;
input macdSlowLength = 26;
input macdSignalLength = 9;
input maxLines = 10;
input showArrows = yes;
input showLabels = yes;
# === MTF Source Selection ===
def priceClose = if useMTF then close(period = higherTF) else close;
def priceHigh = if useMTF then high(period = higherTF) else high;
def priceLow = if useMTF then low(period = higherTF) else low;
# === RSI ===
def rsi = RSI(rsiLength, priceClose);
# === Stochastic FullK ===
def fullK = reference StochasticFull(
overbought = 80, oversold = 20,
KPeriod = slowKLength, DPeriod = slowDLength,
priceH = priceHigh, priceL = priceLow, priceC = priceClose,
slowingPeriod = slowDLength, averageType = AverageType.SIMPLE
).FullK;
# === Manual MACD Calculation ===
def macdFast = ExpAverage(priceClose, macdFastLength);
def macdSlow = ExpAverage(priceClose, macdSlowLength);
def macdValue = macdFast - macdSlow;
# === Signal Logic ===
def bull = fullK > 50 and rsi > 50 and macdValue > 0;
def bear = fullK < 50 and rsi < 50 and macdValue < 0;
def neutral = !bull and !bear;
# === Candle Coloring ===
AssignPriceColor(
if bull then Color.GREEN
else if bear then Color.RED
else Color.YELLOW
);
# === Vertical Line Drawing with Limit ===
def signal = bull or bear;
def barCounter = if signal then barCounter[1] + 1 else barCounter[1];
def lastN = HighestAll(barCounter);
def showLine = barCounter >= lastN - maxLines;
AddVerticalLine(bull and showLine, "BULL", Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(bear and showLine, "BEAR", Color.RED, Curve.SHORT_DASH);
# === Arrows (optional) ===
plot bullArrow = if showArrows and bull and showLine then low - TickSize() * 5 else Double.NaN;
bullArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
bullArrow.SetDefaultColor(Color.GREEN);
bullArrow.SetLineWeight(2);
plot bearArrow = if showArrows and bear and showLine then high + TickSize() * 5 else Double.NaN;
bearArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
bearArrow.SetDefaultColor(Color.RED);
bearArrow.SetLineWeight(2);
# === Summary Label ===
AddLabel(showLabels,
if bull then "Trend: BULLISH"
else if bear then "Trend: BEARISH"
else "Trend: NEUTRAL",
if bull then Color.GREEN else if bear then Color.RED else Color.GRAY
);
# === Alerts ===
Alert(bull, "BULLISH Condition Triggered", Alert.BAR, Sound.Chimes);
Alert(bear, "BEARISH Condition Triggered", Alert.BAR, Sound.Bell);