Saat garis K baru tiba, perhitungan di atas diperbarui bergulir untuk membentuk saluran adaptif atas, tengah dan bawah.
Risiko utama dari strategi ini adalah:
Strategi ini dapat dioptimalkan lebih lanjut dalam aspek berikut:
/*backtest start: 2023-12-01 00:00:00 end: 2023-12-31 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=2 strategy("Stealthy 7 Linear Regression Channel Strategy", overlay=true) source = open length = input(100, minval=1) mult1 = input(1, minval=0.001, maxval=50) mult2 = input(1, minval=0.001, maxval=50) DayTrader = input(title="Range Mode", type=bool, defval=false) //Making the first least squares line sum_x = length * (length + 1) / 2 sum_y = 0 sum_xy = 0 xyproductsum = 0 sum_xx = 0 for i = 1 to length sum_y := sum_y + close[i] sum_xy := i * close[i] + sum_xy sum_xx := i * i + sum_xx m = (length*sum_xy - (sum_x * sum_y)) / (length * sum_xx - (sum_x * sum_x)) b = sum_y / length - (m * sum_x / length) //Finding the first standard deviation from the line difference = 0 for i = 1 to length y = i * m + b difference := pow(abs(close[i] - y),2) + difference STDDEV = sqrt(difference / length) //Creating trading zones dev = mult1 * STDDEV dev2 = mult2 * STDDEV upper = b + dev lower = b - dev2 middle = b if DayTrader == false if crossover(source, upper) strategy.entry("RGLONG", strategy.long, oca_name="RegChannel", comment="RegLong") else strategy.cancel(id="RGLONG") if crossunder(source, lower) strategy.entry("RGSHORT", strategy.short, oca_name="RegChannel", comment="RegShort") else strategy.cancel(id="RGSHORT") if crossover(source, middle) and strategy.position_size < 0 strategy.close_all() if crossunder(source,middle) and strategy.position_size > 0 strategy.close_all() if DayTrader == true if crossover(source, lower) strategy.entry("RGLONG", strategy.long, oca_name="RegChannel", comment="RegLong") else strategy.cancel(id="RGLONG") if crossunder(source, upper) strategy.entry("RGSHORT", strategy.short, oca_name="RegChannel", comment="RegShort") else strategy.cancel(id="RGSHORT") plot(upper, title="UpperBand", color=purple, linewidth=1, style=line) plot(lower, title="LowerBand", color=purple, linewidth=1, style=line) plot(middle, title="MiddleBand", color=black, linewidth=1, style=line)