가격 돌파에 기반한 적응형 스윙 트레이딩 전략


생성 날짜: 2023-12-04 14:34:13 마지막으로 수정됨: 2023-12-04 14:34:13
복사: 0 클릭수: 672
avatar of ChaoZhang ChaoZhang
1
집중하다
1619
수행원

가격 돌파에 기반한 적응형 스윙 트레이딩 전략

개요

이 전략은 가격 돌파점을 기반으로 시장의 흐름을 식별하고, 자기 적응 지표와 결합하여 큰 흐름을 판단하여 단기 가격 역전 기회를 잡습니다. 가격이 기준 돌파 채널에서 돌파 할 때 구매/판매 신호를 생성합니다. 이 전략은 높은 변동률의 디지털 통화 거래에 적합합니다.

전략 원칙

  1. 가격의 극한점을 통로 경계로 식별한다. 가격이 새로운 높이를 만들 때 또는 새로운 낮이를 만들 때, 그 점을 통로 경계로한다.
  2. 적응 변동 지표 MA를 계산하여 전반적인 경향 방향을 판단한다. MA 값이 커질수록 현재 흔들림 단계에 있음을 나타낸다.
  3. 가격이 상향으로 채널의 상단선을 돌파할 때, 구매 신호를 생성한다. 가격이 하향으로 채널의 하단선을 돌파할 때, 판매 신호를 생성한다.
  4. 스톱로스 지점을 설정한다. 긴 포지션 스톱로스 지점은 입시 가격의 1%로 설정한다.

우위 분석

  1. 가격 통로는 자기 적응성이 있어 트렌드 전환점을 정확하게 판단할 수 있다.
  2. 변동 지표는 큰 흐름을 판단하고, 흔들리는 경향에서 큰 방향을 놓치지 않도록 한다.
  3. 반전 전략, 가격의 단기 반전을 잡기 위해 적합하다

위험 분석

  1. 계속적으로 큰 폭의 하락이 발생하면 여러 개의 스톱포인트가 발생하여 큰 손실이 발생할 수 있습니다.
  2. 이 거래는 거래비용을 높여주기 때문에 거래가 자주 이루어지고 있습니다.
  3. 수동으로 접속할 수 있는 시간이 필요하며, 자동으로 거래되는 거래에는 적합성이 있는 위험이 있습니다.

최적화 방향

  1. MA의 파라미터를 최적화하여 전체적인 흐름을 더 잘 판단할 수 있다.
  2. 에너지 지표를 높이고 에너지 고갈을 방지하는 반향 신호.
  3. 기계 학습 모델을 추가하여 매개 변수의 동적 최적화를 구현한다.

요약하다

이 전략의 전체적인 생각은 명확하고 실용적인 가치가 있다. 그러나 여전히 거래 위험을 제어하는 데 주의를 기울여야 하며, 특정 상황에서 큰 손실을 초래하지 않도록 한다. 다음 단계는 전체적인 프레임워크, 지표 파라미터, 위험 제어 등 여러 차원에서 최적화하여 전략 파라미터와 거래 신호를 더 신뢰할 수 있다.

