//@version=5 indicator("Power Trend Indicator V1.0", overlay=true) length1 = 21 length2 = 50 recentHigh = ta.highest(close, 100) ema1 = ta.ema(close, length1) sma1 = ta.sma(close, length2) plot(ema1, color=color.green, title="21-day EMA") plot(sma1, color=color.red, title="50-day SMA") // Create a table at the top-left of the chart with 2 columns and 3 rows var table myTable = table.new(position.bottom_right, 2, 3, bgcolor = color.black, border_width = 2, frame_width=1, frame_color = color.white, border_color=color.white) var table myTable1 = table.new(position.top_right, 1, 2, bgcolor = color.black, border_width = 1, frame_width=1, frame_color = color.white, border_color=color.white) // Populate the table table.cell(myTable, 0, 0, "EMA") table.cell(myTable, 1, 0, "Line") table.cell(myTable, 0, 1, "21 EMA") table.cell(myTable, 1, 1, "─") table.cell(myTable, 0, 2, "50 SMA") table.cell(myTable, 1, 2, "─") // Setting cell text color to green and red respectively table.cell_set_text_color(myTable, 0, 0, color.white) table.cell_set_text_color(myTable, 1, 0, color.white) table.cell_set_text_color(myTable, 0, 1, color.white) table.cell_set_text_color(myTable, 0, 2, color.white) table.cell_set_text_color(myTable, 1, 1, color.green) table.cell_set_text_color(myTable, 1, 2, color.red) // Start Conditions startCondition1 = math.sum(low > ema1 ? 1 : 0, 10) >= 10 startCondition2 = math.sum(ema1 > sma1 ? 1 : 0, 5) >= 5 startCondition3 = sma1 > sma1[1] startCondition4 = close > open var bool inPosition = false //var bool startCondition = false //var bool endCondition = false startCondition = not inPosition and startCondition1 and startCondition2 and startCondition3 and startCondition4 endCondition = inPosition and (ta.crossover(sma1, ema1) or (close < 0.9 * recentHigh and close < sma1)) if (startCondition) inPosition := true if (endCondition) inPosition := false plotshape(startCondition, color=color.green, style=shape.labelup, location=location.belowbar, text="Trend On", textcolor = color.white) plotshape(endCondition, color=color.red, style=shape.labeldown, location=location.abovebar, text="Trend Off", textcolor = color.white) //Populate Powertrend symbol // Populate the table table.cell(myTable1, 0, 0, "Power Trend Status") table.cell_set_text_color(myTable1, 0, 0, color.white) if (inPosition) table.cell(myTable1, 0, 1, "●", text_color = color.green) else table.cell(myTable1, 0, 1, "●", text_color = color.red) table.set_position(myTable1, position.middle_right)