변동성 대역 반전을 기반으로 한 장기적 양적 전략

저자:차오장, 날짜: 2023-09-15 11:34:45
태그:

이 기사에서는 변동 범위를 사용하여 반전을 식별하는 장기적인 양적 거래 전략을 상세히 설명합니다. 가격이 하위 범위를 넘어서면 상향 움직임을 타는 긴 포지션이 필요합니다.

I. 전략 논리

핵심 지표는 변동성 대역입니다.

  1. 중간, 상위 및 하위 이동 평균 대역을 계산합니다.

  2. 구매 신호는 가격이 하위 범위를 넘을 때 생성됩니다.

  3. 판매 신호는 가격이 상단 범위를 넘을 때 생성됩니다.

  4. 출구는 판매 신호나 상단 간격에서 나올 수 있습니다.

  5. 스톱 로스는 고정된 비율입니다.

이것은 하락 단계로 구매를 허용하고, 수익을 취하거나 반전을 활용하기 위해 중단을 통해 탈퇴 할 수 있습니다.

II. 전략의 장점

가장 큰 장점은 변동성 대역을 사용하여 역전 지점을 식별하는 것입니다.

또 다른 장점은 거래당 위험을 제어하기 위한 스톱 로스 메커니즘입니다.

마지막으로, 피라미드 구조는 반전 후 수익을 단계적으로 끌어올리는 데도 도움이 됩니다.

III. 잠재적 위험

그러나 몇 가지 잠재적 인 문제가 있습니다.

첫째로, 이동 평균은 지연을 가지고 있으며, 가장 좋은 입시 시기를 놓칠 수 있습니다.

둘째, 수익을 취하고 손해를 멈추는 수준은 신중한 최적화를 필요로 합니다.

마지막으로, 긴 보유 기간은 특정 마취 기간을 지속한다는 것을 의미합니다.

IV. 요약

요약적으로,이 기사는 변동성 대역을 사용하여 반전을 활용하는 장기적 양적 거래 전략을 설명했습니다. 그것은 장기적 보유에 대한 반전 기회를 효과적으로 탐지 할 수 있습니다. 그러나 MA 지연과 같은 위험은 예방이 필요하며 출구에 최적화가 필요합니다. 전반적으로 강력한 장기적 거래 접근 방식을 제공합니다.


