
Strategi ini dikenali sebagai strategi pengesanan trend BollingerBands, yang menggunakan indikator BollingerBands untuk menentukan trend harga, dan masuk untuk melakukan penembusan tambahan apabila harga menembusi saluran BollingerBands. Ia menggabungkan penapis linear untuk menentukan arah trend apabila penembusan berlaku, dan dengan itu membuat keputusan untuk melakukan penembusan tambahan.
Strategi ini bergantung kepada indikator BollingerBands untuk menentukan trend harga dan lokasi titik masuk. BollingerBands terdiri daripada tiga garis:
Apabila harga menembusi ke atas dari bawah, ia dianggap sedang membentuk trend bullish; apabila harga menembusi ke bawah dari atas, ia dianggap sedang membentuk trend bearish.
Secara khusus, logik strategi adalah:
Untuk menyaring penembusan palsu, strategi memasukkan penghakiman garis rata-rata. Hanya apabila harga penutupan menembusi Bands pada masa yang sama, dan menembusi garis rata-rata, masuk akan dicetuskan.
Exponential Moving Average digunakan di sini sebagai penunjuk garis purata.
Secara ringkasnya, strategi ini menilai perubahan trend dengan cara berikut:
Selepas masuk, hentikan untuk mengikuti garis tengah. Apabila harga menyentuh garis tengah, keluar dari hentikan.
Strategi ini mempunyai kelebihan utama:
Walaupun ada kelebihan, strategi ini mempunyai risiko:
Untuk mengawal risiko di atas, anda boleh mengoptimumkan:
Berdasarkan analisis risiko di atas, strategi ini dapat dioptimumkan dengan lebih lanjut dalam aspek berikut:
Optimumkan parameterDengan menggunakan kaedah yang lebih sistematik, seperti algoritma genetik, mencari kombinasi terbaik antara band dan parameter rata-rata, menjadikan strategi lebih stabil dan menguntungkan.
Pengoptimuman Stop Loss: Uji pelbagai kaedah penutupan kerugian, seperti penutupan ATR, penutupan pengesanan, dan lain-lain, untuk menentukan mekanisme penutupan kerugian yang terbaik.
Optimasi penapisCuba tambahkan indikator lain seperti RSI, KD dan lain-lain sebagai syarat penapisan tambahan, mengurangkan kebarangkalian isyarat palsu dan meningkatkan kadar keuntungan.
Syarat kemasukan yang lebih baikMenambah faktor pertimbangan lain seperti penilaian trend, VOLUME yang tidak aktif, pemilihan masa masuk yang ketat, mengurangkan kedudukan yang tidak perlu.
Pembelajaran Mesin: Mengumpul lebih banyak data sejarah, menggunakan model pembelajaran mendalam seperti LSTM, RNN untuk memodelkan, dan menggunakan AI untuk menentukan tempat terbaik untuk masuk dan keluar.
Pengurusan dinamik risiko dan keuntunganMenambah Stop Loss Rasio Tetap, Meningkatkan Stop Loss Selepas Matlamat Keuntungan, Menguruskan Risiko dan Hasil Secara Dinamis.
Dengan mengoptimumkan aspek-aspek di atas, strategi ini dapat meningkatkan indikator seperti kestabilan, kadar pulangan, dan keupayaan untuk mengawal risiko secara menyeluruh, menjadi strategi algoritma yang boleh diperdagangkan di pasaran.
Secara keseluruhannya, strategi pengesanan trend BollingerBands yang menggunakan indikator Bands dan trend harga penilaian rata-rata, memasuki ketika titik titik penting, adalah jenis strategi pengesanan trend. Ia mempunyai keunggulan seperti kepastian penghakiman, ringkas logik, mudah dilaksanakan, dan juga terdapat beberapa optimasi parameter, cara menghentikan kerugian.
/*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)
// ======================================================================================================================