
この策略は, BollingerBands トレンド追跡策略と呼ばれています.これは,BollingerBands指数を使用して価格の傾向を判断し,価格がBollingerBands通路を破るときに入場し,多空を行う.これは,均線フィルターと組み合わせて,突破が発生したときにトレンドの方向を判断し,多空を行うことを決定します.
この戦略は,主に価格の傾向と位置入場点を判断するBollingerBands指標に依存している.BollingerBandsは3つの線で構成されています.
価格が下線から上線を突破すると,看板トレンドが形成されていると考えられる.価格が上線から下線を突破すると,下向きトレンドが形成されていると考えられる.この2つの突破が発生する際には,入場策は空調を余儀なくする.
具体的には,戦略の論理は次のとおりです.
偽のブレイクをフィルターするために,策略は平均線判断を加える. 閉盘価格がBandsを突破すると同時に平均線を突破した場合のみ,入場を誘発する.
平均線として指数関数移動平均を使用しています.
この戦略は,トレンドブレイクを以下のように判断します.
入場後,ストップは中線を追跡する. 価格が中線に再触したとき,ストップを退出する.
この戦略の利点は以下の通りです.
この戦略には利点があるものの,以下のリスクがあります.
上記のリスクを制御するために,以下の方法で最適化できます.
上記のリスク分析から,この戦略は以下のような点でさらに最適化できます.
パラメータ最適化: 遺伝的アルゴリズムなどのより体系的な方法によって,バンドと平均線パラメータの最適な組み合わせを探し,戦略をより安定的かつ収益性のあるものにする.
ストップ・ロスト・最適化: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)
// ======================================================================================================================