
Cette stratégie est une stratégie de trading quantitatif basée sur une rupture de la ceinture de Brin, utilisant une courbe supérieure de 3 fois l’écart standard et une courbe inférieure de 1 fois l’écart standard, tout en combinant la moyenne mobile à 100 jours comme courbe intermédiaire. La stratégie est principalement conçue pour capturer les tendances à long terme en détectant les ruptures de prix et en utilisant les ruptures de prix comme signal d’arrêt.
Le principe central de la stratégie est basé sur les caractéristiques statistiques de la ceinture de Brin. L’écart standard de 3 fois est utilisé dans la voie supérieure, ce qui signifie que la probabilité de rupture de la voie supérieure n’est que de 0,15% dans le cas d’une distribution normale, de sorte que la formation d’une tendance significative est souvent annoncée lorsque la rupture se produit.
Il s’agit d’une stratégie de suivi de tendance conçue de manière rationnelle et logique. Grâce aux caractéristiques statistiques des bandes de blur et aux caractéristiques de suivi de tendance des moyennes mobiles, il est possible de capturer efficacement des opportunités de percée importantes sur le marché. Bien qu’il existe un certain risque de retrait, il a toujours une bonne valeur pratique grâce à un réglage et un contrôle des risques raisonnables.
/*backtest
start: 2024-11-12 00:00:00
end: 2024-12-11 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MounirTrades007
// @version=6
strategy("Bollinger Bands", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=200)
// Get user input
var g_bb = "Bollinger Band Settings"
upperBandSD = input.float(title="Upper Band Std Dev", defval=3.0, tooltip="Upper band's standard deviation multiplier", group=g_bb)
lowerBandSD = input.float(title="Lower Band Std Dev", defval=1.0, tooltip="Lower band's standard deviation multiplier", group=g_bb)
maPeriod = input.int(title="Middle Band MA Length", defval=100, tooltip="Middle band's SMA period length", group=g_bb)
var g_tester = "Backtester Settings"
drawTester = input.bool(title="Draw Backtester", defval=true, group=g_tester, tooltip="Turn on/off inbuilt backtester display")
// Get Bollinger Bands
[bbIgnore1, bbHigh, bbIgnore2] = ta.bb(close, maPeriod, upperBandSD)
[bbMid, bbIgnore3, bbLow] = ta.bb(close, maPeriod, lowerBandSD)
// Prepare trade persistent variables
drawEntry = false
drawExit = false
// Detect bollinger breakout
if close > bbHigh and barstate.isconfirmed and strategy.position_size == 0
drawEntry := true
strategy.entry(id="Trade", direction=strategy.long)
alert("Bollinger Breakout Detected for " + syminfo.ticker, alert.freq_once_per_bar_close)
// Detect bollinger sell signal
if close < bbLow and barstate.isconfirmed and strategy.position_size != 0
drawExit := true
strategy.close(id="Trade")
alert("Bollinger Exit detected for " + syminfo.ticker, alert.freq_once_per_bar_close)
// Draw bollinger bands
plot(bbMid, color=color.blue, title="Middle SMA")
plot(bbHigh, color=color.green, title="Upper Band")
plot(bbLow, color=color.red, title="Lower Band")
// Draw signals
plotshape(drawEntry, style=shape.triangleup, color=color.green, location=location.belowbar, size=size.normal, title="Buy Signal")
plotshape(drawExit, style=shape.xcross, color=color.red, location=location.belowbar, size=size.normal, title="Sell Signal")
// // =============================================================================
// // START BACKTEST CODE
// // =============================================================================
// // Prepare stats table
// var table testTable = table.new(position.top_right, 2, 2, border_width=1)
// f_fillCell(_table, _column, _row, _title, _value, _bgcolor, _txtcolor) =>
// _cellText = _title + "\n" + _value
// table.cell(_table, _column, _row, _cellText, bgcolor=_bgcolor, text_color=_txtcolor)
// // Draw stats table
// var bgcolor = color.black
// if barstate.islastconfirmedhistory
// if drawTester
// dollarReturn = strategy.equity - strategy.initial_capital
// f_fillCell(testTable, 0, 0, "Total Trades:", str.tostring(strategy.closedtrades), bgcolor, color.white)
// f_fillCell(testTable, 0, 1, "Win Rate:", str.tostring(strategy.wintrades / strategy.closedtrades * 100, "##.##") + "%", bgcolor, color.white)
// f_fillCell(testTable, 1, 0, "Equity:", "$" + str.tostring(strategy.equity, "###,###.##"), bgcolor, color.white)
// f_fillCell(testTable, 1, 1, "Return:", str.tostring((strategy.netprofit / strategy.initial_capital) * 100, "##.##") + "%", dollarReturn > 0 ? color.green : color.red, color.white)
// // =============================================================================
// // END BACKTEST CODE
// // =============================================================================