I have backtested this indicator on TradingView, and it works quite well. However, the problem lies in manually opening each trade due to a lack of time.
This is the idea about automation.
The critical factor is position sizing; the stoploss isn't fixed in terms of pips but depends on price action, as shown in the attachment (SL always on line of previous color)
Stoploss should be set at 0.25% of the capital per trade, and the take profit at 2R.
My envisioning of the EA is as follows: when a bomb,hammer (signal for opening long/short) appears on the chart, signals could repaint!! Therefore, it should always wait for the candle to close. If the signal remains after the candle closes, the position should be opened immediately on the next candle.
The position is opened with the correct size, considering proper risk management.
Hope that it's technically possible to create EA by these terms.
strategy("Follow Line Indicator Strategy", overlay=true)
BBperiod = input(defval = 20, title = "BB Period", type = input.integer, minval = 1)
BBdeviations = input(defval = 0.1, title = "BB Deviations", type = input.float, minval = 0.1, step=0.05)
UseATRfilter = input(defval = true, title = "ATR Filter", type = input.bool)
ATRperiod = input(defval = 5, title = "ATR Period", type = input.integer, minval = 1)
hl = input(defval = false, title = "Hide Labels", type = input.bool)
BBUpper=sma (close,BBperiod)+stdev(close, BBperiod)*BBdeviations
BBLower=sma (close,BBperiod)-stdev(close, BBperiod)*BBdeviations
TrendLine = 0.0
iTrend = 0.0
buy = 0.0
sell = 0.0
BBSignal = close>BBUpper? 1 : close<BBLower? -1 : 0
calculateStopLossLevel() =>
var float stopLossLevel = na
stopLossLevel := na(stopLossLevel[1]) ? TrendLine : stopLossLevel[1]
stopLossLevel := iTrend == 1 and iTrend[1] == -1 ? TrendLine : stopLossLevel
stopLossLevel := iTrend == -1 and iTrend[1] == 1 ? TrendLine : stopLossLevel
stopLossLevel
long_stop_level = calculateStopLossLevel()
short_stop_level = calculateStopLossLevel()
strategy.exit("Long Stop", from_entry="Buy", loss=long_stop_level)
strategy.exit("Short Stop", from_entry="Sell", loss=short_stop_level)
if (BBSignal == 1 and UseATRfilter)
TrendLine := low - atr(ATRperiod)
if (TrendLine < TrendLine[1])
TrendLine := TrendLine[1]
else if (BBSignal == -1 and UseATRfilter)
TrendLine := high + atr(ATRperiod)
if (TrendLine > TrendLine[1])
TrendLine := TrendLine[1]
else if (UseATRfilter)
TrendLine := TrendLine[1]
if (BBSignal == 1 and not UseATRfilter)
TrendLine := low
if (TrendLine < TrendLine[1])
TrendLine := TrendLine[1]
else if (BBSignal == -1 and not UseATRfilter)
TrendLine := high
if (TrendLine > TrendLine[1])
TrendLine := TrendLine[1]
else if (not UseATRfilter)
TrendLine := TrendLine[1]
iTrend := nz(iTrend[1])
iTrend := TrendLine > TrendLine[1] ? 1 : TrendLine < TrendLine[1] ? -1 : iTrend
buy_signal = iTrend[1] == -1 and iTrend == 1 ? 1 : na
sell_signal = iTrend[1] == 1 and iTrend == -1 ? 1 : na
strategy.entry("Buy", strategy.long, when=buy_signal and na(buy_signal[1]))
strategy.entry("Sell", strategy.short, when=sell_signal and na(sell_signal[1]))
plot(TrendLine, color=iTrend > 0 ? color.blue : color.red, style=plot.style_line, linewidth=2, transp=0, title="Trend Line")
plotshape(buy_signal == 1 and not hl ? TrendLine - atr(8) : na, text='💣', style=shape.labelup, location=location.absolute, color=color.blue, textcolor=color.white, offset=0, transp=0, size=size.auto)
plotshape(sell_signal == 1 and not hl ? TrendLine + atr(8) : na, text='🔨', style=shape.labeldown, location=location.absolute, color=color.red, textcolor=color.white, offset=0, transp=0, size=size.auto)