기본 피너 거래 전략

저자:차오장, 날짜: 2023-11-15 15:25:57
태그:

img

전반적인 설명

이 전략은 트렌드 결정과 함께 핀바르 패턴을 활용하여 트렌드 방향으로 트레이드 브레이크오웃으로 평균을 이동하여 트렌드를 결정합니다. 이 전략은 핀바르 촛불에서 형성된 높은 / 낮은에서 가격이 깨지면 거래 신호를 생성합니다. 또한 전체 트렌드 방향을 결정하기 위해 빠르고 느린 움직이는 평균을 사용하여 범위 제한 가격 행동 중에 잘못된 신호를 피합니다.

전략 논리

  1. 빠른 (20주기) 및 느린 (50주기) 이동 평균을 계산합니다.

  2. 촛불을 기준으로 상승 (폐기> 개방) 및 하락 (폐기< 개방) 핑바를 식별합니다.

  3. 핀바르 고위/하위가 이전 촛불의 고위/하위를 깨는지 확인한다. 올림 핀바르가 이전 고위점을 깨는 것은 긴 신호를 준다. 하락 핀바르가 이전 낮은 점을 깨는 것은 짧은 신호를 준다.

  4. 또한 빠른 MA가 느린 MA보다 높는지 확인하여 상승 추세를 결정하고 반대로 하락 추세를 결정합니다.

  5. 긴 신호는 빠른 / 느린 MA가 상승 추세를 나타낼 때만 유효합니다. 짧은 신호는 빠른 / 느린 MA가 하락 추세를 나타낼 때만 유효합니다. 이는 범위 제한 가격 행동 중에 잘못된 신호를 피합니다.

  6. 유효한 긴 신호에서, 미리 정의된 스톱 로스와 테이크프로피스를 통해 긴 신호로 가십시오. 유효한 짧은 신호에서, 미리 정의된 스톱 로스와 테이크프로피스를 통해 짧은 신호로 가십시오.

  7. 빠른 MA가 느린 MA보다 낮으면 기존 포지션을 종료합니다.

장점

  • 핑바의 높은/저하가 강한 모멘텀을 나타내는 브레이크아웃 레벨입니다.

  • 범위에 묶인 가격 행동 중에 잘못된 신호를 피하기 위해 트렌드 방향을 고려하여 정확도를 향상시킵니다.

  • 트렌드와 브레이크오웃을 포착하고 트렌드 시장에서 좋은 성과를 내고 있습니다.

  • 매개 변수는 다양한 제품과 시간 프레임에 최적화 될 수 있습니다.

위험 및 완화

  • 실패한 탈출 위험은 더 넓은 탈출 수준과 더 강한 추진력을 사용하여 완화 할 수 있습니다.

  • 불확정 트렌드 식별 위험. MA 매개 변수를 조정하거나 다른 트렌드 지표를 추가하여 완화 할 수 있습니다.

  • 너무 긴 스톱 로스로 조기 종료로 이어집니다. 제품과 시간 틀에 따라 스톱 로스를 동적으로 조정할 수 있습니다.

  • 이윤을 너무 제한해서 수익을 제한합니다. 수익 목표와 위험/이익 비율을 동적으로 설정할 수 있습니다.

더 나은 기회

  • 전반적으로, MA, 브레이크아웃, 스톱 로스 및 테크프로프트 매개 변수는 맞춤형 전략을 위해 제품과 시간 프레임에 따라 최적화 될 수 있습니다.

  • EMA, SMA 등과 같은 다양한 MAs를 테스트하여 최적의 지표를 찾을 수 있습니다.

  • 모멘텀과 같은 추가 지표는 트렌드 정확성을 향상시킬 수 있습니다.

  • 매개 변수는 기계 학습 기술을 사용하여 동적으로 최적화 할 수 있습니다.

  • 통계학적인 학습을 통해 탈출 성공률을 향상시킬 수 있습니다.

요약

