하이켄 아시와 슈퍼 트렌드 조합 전략

저자:차오장, 날짜: 2023-12-15 11:11:27
태그:

img

전반적인 설명

이것은 하이켄 아시와 슈퍼 트렌드 지표를 결합한 양적 거래 전략입니다. 이 전략은 주로 촛불을 부드럽게하고 시장 소음을 필터하기 위해 하이켄 아시를 사용하고 트렌드를 추적하기 위해 가격 트렌드 방향을 판단하기 위해 슈퍼 트렌드 지표를 사용합니다.

전략 원칙

  1. 하이켄 아시 지표를 사용하여 촛불을 처리하고 시장 소음을 필터링하여 추세를 더 분명하게 만듭니다.
  2. ATR 및 요인을 기반으로 슈퍼 트렌드의 상부 및 하부 대역을 계산합니다.
  3. 가격이 상단 레일을 뚫면 하향 신호이고, 하단 레일을 뚫면 상승 신호입니다.
  4. 요인이 커질수록 슈퍼 트렌드 신호가 적을수록 추적 효과가 더 좋아질 수 있지만 엔트리 수는 감소합니다.
  5. 트렌드를 판단하고 추적하기 위해 하이켄 아시와 슈퍼 트렌드 지표를 결합하십시오.

전략 의 장점

  1. 하이켄 아시 지표는 효과적으로 시장 소음을 필터하고 그래프를 더 명확하게합니다.
  2. 슈퍼 트렌드 지표는 좋은 최적화 효과를 가지고 있으며 입력 주파수를 유연하게 조정할 수 있습니다.
  3. 이중 지표의 조합은 가격 동향을 판단하는 효과를 더 좋게합니다.
  4. 강력한 트렌드를 자동으로 추적합니다

전략 의 위험

  1. 이 지표 조합은 시장 통합 기간 동안 잘못된 신호를 완전히 피할 수 없습니다.
  2. 큰 격차로 인해 유효하지 않은 지표가 발생하여 중요한 신호 포인트가 빠질 수 있습니다.
  3. 슈퍼 트렌드 요인을 너무 크게 설정하면 트렌드 기회를 놓칠 수 있습니다.

해결책: (1) 수퍼 트렌드 매개 변수를 적절히 조정하여 추적 효과와 입력 빈도를 균형을 맞추십시오.
(2) 격차로 인한 문제를 피하기 위해 판단에 도움이되는 다른 지표를 증가

전략의 최적화 방향

  1. 입력 주파수를 최적화하기 위해 ATR 사이클과 슈퍼 트렌드 인수를 조정합니다.
  2. 단일 손실을 제어하기 위해 스톱 손실 표시기를 높여
  3. 트렌드 쇼크의 리듬을 적절하게 다루지 않도록 다른 지표를 결합하여 트렌드 유형을 결정합니다.
  4. 트렌드 방향을 판단하는 데 도움이 되는 기계 학습 알고리즘을 늘려

요약

이 전략은 하이켄 아시와 슈퍼 트렌드의 이중 지표의 장점을 통합하여 지표를 사용하여 가격 트렌드의 방향을 결정하고 자동 추적을 달성합니다. 단일 지표만 사용하는 것과 비교하면 가격 움직임을 판단하는 효과가 더 좋으며 전략의 안정성이 향상됩니다. 물론, 여전히 개선의 여지가 있습니다. 미래에 전략이 더 수익성 있고 덜 위험하도록 엔트리 빈도 및 스톱 로스 측면에서 최적화를 수행 할 수 있습니다.