전략 소스 코드
/*backtest
start: 2023-11-03 00:00:00
end: 2023-12-03 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version = 4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TradingGroundhog



//  ||---   Cash & Date:
cash_amout = 10000
pyramid_val = 1
cash_given_per_lot = cash_amout/pyramid_val
startDate = input(title="Start Date",defval=13)
startMonth = input(title="Start Month",defval=9)
startYear = input(title="Start Year",defval=2021)
afterStartDate = (time >= timestamp(syminfo.timezone,startYear, startMonth, startDate, 0, 0))
//  ||------------------------------------------------------------------------------------------------------



//  ||---   Strategy:
strategy(title="TradingGroundhog - Strategy & Fractal V1 - Short term", overlay=true, max_bars_back = 4000, max_labels_count=500, commission_type=strategy.commission.percent, commission_value=0.00,default_qty_type=strategy.cash, default_qty_value= cash_given_per_lot, pyramiding=pyramid_val)
//  ||------------------------------------------------------------------------------------------------------



//  ||---   Fractal Recognition:
filterBW = input(true, title="filter Bill Williams Fractals:")
filterFractals = input(true, title="Filter fractals using extreme method:")
length = input(2, title="Extreme Window:")
regulartopfractal = high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0]
regularbotfractal = low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0]
billwtopfractal = filterBW ? false : (high[4] < high[2] and high[3] < high[2] and high[2] > high[1] and high[2] > high[0] ? true : false)
billwbotfractal = filterBW ? false : (low[4] > low[2] and low[3] > low[2] and low[2] < low[1] and low[2] < low[0] ? true : false)
ftop = filterBW ? regulartopfractal : regulartopfractal or billwtopfractal
fbot = filterBW ? regularbotfractal : regularbotfractal or billwbotfractal
topf = ftop ? high[2] >= highest(high, length) ? true : false : false
botf = fbot ? low[2] <= lowest(low, length) ? true : false : false
filteredtopf = filterFractals ? topf : ftop
filteredbotf = filterFractals ? botf : fbot
//  ||------------------------------------------------------------------------------------------------------



//  ||---   V1 : Added Swing High/Low Option
ShowSwingsHL = input(true)
highswings = filteredtopf == false ? na : valuewhen(filteredtopf == true, high[2], 2) < valuewhen(filteredtopf == true, high[2], 1) and valuewhen(filteredtopf == true, high[2], 1) > valuewhen(filteredtopf == true, high[2], 0)
lowswings = filteredbotf == false ? na : valuewhen(filteredbotf == true, low[2], 2) > valuewhen(filteredbotf == true, low[2], 1) and valuewhen(filteredbotf == true, low[2], 1) < valuewhen(filteredbotf == true, low[2], 0)
//---------------------------------------------------------------------------------------------------------



//  ||---   V2 : Plot Lines based on the fractals.
showchannel = input(true)
//---------------------------------------------------------------------------------------------------------



//  ||---   ZigZag:
showZigZag = input(true)
//----------------------------------------------------------------------------------------------------------



//  ||---   Fractal computation:
istop = filteredtopf ? true : false
isbot = filteredbotf ? true : false
topcount = barssince(istop)
botcount = barssince(isbot)
vamp = input(title="VolumeMA",  defval=2)
vam = sma(volume, vamp)
fractalup = 0.0
fractaldown = 0.0
up = high[3]>high[4] and high[4]>high[5] and high[2]<high[3] and high[1]<high[2] and volume[3]>vam[3]
down = low[3]<low[4] and low[4]<low[5] and low[2]>low[3] and low[1]>low[2] and volume[3]>vam[3]
fractalup :=  up ? high[3] : fractalup[1] 
fractaldown := down ? low[3] : fractaldown[1]
//----------------------------------------------------------------------------------------------------------



//  ||---   Fractal save:
fractaldown_save = array.new_float(0)
for i = 0 to 4000
    if array.size(fractaldown_save) < 3
        if array.size(fractaldown_save) == 0
            array.push(fractaldown_save, fractaldown[i])
        else 
            if fractaldown[i] != array.get(fractaldown_save, array.size(fractaldown_save)-1)
                array.push(fractaldown_save, fractaldown[i])
if array.size(fractaldown_save) < 3
    array.push(fractaldown_save, fractaldown)
    array.push(fractaldown_save, fractaldown)
fractalup_save = array.new_float(0)
for i = 0 to 4000
    if array.size(fractalup_save) < 3
        if array.size(fractalup_save) == 0
            array.push(fractalup_save, fractalup[i])
        else 
            if fractalup[i] != array.get(fractalup_save, array.size(fractalup_save)-1)
                array.push(fractalup_save, fractalup[i])
if array.size(fractalup_save) < 3
    array.push(fractalup_save, fractalup)
    array.push(fractalup_save, fractalup)
Bottom_1 = array.get(fractaldown_save,  0)
Bottom_2 = array.get(fractaldown_save,  1)
Bottom_3 = array.get(fractaldown_save,  2)
Top_1 = array.get(fractalup_save, 0)
Top_2 = array.get(fractalup_save, 1)
Top_3 = array.get(fractalup_save, 2)
//----------------------------------------------------------------------------------------------------------



//  ||---   Fractal Buy Sell Signal:
bool Signal_Test = false
bool Signal_Test_OUT_TEMP = false
var Signal_Test_TEMP = false
longLossPerc = input(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=0.01) * 0.01
if filteredbotf and open < Bottom_1 and (Bottom_1 - open) / Bottom_1 >= longLossPerc
    Signal_Test := true
if filteredtopf and open > Top_1
    Signal_Test_TEMP := true
if filteredtopf and Signal_Test_TEMP
    Signal_Test_TEMP := false
    Signal_Test_OUT_TEMP := true
//----------------------------------------------------------------------------------------------------------



//  ||---   Plotting:
//plotshape(filteredtopf, style=shape.triangledown, location=location.abovebar, color=color.red, text="•", offset=0)
//plotshape(filteredbotf, style=shape.triangleup, location=location.belowbar, color=color.lime, text="•", offset=0)
//plotshape(ShowSwingsHL ? highswings : na, style=shape.triangledown, location=location.abovebar, color=color.maroon, text="H", offset=0)
//plotshape(ShowSwingsHL ? lowswings : na, style=shape.triangleup, location=location.belowbar, color=color.green, text="L", offset=0)
plot(showchannel ? (filteredtopf ? high[2] : na) : na, color=color.black, offset=0)
plot(showchannel ? (filteredbotf ? low[2] : na) : na, color=color.black, offset=0)
plot(showchannel ? (highswings ? high[2] : na) : na, color=color.black, offset=-2)
plot(showchannel ? (lowswings ? low[2] : na) : na, color=color.black, offset=-2)
plotshape(Signal_Test, style=shape.flag, location=location.belowbar, color=color.yellow, offset=0)
plotshape(Signal_Test_OUT_TEMP, style=shape.flag, location=location.abovebar, color=color.white, offset=0)
//----------------------------------------------------------------------------------------------------------



//  ||---   Buy And Sell:
strategy.entry(id="Long", long=true, when = Signal_Test and afterStartDate)
strategy.close_all(when = Signal_Test_OUT_TEMP and afterStartDate)
//----------------------------------------------------------------------------------------------------------