
이 전략은 BollingerBands 트렌드 트래킹 전략이라고 불리며, BollingerBands 지표를 사용하여 가격 추세를 판단하고, 가격이 BollingerBands 통로를 돌파 할 때 입장을 추가 하락합니다. 그것은 일률 필터와 결합하여 돌파가 발생했을 때 트렌드 방향을 판단하여 추가 하락을 결정합니다.
이 전략은 주로 BollingerBands 지표에 의존하여 가격 동향을 판단하고 진입점을 위치시킨다. BollingerBands는 세 개의 선을 포함합니다:
가격이 하위 라인에서 상선을 돌파했을 때, 부진 추세가 형성되고 있다고 생각하며, 가격이 상선에서 하위 라인에서 상선을 돌파했을 때, 하향 추세가 형성되고 있다고 생각한다. 이 두 가지 돌파구가 발생할 때 전략은 더 많은 공백을 만듭니다.
이 전략의 논리는 다음과 같습니다.
가짜 브레이크를 필터링하기 위해, 전략은 평균선 판단을 추가한다. 상장 가격이 Bands를 돌파하는 동시에 평균선을 돌파할 때만 진입을 촉발한다.
여기서 Exponential Moving Average를 평균선 지표로 사용한다.
이 전략은 다음과 같이 트렌드 브레이크를 판단합니다.
진입 후, 중선을 추적하는 방법으로 스톱을 합니다. 가격이 중선을 다시 만질 때, 스톱을 탈퇴합니다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
이 전략은 장점이 있지만 다음과 같은 위험도 있습니다.
위와 같은 위험을 통제하기 위해, 다음과 같은 측면에서 최적화할 수 있습니다:
위와 같은 위험 분석을 통해, 이 전략은 다음과 같은 측면에서 더욱 개선될 수 있습니다.
변수 최적화보다 체계적인 방법, 예를 들어 유전적 알고리즘을 통해, 밴드와 평균선 변수의 최적의 조합을 찾아서, 전략을 보다 안정적이고 수익성 있게 만든다.
손해 방지 최적화: ATR 중지, 추적 중지 등과 같은 다양한 중지 방법을 테스트하여 최적의 중지 메커니즘을 결정합니다.
필터 최적화: RSI, KD 등과 같은 다른 지표를 추가 필터링 조건으로 추가하여 가짜 신호의 가능성을 낮추고 수익률을 높이는 것을 시도하십시오.
입학 조건 최적화: 트렌드 판단, 변동성 VOLUME 등과 같은 다른 고려 요소를 추가하고, 입시 시기를 엄격하게 선정하고, 불필요한 입장을 줄인다.
기계 학습더 많은 역사 데이터를 수집하고, LSTM, RNN 등의 딥러닝 모델을 사용하여 모형화하고, AI를 사용하여 가장 좋은 출전점을 판단한다.
위험과 수익의 역동적 관리: 고정 비율의 스톱 스톱 손실, 수익 목표 이후의 스톱 스톱 팽창을 추가하는 방법, 위험과 수익을 동적으로 관리하는 방법.
위의 몇 가지 측면을 최적화하면 전략의 안정성, 수익률, 위험 조절 능력과 같은 지표가 전체적으로 향상되어 실제 거래의 알고리즘 전략이 될 수 있습니다.
전체적으로 볼 때, 이 BollingerBands 트렌드 추적 전략은 Bands 지표와 평형 판단 가격 트렌드를 활용하여, 중요한 지점 지점을 돌파할 때 출전하는 트렌드 추적 유형 전략에 속한다. 판단이 명확하고, 논리 간결하고, 구현하기 쉬운 등의 장점이 있으며, 또한 몇 가지 매개 변수 최적화, 손해 중지 방법 등이 있습니다. 공간은 매개 변수 설정을 추가 조정하고, 손해 중지 메커니즘을 최적화하고, 기계 학습 모델 등을 추가함으로써 안정적이고 신뢰할 수 있는 양적 전략으로 만들 수 있다.
/*backtest
start: 2023-12-15 00:00:00
end: 2024-01-14 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//VERSION =================================================================================================================
//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// This strategy is intended to study.
// It can also be used to signal a bot to open a deal by providing the Bot ID, email token and trading pair in the strategy settings screen.
// As currently written, this strategy uses a Bollinger Bands for trend folling, you can use a EMA as a filter.
//Autor Credsonb (M4TR1X_BR)
//▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
//STRATEGY ================================================================================================================
strategy(title = 'BT-Bollinger Bands - Trend Following',
shorttitle = 'BBTF',
overlay = true )
//▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
// CONFIG =================================================================================================================
// TIME INPUTS
usefromDate = input.bool(defval = true, title = 'Start date', inline = '0', group = "Time Filters")
initialDate = input(defval = timestamp('01 Jan 2022 00:00 UTC'), title = '', inline = "0",group = 'Time Filters',tooltip="This start date is in the time zone of the exchange ")
usetoDate = input.bool(defval = true, title = 'End date', inline = '1', group = "Time Filters")
finalDate = input(defval = timestamp('31 Dec 2029 23:59 UTC'), title = '', inline = "1",group = 'Time Filters',tooltip="This end date is in the time zone of the exchange")
// TIME LOGIC
inTradeWindow = true
// ENABLE LONG SHORT OPTIONS
string entrygroup ='Long/Short Options ==================================='
checkboxLong = input.bool(defval=true, title="Enable Long Entrys",group=entrygroup)
checkboxShort = input.bool(defval=true, title="Enable Short Entrys",group=entrygroup)
// BOLLINGER BANDS INPUTS ==================================================================================================
string bbgroup ='Bollinger Bands ======================================'
bbLength = input.int(defval=20,title='BB Length', minval=1, step=5, group=bbgroup)
bbStddev = input.float(defval=2, title='BB StdDev', minval=0.5, group=bbgroup)
//BOLLINGER BANDS LOGIC
[bbMiddle, bbUpper, bbLower] = ta.bb(close, bbLength, bbStddev)
// MOVING AVERAGES INPUTS ================================================================================================
string magroup = 'Moving Average ======================================='
useEma = input.bool(defval = true, title = 'Moving Average Filter',inline='', group= magroup,tooltip='This will enable or disable Exponential Moving Average Filter on Strategy')
emaType=input.string (defval='Ema',title='Type',options=['Ema','Sma'],inline='', group= magroup)
emaSource = input.source(defval=close,title=" Source",inline="", group= magroup)
emaLength = input.int(defval=100,title="Length",minval=0,inline='', group= magroup)
// MOVING AVERAGE LOGIC
float ema = emaType=='Ema'? ta.ema(emaSource,emaLength): ta.sma(emaSource,emaLength)
// BOT MESSAGES
string msgroup='Alert Message For Bot ================================'
messageEntry = input.string("", title="Strategy Entry Message",group=msgroup)
messageExit =input.string("",title="Strategy Exit Message",group=msgroup)
messageClose = input.string("", title="Strategy Close Message",group=msgroup)
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
// POSITIONS =============================================================================================================
//VERIFY IF THE BUY FILTERS ARE ON OR OFF
bool emaFilterBuy = useEma? (close > ema):(close >= ema) or (close <= ema)
//LONG / SHORT POSITIONS LOGIC
bool openLongPosition = (close[1] < bbUpper) and (close > bbUpper) and (emaFilterBuy)
bool openShortPosition = (close[1] > bbLower) and (close < bbLower) and (emaFilterBuy)
//bool closeLongPosition = (close > bbMiddle)
//bool closeShortPosition= (close < bbLower)
// CHEK OPEN POSITONS =====================================================================================================
// open signal when not already into a position
bool validOpenLongPosition = openLongPosition and strategy.opentrades.size(strategy.opentrades - 1) <= 0
bool longIsActive = validOpenLongPosition or strategy.opentrades.size(strategy.opentrades - 1) > 0
bool validOpenShortPosition = openShortPosition and strategy.opentrades.size(strategy.opentrades - 1) <= 0
bool shortIsActive = validOpenShortPosition or strategy.opentrades.size(strategy.opentrades - 1) < 0
longEntryPoint = high
if (openLongPosition) and (inTradeWindow) and (checkboxLong)
strategy.entry(id = 'Long Entry', direction = strategy.long, stop = longEntryPoint, alert_message=messageEntry)
if not (openLongPosition)
strategy.cancel('Long Entry')
//submit exit orders for trailing take profit price
if (longIsActive) and (inTradeWindow)
strategy.exit(id = 'Long Exit', stop=bbMiddle, alert_message=messageExit)
//if (closeLongPosition)
// strategy.close(id = 'Long Entry', alert_message=messageClose)
shortEntryPoint = low
if (openShortPosition) and (inTradeWindow) and (checkboxShort)
strategy.entry(id = 'Short Entry', direction = strategy.short, stop = shortEntryPoint, alert_message=messageEntry)
if not(openShortPosition)
strategy.cancel('Short Entry')
if (shortIsActive)
strategy.exit(id = 'Short Exit', stop = bbMiddle, alert_message=messageExit)
//if (closeShortPosition)
//strategy.close(id = 'Short Close', alert_message=messageClose)
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
// PLOTS ===============================================================================================================
// TRADE WINDOW ========================================================================================================
bgcolor(color = inTradeWindow ? color.new(#089981,90):na, title = 'Time Window')
// EMA/SMA
var emafilterColor = color.new(color.white, 0)
plot(series=useEma? ema:na, title = 'EMA Filter', color = emafilterColor, linewidth = 2, style = plot.style_line)
// BOLLINGER BANDS
plot(series=bbUpper, title = "Upper Band", color = color.aqua)//, display = display.none)
plot(series=bbMiddle, title = "MA Band", color = color.red)//, display = display.none)
plot(series=bbLower, title = "Lower Band", color = color.aqua)//, display = display.none)
// PAINT BARS COLORS
bool bulls = (close[1] < bbUpper[1]) and (close > bbUpper)
bool bears = (close[1] > bbLower [1]) and (close < bbLower)
neutral_color = color.new(color.black, 100)
barcolors = bulls ? color.green : bears ? color.red : neutral_color
barcolor(barcolors)
// ======================================================================================================================