전략에 따른 평탄한 하이킨 아시 트렌드

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

img

전반적인 설명

이 전략은 사용자 지정 매끄러운 오시레이터 지표를 사용하여 가격 추세를 식별하고 추세를 따르는 원칙에 따라 거래를합니다. 가격이 지표 라인을 넘어서면 길고 가격이 라인을 넘어서면 짧습니다.

전략 논리

이 전략은 맞춤형 평형 오시일레이터를 사용하여 하이킨 아시 촛불 색상을 빨간색에서 녹색으로 전환하는 데 필요한 역 폐쇄 가격을 계산합니다. 이 역 폐쇄는 최종 오시일레이터 라인을 얻기 위해 이동 평균을 사용하여 평평화됩니다. 라인 위의 (아래) 가격 거래는 상승 추세 (하락 추세) 를 신호합니다.

이 전략은 지표 라인의 브레이크아웃을 기반으로 거래를 시작합니다. 가격이 라인의 위를 넘을 때 긴 거래가 시작되며 라인 아래에 파기되면 짧은 거래가 시작됩니다. 스톱 손실은 수익을 잠금하고 위험을 제어하기 위해 엔트리 가격에서 고정된 비율로 설정됩니다.

장점

  1. 사용자 지정 지표는 좋은 백테스트 결과를 가진 트렌드를 식별합니다.
  2. 트렌드를 따르는 접근 방식은 양적 이론과 일치합니다.
  3. 스톱 로스 구현은 위험 관리를 촉진

위험성

  1. 라이브 성능이 떨어질 수 있는 재칠 가능성이 있습니다.
  2. 단 하나의 지표에 의존하는 것은 나쁜 신호의 위험이 있습니다.
  3. 스톱 손실 설정은 추가 최적화를 필요로 합니다.

더 나은 기회

  1. 볼링거 밴드, RSI 등과 같은 추가 필터를 포함합니다.
  2. 다른 지표 매개 변수를 테스트
  3. 스톱 로스 배치 최적화
  4. 더 많은 테스트를 통해 도구와 시간

결론

이 전략은 사용자 지정 오시일레이터 지표를 사용하는 접근 방식을 따르는 명확한 추세를 보여줍니다. 백테스트 결과는 라이브 거래의 잠재력을 나타내는 격려적입니다. 그러나 하나의 재칠 지표에만 의존하고 신호 품질 검증 부족은 우려입니다. 스톱 손실 메커니즘 또한 추가 테스트와 조정이 필요합니다. 전반적으로 전략 개념은 실현 가능하지만 라이브 거래에 신뢰할 수 있도록 더 많은 작업이 필요합니다.


