According to my previous post, I’ve inserted a proposal of script for tradingview Strategy (to be improved-revised).
Remember that this authomatical strategy is not solid, because it is based upon technical analisys, while the indicator must be used in coniunjction with target price (or, at limit, alone on ETF for index prices)
//@version=5
// In this strategy, enter long if close is the higher than last x-days’ highs and exit when close is lower then x-days’ lows
strategy(title=’Breakout candle max min long only v2′, calc_on_order_fills=false, calc_on_every_tick=true, max_bars_back=5000, initial_capital=100000, commission_type=strategy.commission.cash_per_order, commission_value=50, overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=20)
// INPUTS
length = input.int(2, ‘period of days ago- immodificabile’, minval=1)
lossp = input.int(13, ‘stop loss percentage’, minval=2, step=1)
targetp = input.int(25, ‘target profit percentage’, minval=2, step=1)
// === INPUT BACKTEST RANGE ===
fromMonth = input.int(defval = 1, title = “From Month”, minval = 1, maxval = 12)
fromDay = input.int(defval = 1, title = “From Day”, minval = 1, maxval = 31)
fromYear = input.int(defval = 2019, title = “From Year”, minval = 1970)
thruMonth = input.int(defval = 1, title = “Thru Month”, minval = 1, maxval = 12)
thruDay = input.int(defval = 1, title = “Thru Day”, minval = 1, maxval = 31)
thruYear = input.int(defval = 2112, title = “Thru Year”, minval = 1970)
// === FUNCTION EXAMPLE limit for backtest ===
start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start window
finish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function “within window of time”
hl2 = (high+close)/2
hl21 = (high[1]+close[1])/2
hl22 = (high[2]+close[2])/2
//ENTRY CONDITION
entry1 = hl2 >= math.max(hl21,hl22)
/// Entry orders
strategy.entry(‘Long’, strategy.long, comment=’bar up’, when=entry1 and window())
//CONDIZIONI DI USCITA
lc1= (low+close)/2
lc21 = (low[1]+close[1])/2
lc22 = (low[2]+close[2])/2
exit3 = lc1 <= math.min(lc21, lc22)
losspel = strategy.position_avg_price * (1 – lossp / 100)
exit4 = close < losspel
profitplev = strategy.position_avg_price * (1+ targetp / 100)
exit2 = close > profitplev
// exit orders
strategy.close(‘Long’, when=exit3, comment=’bar down’)
// FIXED MONEY MANAGEMENT
strategy.close(‘Long’, when=exit4, comment=’stop loss’)
strategy.close(‘Long’, when=exit2, comment=’target profit’)
// to reader, adding trailing stop




