이 글은 K선 수를 기반으로 한 추세 추적 전략에 대해 소개한다. 이 전략은 K선 방향을 통계를 통해, 시장의 움직임을 판단하고, 고정 뿌리 K선 이후 입장을 한다.
이 전략은 다음과 같은 원칙에 기초하고 있습니다.
통계 K선 방향, 판단 현상 Bias。 N근 연속 K선 방향이 동시일 때, 판단 트렌드가 형성。
상승 추세에서는 N근 연속 음선이 나타나면 더 많이 하고, 하향 추세에서는 N근 연속 양선이 나타나면 공백을 한다.
N의 값이 작으면 전략이 트렌드를 더 빨리 잡을 수 있지만 N의 값이 너무 작으면 흔들리는 시장에 의해 오해될 수 있다.
수익을 고정하고 위험을 제어하기 위해 고정 스톱 스톱 손실 지점을 설정할 수 있습니다.
반전 K선이 나타났을 때, 평행이 멈춰진다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
K선 통계로 추세를 판단하고, 간단하고, 직설적이며, 조작이 쉽다.
“이런 트렌드를 제대로 파악할 수 있는 좋은 입점입니다.
고정 스톱 스톱 지점으로, 위험을 효과적으로 제어할 수 있다.
K선수 매개 변수는 조정할 수 있으며, 다른 시장 환경에 적용된다.
전략은 간단하고 명확하며, 수정 및 최적화가 쉽다.
이 전략에는 위험도 있습니다.
진동상태에서 K선계수는 잘못된 신호를 발산할 수 있다.
고정 스톱 스톱 손실 지점은 너무 단단하여 충분히 수익을 얻지 못할 수 있습니다.
회전 신호를 잘못 판단하면 조기 중단될 수 있다.
적절하게 변수를 조정하고 포지션 규모를 제어하십시오.
거래자는 계산 변수의 타당성을 신중하게 평가해야 합니다.
이 전략은 K선 통계와 트렌드 추적의 개념을 통합한다. 파라미터를 설정하는 것이 합리적인 경우, 좋은 효과를 낼 수 있다. 그러나 거래자는 여전히 시장 환경을 신중하게 평가하고, 적절한 파라미터를 조정하여 장기적인 이익을 얻을 수 있다.
/*backtest
start: 2023-08-16 00:00:00
end: 2023-09-15 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//@author=Daveatt
StrategyName = "BEST Candle Meter Strategy"
ShortStrategyName = "BEST Candle Meter Strategy"
// strategy(title=StrategyName, shorttitle=ShortStrategyName, overlay=true,
// pyramiding=0, default_qty_value=100, precision=7, currency=currency.USD,
// commission_value=0.2,commission_type=strategy.commission.percent, initial_capital=10000)
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////// INPUTS ///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// TD Sequential approach would be setting bar_counter == 9
bar_counter = input(5, "Bar Counter",minval=1, step=1)
// if based on same candle
GreenCandle = close > open
RedCandle = close < open
// if based on previous candle open
GreenPrevCandle = close > open[1]
RedPrevCandle = close < open[1]
// conditons
barUP = GreenCandle
barDN = RedCandle
///////////////////////////////////////////////////////////////////////////////
////////////////////////////// COUNTERS ///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
var barsFromUp = 0
var barsFromDn = 0
barsFromUp := barUP ? barsFromUp + 1 : 0
barsFromDn := barDN ? barsFromDn + 1 : 0
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////// PLOTS ///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
plot_color = barsFromUp > 0 ? color.lime : color.red
//plot(barsFromUp, title="UP Histogram", color=plot_color, style=plot.style_histogram, linewidth=4)
//plot(barsFromDn, title="DN Histogram", color=plot_color, style=plot.style_histogram, linewidth=4)
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////// HLINE ///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//hline(9, '9 TD Sequential Line', linestyle=hline.style_solid, linewidth=2, color=color.black)
//hline(13, '12 TD Sequential Line', linestyle=hline.style_solid, linewidth=3, color=color.purple)
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////// PLOTCHAR //////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// var _lbl_UP = label(na)
// if barsFromUp > 0
// _lbl_UP := label.new(bar_index, close, tostring(barsFromUp, '#'), textcolor=color.green, style=label.style_none, yloc=yloc.price, xloc=xloc.bar_index, size=size.normal)
// var _lbl_DN = label(na)
// if barsFromDn > 0
// _lbl_DN := label.new(bar_index, close, tostring(barsFromDn, '#'), textcolor=color.red, style=label.style_none, yloc=yloc.price, xloc=xloc.bar_index, size=size.normal)
//plotshape(barsFromUp > 0, "", shape.arrowup, location.abovebar, color.green, text="A")
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////// ALERTS ////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// alertcondition(barsFromUp == 9, title='🔔Sell 9 Alert🔔', message="Sell 9 Alert")
// alertcondition(barsFromDn == 9, title='🔔Buy 9 Alert🔔', message='Buy 9 Alert')
// alertcondition(barsFromUp > 9, title='🔔Sell > 9 Alert🔔', message="Sell > 9 Alert")
// alertcondition(barsFromDn > 9, title='🔔Buy > 9 Alert🔔', message='Buy > 9 Alert')
///////////////////////////////////////////////
//* Backtesting Period Selector | Component *//
///////////////////////////////////////////////
StartYear = input(2017, "Backtest Start Year",minval=1980)
StartMonth = input(1, "Backtest Start Month",minval=1,maxval=12)
StartDay = input(1, "Backtest Start Day",minval=1,maxval=31)
testPeriodStart = timestamp(StartYear,StartMonth,StartDay,0,0)
StopYear = input(2020, "Backtest Stop Year",minval=1980)
StopMonth = input(12, "Backtest Stop Month",minval=1,maxval=12)
StopDay = input(31, "Backtest Stop Day",minval=1,maxval=31)
testPeriodStop = timestamp(StopYear,StopMonth,StopDay,0,0)
testPeriod() => true
isLong = barsFromUp == bar_counter
isShort = barsFromDn == bar_counter
long_entry_price = valuewhen(isLong, close, 0)
short_entry_price = valuewhen(isShort, close, 0)
sinceNUP = barssince(isLong)
sinceNDN = barssince(isShort)
buy_trend = sinceNDN > sinceNUP
sell_trend = sinceNDN < sinceNUP
//////////////////////////
//* Profit Component *//
//////////////////////////
//////////////////////////// MinTick ///////////////////////////
fx_pips_value = syminfo.type == "forex" ? syminfo.mintick*10 : 1
input_tp_pips = input(60, "Backtest Profit Goal (in USD)",minval=0)*fx_pips_value
input_sl_pips = input(30, "Backtest STOP Goal (in USD)",minval=0)*fx_pips_value
tp = buy_trend? long_entry_price + input_tp_pips : short_entry_price - input_tp_pips
sl = buy_trend? long_entry_price - input_sl_pips : short_entry_price + input_sl_pips
plot_tp = buy_trend and high[1] <= tp ? tp : sell_trend and low[1] <= tp ? tp : na
plot_sl = buy_trend and low[1] >= sl ? sl : sell_trend and high[1] >= sl ? sl : na
plot(plot_tp, title="TP", style=plot.style_circles, linewidth=3, color=color.blue)
plot(plot_sl, title="SL", style=plot.style_circles, linewidth=3, color=color.red)
longClose = isShort
shortClose = isLong
if testPeriod()
strategy.entry("Long", 1, when=isLong)
strategy.close("Long", when=longClose )
strategy.exit("XL","Long", limit=tp, when=buy_trend, stop=sl)
if testPeriod()
strategy.entry("Short", 0, when=isShort)
strategy.close("Short", when=shortClose )
strategy.exit("XS","Short", when=sell_trend, limit=tp, stop=sl)