전략에 따라 촛불 평균 이동 수 추세

저자:차오장, 날짜: 2023-09-16 19:04:02
태그:

전반적인 설명

이 문서에서는 촛불 수를 기반으로 한 트렌드 다음 전략을 소개합니다. 촛불 방향을 세어 일정 수의 촛불 후에 트렌드 방향을 판단합니다.

전략 논리

이 전략은 다음을 기본으로 합니다.

  1. 시장 편향을 결정하기 위해 촛불 방향을 계산합니다. N 개의 연속 촛불이 한 방향으로 갈 때 추세가 확인됩니다.

  2. 상승 추세에서는 N의 연속 하락 촛불 후에 장을 가십시오. 하락 추세에서는 N의 연속 상승 촛불 후에 짧은 것을 가십시오.

  3. 더 작은 N 값은 추세를 더 빨리 파악하지만, 윙사우에 더 민감합니다.

  4. 고정된 수익점과 스톱 로스 포인트는 수익을 차단하고 위험을 통제합니다.

  5. 반전 촛불이 나타나면 위치를 닫습니다.

이점 분석

이 전략의 장점:

  1. 직접적인 트렌드 판단을 위한 간단한 촛불 계산. 구현하기 쉽습니다.

  2. 트렌드 엔트리는 트렌드가 잘 움직입니다.

  3. 고정된 정지로는 위험을 효과적으로 관리합니다.

  4. 조정 가능한 매개 변수는 다른 시장 환경에 적합합니다.

  5. 간단한 논리는 최적화를 쉽게 합니다.

위험 분석

또한 고려해야 할 위험이 있습니다.

  1. 계산은 시장에서 오해할 수 있습니다.

  2. 고정된 정지점은 수익 잠재력을 제한할 수 있습니다.

  3. 잘못된 판단 때문에 조기에 멈춰서서

  4. 매개 변수와 크기를 적절히 조정합니다.

  5. 계산 매개 변수들은 신중하게 평가되어야 합니다.

결론

이 전략 은 촛불 수를 결합 하고 트렌드 를 따라가는 방법 이다. 적절 한 조정 을 하면 괜찮은 결과 를 낼 수 있다. 그러나 상인들은 시장 을 신중 하게 평가 하고 장기적 이익 을 위해 매개 변수 를 조정 해야 한다.


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

더 많은