이 전략은 이론적으로 필터링 된 신호를위한 트렌드와 모멘텀을 결합합니다. 핵심은 좋은 성능을 위해 제품과 시간 프레임에 걸쳐 강력한 매개 변수 최적화입니다. 또한 보조 지표와 기계 학습 기술은 전략을 더욱 향상시킬 수 있습니다. 지속적인 향상으로 이것은 강력한 트렌드 브레이크오웃 거래 시스템으로 변할 수 있습니다.


/*backtest
start: 2023-10-15 00:00:00
end: 2023-11-14 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
//Backtested Time Frame: H1
//Default Settings: Are meant to run successfully on all currency pairs to reduce over-fitting.
//Risk Warning: This is a forex trading robot, backtest performance will not equal future performance, USE AT YOUR OWN RISK.
//Code Warning: Although every effort has been made for robustness, this code has not been vetted by independent 3rd parties.
strategy("Pin Bar Strategy v1", overlay=true)

// User Input
usr_risk = input(title="Equity Risk (%)",type=input.integer,minval=1,maxval=100,step=1,defval=3,confirm=false)
atr_mult = input(title="Stop Loss (x*ATR, Float)",type=input.float,minval=0.1,maxval=100,step=0.1,defval=1.9,confirm=false)
trd_rewd = input(title="Risk : Reward (1 : x*SL, Float)",type=input.float,minval=0.1,maxval=100,step=0.1,defval=3.1,confirm=false)
sma_fast = input(title="Fast MA (Period)",type=input.integer,minval=1,maxval=500,step=1,defval=20,confirm=false)
sma_slow = input(title="Slow MA (Period)",type=input.integer,minval=1,maxval=500,step=1,defval=50,confirm=false)
atr_valu = input(title="ATR (Period)",type=input.integer,minval=1,maxval=500,step=1,defval=14,confirm=false)
use_slpe = input(title="Use MA Slope (Boolean)",type=input.bool,defval=true,confirm=false)
slp_long = input(title="Bull Slope Angle (Deg)",type=input.integer,minval=-90,maxval=90,step=1,defval=1,confirm=false)
slp_shrt = input(title="Bear Slope Angle (Deg)",type=input.integer,minval=-90,maxval=90,step=1,defval=-1,confirm=false)
emg_exit = input(title="Exit When MA Re-Cross (Boolean)",type=input.bool,defval=true,confirm=false)
ent_canc = input(title="Cancel Entry After X Bars (Period)",type=input.integer,minval=1,maxval=500,step=1,defval=3,confirm=false)

// Create Indicators
fastSMA = sma(close, sma_fast)
slowSMA = sma(close, sma_slow)
bullishPinBar = ((close > open) and ((open - low) > 0.66 * (high - low))) or ((close < open) and ((close - low) > 0.66 * (high - low)))
bearishPinBar = ((close > open) and ((high - close) > 0.66 * (high - low))) or ((close < open) and ((high - open) > 0.66 * (high - low)))
atr = atr(atr_valu)

// Specify Trend Conditions
smaUpTrend = (fastSMA > slowSMA) and (fastSMA[1] > slowSMA[1]) and (fastSMA[2] > slowSMA[2]) and (fastSMA[3] > slowSMA[3]) and (fastSMA[4] > slowSMA[4])
smaDnTrend = (fastSMA < slowSMA) and (fastSMA[1] < slowSMA[1]) and (fastSMA[2] < slowSMA[2]) and (fastSMA[3] < slowSMA[3]) and (fastSMA[4] < slowSMA[4])
candleUpTrend = (close[5] > fastSMA[5]) and (open[5] > fastSMA[5]) and (close[6] > fastSMA[6]) and (open[6] > fastSMA[6]) and (close[7] > fastSMA[7]) and (open[7] > fastSMA[7]) and (close[8] > fastSMA[8]) and (open[8] > fastSMA[8]) and (close[9] > fastSMA[9]) and (open[9] > fastSMA[9]) and (close[10] > fastSMA[10]) and (open[10] > fastSMA[10])
candleDnTrend = (close[5] < fastSMA[5]) and (open[5] < fastSMA[5]) and (close[6] < fastSMA[6]) and (open[6] < fastSMA[6]) and (close[7] < fastSMA[7]) and (open[7] < fastSMA[7]) and (close[8] < fastSMA[8]) and (open[8] < fastSMA[8]) and (close[9] < fastSMA[9]) and (open[9] < fastSMA[9]) and (close[10] < fastSMA[10]) and (open[10] < fastSMA[10])

// Specify Piercing Conditions
bullPierce = ((low < fastSMA) and (open > fastSMA) and (close > fastSMA)) or ((low < slowSMA) and (open > slowSMA) and (close > slowSMA))
bearPierce = ((high > fastSMA) and (open < fastSMA) and (close < fastSMA)) or ((high > slowSMA) and (open < slowSMA) and (close < slowSMA))

// MA Slope Function
angle(_source) =>
    rad2degree=180/3.14159265359
    ang=rad2degree*atan((_source[0] - _source[1])/atr(atr_valu)) 

// Calculate MA Slope
fastSlope=angle(fastSMA)
slowSlope=angle(slowSMA)
slopingUp = fastSlope > slp_long
slopingDn = fastSlope < slp_shrt
    
// Specify Entry Conditions
longEntry = smaUpTrend and bullishPinBar and bullPierce
shortEntry = smaDnTrend and bearishPinBar and bearPierce
longEntryWithSlope = smaUpTrend and bullishPinBar and bullPierce and slopingUp
shortEntryWithSlope = smaDnTrend and bearishPinBar and bearPierce and slopingDn

// Specify Secondary Exit Conditions
longExit = crossunder(fastSMA, slowSMA)
shortExit = crossover(fastSMA, slowSMA)

// Long Entry Function
enterlong() =>
    risk = usr_risk * 0.01 * strategy.equity
    stopLoss = low[1] - atr[1] * atr_mult
    entryPrice = high[1]
    units = risk / (entryPrice - stopLoss)
    takeProfit = entryPrice + trd_rewd * (entryPrice - stopLoss)
    strategy.entry("long", strategy.long, units, stop=entryPrice)
    strategy.exit("exit long", "long", stop=stopLoss, limit=takeProfit)
    
// Short Entry Function
entershort() =>
    risk = usr_risk * 0.01 * strategy.equity
    stopLoss = high[1] + atr[1] * atr_mult
    entryPrice = low[1]
    units = risk / (stopLoss - entryPrice)
    takeProfit = entryPrice - trd_rewd * (stopLoss - entryPrice)
    strategy.entry("short", strategy.short, units, stop=entryPrice)
    strategy.exit("exit short", "short", stop=stopLoss, limit=takeProfit)
    
// Execute Long Entry w/o Slope
if (longEntry and use_slpe == false)
    enterlong()
    
// Execute Long Entry w/ Slope
if (longEntryWithSlope and use_slpe == true)
    enterlong()

// Exit Long Due to Re-Cross
if(longExit and strategy.position_size > 0 and emg_exit)    
    strategy.order("exit long, re-cross", strategy.short, abs(strategy.position_size))

// Cancel the Long Entry
strategy.cancel("long", barssince(longEntry) > ent_canc)

// Execute Short Entry w/o Slope
if (shortEntry and use_slpe == false)
    entershort() 
    
// Execute Short Entry w/ Slope
if (shortEntryWithSlope and use_slpe == true)
    entershort() 

// Exit Short Due to Re-Cross
if(shortExit and strategy.position_size < 0 and emg_exit)    
    strategy.order("exit short, re-cross", strategy.long, abs(strategy.position_size))

// Cancel the Short Entry
strategy.cancel("short", barssince(shortEntry) > ent_canc)

// Plot Moving Averages to Chart
plot(fastSMA, color=color.red)
plot(slowSMA, color=color.blue)

// Plot Pin Bars to Chart
plotshape(bullishPinBar, style=shape.arrowup, location=location.abovebar, color=#FF0000, text='')
plotshape(bearishPinBar, style=shape.arrowdown, location=location.belowbar, color=#0000FF, text='')

더 많은