Doji Trender
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Kerbal

//@version=5
indicator("Doji Trender", overlay = true, max_lines_count = 500, max_bars_back = 5000)
float dojiPercent = input.float(0.00025, "Doji O/C percent", minval = 0.00001, step = 0.00001)
int emaLength = input.int(10, "EMA length")
string tf1 = input.timeframe("5", "Timeframe 1")
string tf2 = input.timeframe("15", "Timeframe 2")
string tf3 = input.timeframe("60", "Timeframe 3")
string tf4 = input.timeframe("240", "Timeframe 4")

float dojiMath = math.abs(1 - close / open) <= dojiPercent ? (open + close) / 2 : na
int otherSize = 3

float dojisChart = request.security(syminfo.ticker, timeframe.period, dojiMath)
if (timeframe.period == tf1) or (timeframe.period == tf2) or (timeframe.period == tf3) or (timeframe.period == tf4)
    dojisChart := na
plot(dojisChart, "Chart doji trends", color.rgb(0, 225, 255), 2, plot.style_line, display = display.pane - display.status_line)
plot(dojisChart, "Chart doji markers", color.rgb(0, 225, 255), 5, plot.style_circles, display = display.all)

dojisMaChart = ta.ema(dojisChart, emaLength)
plot(dojisMaChart, "Chart doji trends ma", color.rgb(0, 225, 255), 1, plot.style_line, display = display.pane - display.status_line)

float dojisTf4 = request.security(syminfo.ticker, tf4, dojiMath)
plot(dojisTf4, "Fourth timeframe doji trends", color.rgb(0, 255, 0), 2, plot.style_line, display = display.pane - display.status_line)
plot(dojisTf4, "Fourth timeframe doji markers", color.rgb(0, 255, 0), otherSize, plot.style_circles, display = display.all)

dojisMaTf4 = ta.ema(dojisTf4, emaLength)
plot(dojisMaTf4, "Fourth timeframe doji trends ma", color.rgb(0, 255, 0), 1, plot.style_line, display = display.pane - display.status_line)


float dojisTf3 = request.security(syminfo.ticker, tf3, dojiMath)
plot(dojisTf3, "Third timeframe doji trends", color.rgb(255, 255, 0), 2, plot.style_line, display = display.pane - display.status_line)
plot(dojisTf3, "Third timeframe doji markers", color.rgb(255, 255, 0), otherSize, plot.style_circles, display = display.all)

dojisMaTf3 = ta.ema(dojisTf3, emaLength)
plot(dojisMaTf3, "Third timeframe doji trends ma", color.rgb(255, 255, 0), 1, plot.style_line, display = display.pane - display.status_line)

float dojisTf2 = request.security(syminfo.ticker, tf2, dojiMath)
plot(dojisTf2, "Second timeframe doji trends", color.rgb(255, 128, 0), 2, plot.style_line, display = display.pane - display.status_line)
plot(dojisTf2, "Second timeframe doji markers", color.rgb(255, 128, 0), otherSize, plot.style_circles, display = display.all)

float dojisTf1 = request.security(syminfo.ticker, tf1, dojiMath)
plot(dojisTf1, "First timeframe doji trends", color.rgb(255, 0, 0), 2, plot.style_line, display = display.pane - display.status_line)
plot(dojisTf1, "First timeframe doji markers", color.rgb(255, 0, 0), otherSize, plot.style_circles, display = display.all)