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

저자:차오장, 날짜: 2023-11-02 16:15:18
태그:

img

전반적인 설명

하이켄 아시와 슈퍼 트렌드 전략은 하이켄 아시 촛불과 슈퍼 트렌드 지표를 결합한 트렌드를 따르는 전략이다. 트렌드 방향을 파악하고 트렌드에 따라 거래하고 트렌드가 역전되면 신속하게 빠져나가는 것을 목표로 하며, 트렌드 이외의 거래로 인한 손실을 최소화합니다.

전략 논리

하이켄 아시 촛불은 촛불 몸의 그래프를 그리기 위해 개방, 폐쇄, 높은 및 낮은 가격의 평균을 사용하는 특별한 유형의 촛불이다. 시장 소음을 필터링하고 패턴을 더 명확하게 만듭니다. 슈퍼 트렌드 지표는 트렌드 방향을 결정하기 위해 동적 지원과 저항을 형성하는 두 줄로 구성됩니다.

이 전략은 먼저 하이켄 아시 촛불을 계산하고, 그 다음 하이켄 아시 촛불을 기반으로 슈퍼 트렌드 지표를 계산합니다. 거래 신호는 가격이 슈퍼 트렌드 라인을 통과 할 때 생성됩니다. 구체적으로, 전략은 하이켄 아시 촛불을 사용하여 진정한 범위를 계산하고, 그 다음 범위를 사용하여 슈퍼 트렌드의 상부 및 하부 밴드를 추출합니다. 가격이 하부 밴드 이상으로 넘어갈 때 긴 신호가 생성되며 가격이 상부 밴드 아래에 넘어갈 때 짧은 신호가 생성됩니다.

슈퍼 트렌드 매개 변수 또한 최고의 결과를 위해 최적화되어 지표의 민감도를 향상시킵니다. 또한 수익을 잠금하는 동안 위험을 제어하기 위해 스톱 로스 메커니즘이 구현됩니다.

이점 분석

  • 하이켄 아시 촛불은 더 명확한 신호를 위해 소음을 필터합니다.
  • 슈퍼 트렌드는 트렌드 변화를 빠르게 파악하고 적시에 신호를 생성합니다.
  • 매개 변수 최적화는 지표의 신뢰성을 향상시킵니다.
  • 내장된 스톱 로스 메커니즘은 위험을 효과적으로 제어합니다.
  • 트렌드 추적과 자동화 거래를 결합하여 높은 자동화 수준.

위험 분석

  • 높은 자동화는 이상 현상을 피하기 위해 철저한 모니터링이 필요합니다.
  • 하이켄 아시는 소음을 필터링할 때 아주 작은 반전 신호를 놓칠 수 있습니다.
  • 슈퍼 트렌드는 잘못된 신호를 생성하여 조기 진입 또는 스톱 로스를 유발할 수 있습니다.
  • 부적절한 스톱 로스 배치도 불필요한 손실로 이어질 수 있습니다.
  • 백테스트 데이터가 충분하지 않아서 과장 조정이 발생할 수 있습니다. 실시간 결과는 백테스트에서 크게 벗어날 수 있습니다.

최적화 방향

  • 슈퍼 트렌드를 더 최적화하기 위해 더 많은 매개 변수 조합을 테스트합니다.
  • 다른 지표를 추가하여 슈퍼 트렌드 신호를 확인하고 잘못된 신호를 줄이십시오.
  • 손해를 막는 전략을 최적화하여 불필요한 손해를 최소화하고 수익을 확보합니다.
  • 기계 학습 알고리즘을 통합하여 빅데이터를 사용하여 실제 트렌드에 대한 판단을 훈련시킵니다.
  • 신뢰성을 높이기 위해 역 테스트를 위해 더 긴 시간 프레임과 더 다양한 역사적 데이터를 사용하십시오.

요약

하이켄 아시 및 슈퍼 트렌드 전략은 트렌드를 따르는 전략이다. 트렌드 방향을 파악하고 주요 트렌드에 따라 거래를 하며, 반전 시 빠르게 중단한다. 이 전략은 하이켄 아시의 노이즈 필터링과 슈퍼 트렌드의 빠른 트렌드 변화 검출을 통합한다. 매개 변수 최적화와 스톱 로스 디자인은 위험을 제어하면서 수익을 극대화 할 수 있다. 미래의 최적화는 더 많은 매개 변수 조정, 추가 신호 확인, 확장된 백테스팅 데이터 등을 포함하여 전략의 안정성과 신뢰성을 향상시킬 수 있다.


/*backtest
start: 2022-10-26 00:00:00
end: 2023-11-01 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5

strategy("Heiken Ashi & Super Trend_ARM", 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/////////////////////
///////////////////////////////////////////////////

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


[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          =                   time >= testPeriodStart and time <= testPeriodStop ? true : false

// 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)





더 많은