/*backtest
start: 2022-12-08 00:00:00
end: 2023-12-14 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

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

//@version=5

strategy("Heiken Ashi & Super Trend", overlay=true,  pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.02)

///////////////////////////////////////////////////
////////////////////Function///////////////////////
///////////////////////////////////////////////////


heikinashi_open = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)
heikinashi_high = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)
heikinashi_low  = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)
heikinashi_close= request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)
heikinashi_color = heikinashi_open < heikinashi_close ? #53b987 : #eb4d5c
// plotbar(heikinashi_open, heikinashi_high, heikinashi_low, heikinashi_close, color=heikinashi_color)

x_sma(x, y) =>
    sumx = 0.0
    for i = 0 to y - 1
        sumx := sumx + x[i] / y
    sumx

x_rma(src, length) =>
	alpha = 1/length
	sum = 0.0
	sum := na(sum[1]) ? x_sma(src, length) : alpha * src + (1 - alpha) * nz(sum[1])

x_atr(length) =>
    trueRange = na(heikinashi_high[1])? heikinashi_high-heikinashi_low : math.max(math.max(heikinashi_high - heikinashi_low, math.abs(heikinashi_high - heikinashi_close[1])), math.abs(heikinashi_low - heikinashi_close[1]))
    //true range can be also calculated with ta.tr(true)
    x_rma(trueRange, length)

x_supertrend(factor, atrPeriod) =>
	src = (heikinashi_high+heikinashi_low)/2
	atr = x_atr(atrPeriod)
	upperBand = src + factor * atr
	lowerBand = src - factor * atr
	prevLowerBand = nz(lowerBand[1])
	prevUpperBand = nz(upperBand[1])

	lowerBand := lowerBand > prevLowerBand or heikinashi_close[1] < prevLowerBand ? lowerBand : prevLowerBand
	upperBand := upperBand < prevUpperBand or heikinashi_close[1] > prevUpperBand ? upperBand : prevUpperBand
	int direction = na
	float superTrend = na
	prevSuperTrend = superTrend[1]
	if na(atr[1])
		direction := 1
	else if prevSuperTrend == prevUpperBand
		direction := heikinashi_close > upperBand ? -1 : 1
	else
		direction := heikinashi_close < lowerBand ? 1 : -1
	superTrend := direction == -1 ? lowerBand : upperBand
	[superTrend, direction]
	

///////////////////////////////////////////////////
////////////////////Indicators/////////////////////
///////////////////////////////////////////////////

atrPeriod = input(10, "ATR Length")
factor = input.float(3.0, "Factor", step = 0.01)

[supertrend, direction] = x_supertrend(factor, atrPeriod)

bodyMiddle = plot((heikinashi_open + heikinashi_close) / 2, display=display.none)
upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)
downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = color.red, style=plot.style_linebr)

fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps=false)
fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps=false)

///////////////////////////////////////////////////
////////////////////Strategy///////////////////////
///////////////////////////////////////////////////

var bool longCond                    = na, var bool shortCond                   = na, longCond := nz(longCond[1]), shortCond := nz(shortCond[1])
var int CondIni_long                 = 0, var int CondIni_short                 = 0, CondIni_long := nz(CondIni_long[1]), CondIni_short := nz(CondIni_short[1])
var float open_longCondition         = na, var float open_shortCondition   = na


long  = ta.change(direction) < 0
short = ta.change(direction) > 0


longCond        :=                                                              long
shortCond       :=                                                              short

CondIni_long    :=                                                              longCond[1] ? 1 : shortCond[1] ? -1 : nz(CondIni_long[1])
CondIni_short   :=                                                              longCond[1] ? 1 : shortCond[1] ? -1 : nz(CondIni_short[1])
longCondition   =                                                               (longCond[1] and nz(CondIni_long[1]) == -1)
shortCondition  =                                                               (shortCond[1] and nz(CondIni_short[1]) == 1)


open_longCondition             :=                                          long ? close[1] :                                                      nz(open_longCondition[1])
open_shortCondition            :=                                          short ? close[1] :                                                     nz(open_shortCondition[1])


//TP
tp                    = input.float(1.1  , "TP [%]",                      step = 0.1) 

//BACKTESTING inputs --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

testStartYear       =                   input.int(2000,                             title="start year",                                         minval = 1997, maxval = 3000,                                                   group= "BACKTEST") 
testStartMonth      =                   input.int(01,                               title="start month",                                        minval = 1, maxval = 12,                                                        group= "BACKTEST")
testStartDay        =                   input.int(01,                               title="start day",                                          minval = 1, maxval = 31,                                                        group= "BACKTEST")
testPeriodStart     =                   timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear        =                   input.int(3333,                             title="stop year",                                          minval=1980, maxval = 3333,                                                     group= "BACKTEST")
testStopMonth       =                   input.int(12,                               title="stop month",                                         minval=1, maxval=12,                                                            group= "BACKTEST")
testStopDay         =                   input.int(31,                               title="stop day",                                           minval=1, maxval=31,                                                            group= "BACKTEST")
testPeriodStop      =                   timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)
testPeriod          =                   true

// Backtest  ==================================================================================================================================================================================================================================================================================================================================


if longCond
    strategy.entry("L", strategy.long, when=testPeriod)

if shortCond
    strategy.entry("S", strategy.short, when=testPeriod)
    

strategy.exit("TP_L", "L", profit =((open_longCondition   *       (1+(tp/100))) - open_longCondition)/syminfo.mintick)

strategy.exit("TP_S", "S", profit =((open_shortCondition  *       (1+(tp/100))) - open_shortCondition)/syminfo.mintick)





더 많은