
이 전략은 직각 도표 찢어짐 원리를 활용하여 이동 평균의 추세 판단과 결합하여 추세 방향의 돌파 거래를 실현한다. 가격이 직각 도표 경계를 돌파 할 때 거래 신호를 발생시킨다. 동시에, 빠른 및 느린 이동 평균의 위치 관계를 판단하여 전체 추세 방향을 결정하고, 전체 판에서 잘못된 신호를 발생시키지 않는다.
빠른 이동 평균 ((20주기) 과 느린 이동 평균 ((50주기) 을 계산한다.
K선에 따라 상승하는 긴사각형 ((close>open) 또는 하락하는 긴사각형 ((close
장사각형이 앞의 K선에서 가장 높은 가격이나 가장 낮은 가격을 돌파했는지 여부를 판단하십시오. 상승하는 장사각형이 앞의 K선에서 가장 높은 가격을 돌파하면 다중 돌파 신호가 발생하며, 하강하는 장사각형이 앞의 K선에서 가장 낮은 가격을 돌파하면 공중 돌파 신호가 발생합니다.
동시에 빠른 이동 평균이 느린 이동 평균 위에 있는지 여부를 판단합니다. 만약 그렇다면, 다목적 경향으로 판단합니다. 반대로, 공백 경향으로 판단합니다.
빠른 느린 평균선이 다목적 경향으로 판단될 때만 다목적 돌파 신호가 유효하며, 빠른 느린 평균선이 공허 경향으로 판단될 때만 공허 돌파 신호가 유효한다. 이것은 조립에서 잘못된 신호를 발생하지 않게 한다.
유효한 다중 헤드 브레이크 신호가 발생했을 때, 특정 스톱 및 스톱 기준에 따라 여러 장을 열고, 유효한 공중 헤드 브레이크 신호가 발생했을 때 특정 스톱 및 스톱 기준에 따라 공백 장을 열는다.
만약 빠른 이동 평균과 느린 이동 평균이 서로 갈라지면, 현재의 포지션을 평행한다.
직사각형의 경계선을 뚫는 구멍으로 사용해서 강력한 뚫는 신호를 나타냅니다.
트렌드 방향을 고려하면서 조회에서 잘못된 신호를 피하고 정확도를 높여라.
트렌드와 브레이크를 모두 고려하여 트렌드 상황에서 전략이 잘 작동하도록 한다.
매개 변수를 최적화하여 다양한 품종과 시간 주기에도 적응할 수 있다.
파격 실패의 위험. 해결책은 더 큰 파격문을 선택하여 파격 동력이 더 강하도록 하는 것이다.
트렌드를 판단할 때 정확하지 않은 위험. 해결 방법은 평균선 변수를 조정하거나 다른 보조 지표를 추가하여 트렌드를 판단할 수 있습니다.
스로퍼 설정이 너무 작아서 스로퍼가 너무 자주 발생하는 위험이 있다. 해결 방법은 다양한 품종과 시간 주기 역학에 따라 스로퍼 폭을 조정하는 것이다.
수익 공간 설정이 너무 작은 위험. 해결 방법은 다양한 품종과 시간 주기 역동성에 따라 다른 수익/손실 비율을 설정하는 것이다.
전체적으로, 이동 평균 변수, 돌파구 변수, 중단량, 그리고 상환율이 서로 다른 품종과 시간 주기에 따라 테스트되고 최적화되어 전략 변수가 맞춤화되어야 합니다.
다양한 유형의 이동 평균을 테스트 할 수 있습니다 (EMA, SMA 등), 더 적합한 평균 지표를 찾습니다.
트렌드 판단의 정확성을 높이기 위해 Momentum와 같은 다른 보조 판단 지표를 추가 할 수 있습니다.
기계학습과 같은 방법을 통해 다양한 파라미터를 동적으로 최적화할 수 있다.
돌파의 성공률에 따라 통계학습을 할 수 있으며, 돌파구 파라미터를 조정할 수 있다.
이 전략은 트렌드 특징과 브레이크 특징을 통합하여 이론적으로 많은 비효율적 인 신호를 필터링 할 수 있습니다. 중요한 것은 다양한 품종과 시간대에 적합한 전략을 맞춤화하여 실제 거래에서 더 나은 효과를 얻을 수 있도록 매개 변수의 테스트 및 최적화에 중점을 두는 것입니다. 또한 보조 지표와 기계 학습 기술은 전략의 개선에 대한 방향을 제공합니다. 지속적인 최적화를 통해 이 전략은 안정적이고 신뢰할 수있는 트렌드 브레이크 거래 전략이 될 수 있습니다.
/*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='')