/*backtest
start: 2023-12-19 00:00:00
end: 2023-12-26 00:00:00
period: 10m
basePeriod: 1m
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/

// © TraderHalai
// This is a backtest of the Smoothed Heikin Ashi Trend indicator, which computes the reverse candle close price required to flip a heikin ashi trend from red to green and vice versa. Original indicator can be found on the scripts section of my profile.

// Default testing parameters are 10% of equity position size, with a 1% stop loss on short and long strategy.opentrades.commission

// This particular back test uses this indicator as a Trend trading tool with a tight stop loss. The equity curve as tested seems promising but requires further work to refine. Note in an actual trading setup, you may wish to use this with volatilty filters as most of the losses are in sideways, low volatility markets.


//@version=5
strategy("Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST", " SHA Trend - BACKTEST", overlay=true)
//Inputs

i_useSmooth =       input ( true, "Use smoothing Heikin Ashi")
i_smoothingMethod = input.string("SMA", "Method", options=["SMA", "EMA", "HMA", "VWMA", "RMA"])
i_smoothingPeriod = input ( 10, "Smoothing period")

i_infoBox   =       input ( true, "Show Info Box"        )
i_decimalP  =       input ( 2,    "Prices Decimal Places") 
i_boxOffSet =       input ( 5,    "Info Box Offset"      )
i_repaint   =       input (false,  "Repaint -  Keep on for live / Off for backtest")

i_longLossPerc = input.float(title="Long Stop Loss (%)",minval=0.0, step=0.1, defval=1) * 0.01

i_shortLossPerc = input.float(title="Short Stop Loss (%)", minval=0.0, step=0.1, defval=1) * 0.01


timeperiod = timeframe.period

//Security functions to avoid repaint, as per PineCoders
f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
f_security(_symbol, _res, _src, _repaint) => request.security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 : 0])[_repaint ? 0 : barstate.isrealtime ? 0 : 1]
f_secSecurity2(_symbol, _res, _src) => request.security(_symbol, _res, _src[1])


candleClose = f_security(syminfo.tickerid, timeperiod, close, i_repaint)
candleOpen = f_security(syminfo.tickerid, timeperiod, open, i_repaint)
candleLow = f_security(syminfo.tickerid, timeperiod, low, i_repaint)
candleHigh = f_security(syminfo.tickerid, timeperiod, high, i_repaint)

haTicker = ticker.heikinashi(syminfo.tickerid)
haClose = f_security(haTicker, timeperiod, close, i_repaint)
haOpen = f_security(haTicker, timeperiod, open, i_repaint)
haLow = f_security(haTicker, timeperiod, low, i_repaint)
haHigh= f_security(haTicker, timeperiod, high, i_repaint)


reverseClose = (2 * (haOpen[1] + haClose[1])) - candleHigh - candleLow - candleOpen

if(reverseClose < candleLow)
    reverseClose := (candleLow + reverseClose) / 2

if(reverseClose > candleHigh)
    reverseClose := (candleHigh + reverseClose) / 2
    
//Smoothing
    
smaSmoothed = ta.sma(reverseClose, i_smoothingPeriod)
emaSmoothed = ta.ema(reverseClose, i_smoothingPeriod)
hmaSmoothed = ta.hma(reverseClose, i_smoothingPeriod)
vwmaSmoothed = ta.vwma(reverseClose, i_smoothingPeriod)
rmaSmoothed = ta.rma(reverseClose, i_smoothingPeriod)

shouldApplySmoothing = i_useSmooth and i_smoothingPeriod > 1 

smoothedReverseClose = reverseClose

if(shouldApplySmoothing)
    if(i_smoothingMethod == "SMA")
        smoothedReverseClose := smaSmoothed
    else if(i_smoothingMethod == "EMA")
        smoothedReverseClose := emaSmoothed
    else if(i_smoothingMethod == "HMA")
        smoothedReverseClose := hmaSmoothed
    else if(i_smoothingMethod == "VWMA")
        smoothedReverseClose := vwmaSmoothed
    else if(i_smoothingMethod == "RMA")
        smoothedReverseClose := rmaSmoothed
    else 
        smoothedReverseClose := reverseClose // Default to non-smoothed for invalid smoothing type
    
haBull = candleClose >= smoothedReverseClose
haCol = haBull ? color.green : color.red


//Overall trading strategy
if(ta.crossover(candleClose, smoothedReverseClose))
    strategy.entry("LONG", strategy.long, stop=smoothedReverseClose)
else
    strategy.cancel("LONG")

if(ta.crossunder(candleClose, smoothedReverseClose))
    strategy.entry("SHORT", strategy.short, stop=smoothedReverseClose)
else
    strategy.cancel("SHORT")
    

longStopPrice  = strategy.position_avg_price * (1 - i_longLossPerc)
shortStopPrice = strategy.position_avg_price * (1 + i_shortLossPerc)



plot(series=(strategy.position_size > 0) ? longStopPrice : na,
     color=color.red, style=plot.style_cross,
     linewidth=2, title="Long Stop Loss")
plot(series=(strategy.position_size < 0) ? shortStopPrice : na,
     color=color.red, style=plot.style_cross,
     linewidth=2, title="Short Stop Loss")
     
plot(smoothedReverseClose, color=haCol)

if (strategy.position_size > 0)
    strategy.exit(id="XL STP", stop=longStopPrice)

if (strategy.position_size < 0)
    strategy.exit(id="XS STP", stop=shortStopPrice)


더 많은