// Compute the Average Line averageLine = (linRegForecast + tma) / 2
// Compute Stochastic (8,4,4) k = ta.sma(ta.stoch(close, high, low, stoch_k), stoch_smooth) d = ta.sma(k, stoch_d)
// Track last confirmed Stochastic crossovers var float lastBuyCrossover = na var float lastSellCrossover = na
if ta.crossover(k, d) and k < 30 lastBuyCrossover := bar_index // Store the bar index of last Buy crossover below 30
if ta.crossunder(k, d) and k > 70 lastSellCrossover := bar_index // Store the bar index of last Sell crossover above 70
// Define Buy & Sell Signal Conditions with Confirmation buySignal = ta.crossover(linRegForecast, tma) and lastBuyCrossover > lastSellCrossover sellSignal = ta.crossunder(linRegForecast, tma) and lastSellCrossover > lastBuyCrossover
// Plot the indicators plot(linRegForecast, color=color.blue, title="Linear Regression Forecast") plot(tma, color=color.green, title="Triangular Moving Average (TMA)") plot(averageLine, color=color.white, title="Average Line", linewidth=2) // White Average Line