/*backtest
start: 2023-09-07 00:00:00
end: 2023-09-12 04:00:00
period: 14m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ediks123

//strategy logic  has been borrowed from ceyhun  and tweaked the settings for back testing

//@version=4


//SPY 4 hrs settings 8, 13 , 3.33 , 0.9  on 4 hrs chart
//QQQ above settings is good , but 13, 13 has less number of bars 
//QQQ 4 hrs settings 13, 13 , 3.33 , 0.9  on 4 hrs chart

strategy(title="Volatility Bands Reversal Strategy",  shorttitle="VolatilityBandReversal" , overlay=true, pyramiding=2,     default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000, currency=currency.USD)  //default_qty_value=10, default_qty_type=strategy.fixed,


av = input(8, title="Band Average")
vp = input(13, title="Volatility Period")
df = input(3.33,title="Deviation Factor",minval=0.1)
lba = input(0.9,title="Lower Band Adjustment",minval=0.1)

riskCapital = input(title="Risk % of capital", defval=10, minval=1)
stopLoss=input(6,title="Stop Loss",minval=1)

exitOn=input(title="Exit on", defval="touch_upperband", options=["Sell_Signal", "touch_upperband"])



src = hlc3
typical = src >= src[1] ? src - low[1] : src[1] - low
deviation = sum( typical , vp )/ vp * df
devHigh = ema(deviation, av)
devLow = lba * devHigh
medianAvg = ema(src, av)

emaMediaAvg=ema(medianAvg, av)

upperBandVal= emaMediaAvg + devHigh
lowerbandVal= emaMediaAvg - devLow
MidLineVal=sma(medianAvg, av)

UpperBand = plot ( upperBandVal, color=#EE82EE, linewidth=2, title="UpperBand")
LowerBand = plot ( lowerbandVal , color=#EE82EE, linewidth=2, title="LowerBand")
MidLine = plot (MidLineVal, color=color.blue, linewidth=2, title="MidLine")
buyLine = plot ( (lowerbandVal + MidLineVal )/2  , color=color.blue, title="BuyLine")

up=ema(medianAvg, av) + devHigh
down=ema(medianAvg, av) - devLow


ema50=ema(hlc3,50)
plot ( ema50, color=color.orange, linewidth=2, title="ema 50")

//outer deviation

//deviation1 = sum( typical , vp )/ vp * 4
//devHigh1 = ema(deviation, av)
//devLow1 = lba * devHigh
//medianAvg1 = ema(src, av)

//UpperBand1 = plot (emaMediaAvg + devHigh1, color=color.red, linewidth=3, title="UpperBand1")
//LowerBand1 = plot (emaMediaAvg - devLow1, color=color.red, linewidth=3, title="LowerBand1")
//



///Entry Rules
//1)First candle close below the Lower Band of the volatility Band
//2)Second candle close above the lower band
//3)Third Candle closes above previous candle
Buy = close[2] < down[2] and close[1]>down[1] and close>close[1]
//plotshape(Buy,color=color.blue,style=shape.arrowup,location=location.belowbar, text="Buy")
//barcolor(close[2] < down[2] and close[1]>down[1] and close>close[1] ? color.blue :na )
//bgcolor(close[2] < down[2] and close[1]>down[1] and close>close[1] ? color.green :na )

///Exit Rules
//1)One can have a static stops initially followed by an trailing stop based on the risk the people are willing to take
//2)One can exit with human based decisions or predefined target exits. Choice of deciding the stop loss and profit targets are left to the readers.
Sell = close[2] > up[2] and close[1]<up[1] and close<close[1]
//plotshape(Sell,color=color.red,style=shape.arrowup,text="Sell")
barcolor(close[2] > up[2] and close[1]<up[1] and close<close[1] ? color.yellow :na )
bgcolor(close[2] > up[2] and close[1]<up[1] and close<close[1] ? color.red :na )

//Buyer = crossover(close,Buy)
//Seller = crossunder(close,Sell)

//alertcondition(Buyer, title="Buy Signal", message="Buy")
//alertcondition(Seller, title="Sell Signal", message="Sell")


//Entry--
//Echeck how many units can be purchased based on risk manage ment and stop loss
qty1 = (strategy.equity  * riskCapital / 100 ) /  (close*stopLoss/100)  

//check if cash is sufficient  to buy qty1  , if capital not available use the available capital only
qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1

strategy.entry(id="vbLE", long=true, qty=qty1, when=Buy)

bgcolor(strategy.position_size>=1 ? color.blue : na)
// stop loss exit
stopLossVal = strategy.position_size>=1 ?  strategy.position_avg_price * ( 1 - (stopLoss/100) ) : 0.00
//draw initil stop loss
plot(strategy.position_size>=1 ? stopLossVal : na, color = color.purple , style=plot.style_linebr,  linewidth = 2, title = "stop loss") //, trackprice=true)


strategy.close(id="vbLE", comment="SL exit Loss is  "+tostring(close - strategy.position_avg_price,  "###.##") , when=abs(strategy.position_size)>=1 and close < stopLossVal )   




//close on Sell_Signal
strategy.close(id="vbLE", comment="Profit is : "+tostring(close - strategy.position_avg_price,  "###.##") , when=strategy.position_size>=1 and  exitOn=="Sell_Signal"  and Sell)

//close on touch_upperband
strategy.close(id="vbLE", comment="Profit is : "+tostring(close - strategy.position_avg_price,  "###.##") , when=strategy.position_size>=1 and  exitOn=="touch_upperband"  and (crossover(close, up) or crossover(high, up)))

더 많은