Halfband (=hi-lo middle value) Trading System in support for investments (2024)

First of all, Happy New 2024 and a big hug to Japanese friends… we hope all ok for you all.

This is a very effective system in support for entries and exits for swing traders and investments (i.e. if you want not to see graphs everyday but only once or twice per week and you want to keep a position for some days or weeks). This system beats continually the lazy but good “Buy and Hold” for many and many stocks.

Just Trade in these stocks:

  • * Trade stocks with a ROE> 20% (it depends in the purpose of your investments, but you may select a more ambitious 30%, but there are more risks for going lower than going higher). – Tradingview stock screener is a great help for all market (not only U.S. like Finviz) – Do not regard of any other indicator, like P/E, analysts’ opionions and target price and so on. The behaviour of the market is collapsed into prices movements, and in this technical analsys
  • * Entry when close overcomes the average of the high and low of the last but one bar on weekly chart (=so called “Halfband“). There is a filter of a “green bar” (close > open) for the last bar, i.e. the overcome should not due to a so low level of the halfband (typical in falling markets).
  • * Since in the trading system the order are placed at the opening of the next bar, but the instructions calc_on_order_fills=true is critical, before entry a position check only if the monday’s open (or of first day of the week of market opened) is not below “Haldfband”. Otherwise, stay flat

EXIT the market

  • * in case of a fixed stop loss (risk management), in trading system = 7%
  • * if close is under Haldfband.

The system is very simple, but effective. You don’t need any I.A. or trading machines to implement it. You may do it manually and take into observation dozens of stocks, since analysis is very quick and collapsed in just one or two moment a week.

TRADINGVIEW CODE (fundamental passages are in bold)

//@version=5

strategy(title=’Halfband 2 W_lo’, overlay=true, precision=4, calc_on_order_fills=true, calc_on_every_tick =true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=20000, currency=currency.EUR, commission_type=strategy.commission.percent, commission_value=0.25)

period_ = input.int(1, title=”Length”, minval=1)

halfband = (high[period_]+low[period_])/2

plot(halfband, title=”halfband”, color=color.rgb(243, 222, 33), linewidth = 2, style=plot.style_stepline, precision = 4)

// === 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 = 2022, 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”

// entries: version 2 variant is here, in xentryl

Entry1= ta.crossover(close, halfband) and window()

Entry2 = close> open

xentryl = Entry1 and Entry2

xentrys = ta.crossunder(close, halfband) and window()

strategy.entry(‘Long’, strategy.long, when= xentryl)

strategy.close(‘Long’, when=xentrys, comment=’change’)

// MONEY MANAGEMENT

lossp = input.float(7, minval=1, step=1)

losspel = strategy.position_avg_price * (1 – lossp / 100)

fixed_stop_long = close < losspel

strategy.close(‘Long’, when=fixed_stop_long, comment = ‘Stop loss’)

5,0 / 5
Grazie per aver votato!