Stratégie de rupture SR


Date de création: 2024-05-15 16:30:14 Dernière modification: 2024-05-15 16:30:14
Copier: 1 Nombre de clics: 568
1
Suivre
1617
Abonnés

Stratégie de rupture SR

Aperçu

La stratégie SR Breakout Strategy est une stratégie de rupture de résistance de support basée sur l’indicateur Breakout Finder développé par LonesomeTheBlue. L’idée principale de la stratégie est de générer un signal d’achat ou de vente en déterminant si le prix de clôture a franchi le support ou la résistance. La configuration par défaut est basée sur la ligne K de 8 heures, mais il existe une configuration de paramètres supérieure sur la ligne K de 4 heures.

Principe de stratégie

  1. Les fonctions pivothigh et pivotlow sont utilisées pour calculer respectivement les hauts et les bas des périodes passées et sont stockées dans un tableau.
  2. Détermine si le cours de clôture actuel est supérieur à la résistance et, si c’est le cas, détermine une rupture du bullish, générant un signal de plus.
  3. Détermine si le cours de clôture actuel est en dessous du support, et si c’est le cas, détermine une rupture baissière, générant un signal de dépréciation.
  4. Après la génération du signal de transaction, le prix d’arrêt et le prix d’arrêt sont calculés en fonction du ratio de stop-loss et de stop-loss défini, et les ordres d’arrêt et de stop-loss correspondants sont définis.
  5. La distance de rupture correspondante est tracée en fonction de la direction de la rupture.

Avantages stratégiques

  1. La rupture du support-résistance est une stratégie de trading classique, avec une base de combat.
  2. Le support et la résistance sont calculés en utilisant les fonctions pivothigh et pivotlow, permettant de capturer avec une plus grande précision la situation de rupture.
  3. La structure du code de la stratégie est claire et peut être facilement retracée et optimisée en stockant les hauts et les bas dans un tableau.
  4. Le stop loss et le stop stop stop permettent de mieux contrôler le risque.

Risque stratégique

  1. Les stratégies de rupture de la résistance des supports ne fonctionnent pas bien dans les conditions de choc, et sont sujettes à de fréquentes fausses ruptures.
  2. Le ratio de stop-loss fixe peut ne pas s’adapter à différentes situations, ce qui entraîne un déséquilibre risque-bénéfice.
  3. Cette stratégie ne prend en compte que le facteur prix, sans prendre en compte d’autres indicateurs importants tels que le volume de transactions, ce qui pourrait laisser passer des signaux importants.

Orientation de l’optimisation de la stratégie

  1. L’introduction de plus d’indicateurs techniques, tels que le trafic, le MACD, etc., peut être envisagée pour améliorer l’exactitude et la fiabilité du signal.
  2. Pour l’arrêt et le freinage, on peut envisager d’utiliser un freinage mobile ou un freinage dynamique pour mieux s’adapter aux différentes situations.
  3. On peut envisager d’introduire des conditions de filtrage telles que le filtrage de tendance, le filtrage de la volatilité, etc. pour réduire les faux breakouts dans les conditions de choc.
  4. On peut envisager d’optimiser les positions de support et de résistance, par exemple en utilisant des cycles d’adaptation ou en introduisant des échelles de Fibonacci.

Résumer

La stratégie de rupture de SR est une stratégie de négociation basée sur l’idée classique de rupture de la résistance des supports, qui calcule les niveaux de support et de résistance à l’aide des fonctions pivothigh et pivotlow, et génère un signal de négociation en déterminant si le prix de clôture a franchi ces positions. L’avantage de cette stratégie réside dans la clarté de l’idée, la facilité de mise en œuvre et d’optimisation; il existe également des risques, tels que la mauvaise performance dans des conditions de choc et le risque que peut entraîner un taux de stop-loss fixe.

Code source de la stratégie
/*backtest
start: 2024-05-07 00:00:00
end: 2024-05-14 00:00:00
period: 10m
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/
// © LonesomeTheBlue © chanu_lev10k

//@version=5
strategy('SR Breakout Strategy', overlay=true, max_bars_back=500, max_lines_count=400)
prd = input.int(defval=5, title='Period', minval=2)
bo_len = input.int(defval=71, title='Max Breakout Length', minval=30, maxval=300)
cwidthu = input.float(defval=3., title='Threshold Rate %', minval=1., maxval=10) / 100
mintest = input.int(defval=2, title='Minimum Number of Tests', minval=1)
bocolorup = input.color(defval=color.blue, title='Breakout Colors', inline='bocol')
bocolordown = input.color(defval=color.red, title='', inline='bocol')
// lstyle = input.string(defval=line.style_solid, title='Line Style')
issl = input.bool(title='SL', inline='linesl1', group='Stop Loss / Take Profit:', defval=false)
slpercent = input.float(title=', %', inline='linesl1', group='Stop Loss / Take Profit:', defval=18.0, minval=0.0, step=0.1)
istp = input.bool(title='TP', inline='linetp1', group='Stop Loss / Take Profit:', defval=false)
tppercent = input.float(title=', %', inline='linetp1', group='Stop Loss / Take Profit:', defval=18.0, minval=0.0, step=0.1)

//width
lll = math.max(math.min(bar_index, 300), 1)
float h_ = ta.highest(lll)
float l_ = ta.lowest(lll)
float chwidth = (h_ - l_) * cwidthu

// check if PH/PL
ph = ta.pivothigh(prd, prd)
pl = ta.pivotlow(prd, prd)

//keep Pivot Points and their locations in the arrays
var phval = array.new_float(0)
var phloc = array.new_int(0)
var plval = array.new_float(0)
var plloc = array.new_int(0)

// keep PH/PL levels and locations
if bool(ph)
    array.unshift(phval, ph)
    array.unshift(phloc, bar_index - prd)
    if array.size(phval) > 1  // cleanup old ones
        for x = array.size(phloc) - 1 to 1 by 1
            if bar_index - array.get(phloc, x) > bo_len
                array.pop(phloc)
                array.pop(phval)

if bool(pl)
    array.unshift(plval, pl)
    array.unshift(plloc, bar_index - prd)
    if array.size(plval) > 1  // cleanup old ones
        for x = array.size(plloc) - 1 to 1 by 1
            if bar_index - array.get(plloc, x) > bo_len
                array.pop(plloc)
                array.pop(plval)

// check bullish cup
float bomax = na
int bostart = bar_index
num = 0
hgst = ta.highest(prd)[1]
if array.size(phval) >= mintest and close > open and close > hgst
    bomax := array.get(phval, 0)
    xx = 0
    for x = 0 to array.size(phval) - 1 by 1
        if array.get(phval, x) >= close
            break
        xx := x
        bomax := math.max(bomax, array.get(phval, x))
        bomax
    if xx >= mintest and open <= bomax
        for x = 0 to xx by 1
            if array.get(phval, x) <= bomax and array.get(phval, x) >= bomax - chwidth
                num += 1
                bostart := array.get(phloc, x)
                bostart
        if num < mintest or hgst >= bomax
            bomax := na
            bomax

// if not na(bomax) and num >= mintest
//     line.new(x1=bar_index, y1=bomax, x2=bostart, y2=bomax, color=bocolorup)
//     line.new(x1=bar_index, y1=bomax - chwidth, x2=bostart, y2=bomax - chwidth, color=bocolorup)
//     line.new(x1=bostart, y1=bomax - chwidth, x2=bostart, y2=bomax, color=bocolorup)
//     line.new(x1=bar_index, y1=bomax - chwidth, x2=bar_index, y2=bomax, color=bocolorup)

plotshape(not na(bomax) and num >= mintest, location=location.belowbar, style=shape.triangleup, color=bocolorup, size=size.small)
//alertcondition(not na(bomax) and num >= mintest, title='Breakout', message='Breakout')

// check bearish cup
float bomin = na
bostart := bar_index
num1 = 0
lwst = ta.lowest(prd)[1]
if array.size(plval) >= mintest and close < open and close < lwst
    bomin := array.get(plval, 0)
    xx = 0
    for x = 0 to array.size(plval) - 1 by 1
        if array.get(plval, x) <= close
            break
        xx := x
        bomin := math.min(bomin, array.get(plval, x))
        bomin
    if xx >= mintest and open >= bomin
        for x = 0 to xx by 1
            if array.get(plval, x) >= bomin and array.get(plval, x) <= bomin + chwidth
                num1 += 1
                bostart := array.get(plloc, x)
                bostart
        if num1 < mintest or lwst <= bomin
            bomin := na
            bomin

// if not na(bomin) and num1 >= mintest
//     line.new(x1=bar_index, y1=bomin, x2=bostart, y2=bomin, color=bocolordown)
//     line.new(x1=bar_index, y1=bomin + chwidth, x2=bostart, y2=bomin + chwidth, color=bocolordown)
//     line.new(x1=bostart, y1=bomin + chwidth, x2=bostart, y2=bomin, color=bocolordown)
//     line.new(x1=bar_index, y1=bomin + chwidth, x2=bar_index, y2=bomin, color=bocolordown)

plotshape(not na(bomin) and num1 >= mintest, location=location.abovebar, style=shape.triangledown, color=bocolordown, size=size.small)

//alertcondition(not na(bomin) and num1 >= mintest, title='Breakdown', message='Breakdown')
//alertcondition(not na(bomax) and num >= mintest or not na(bomin) and num1 >= mintest, title='Breakout or Breakdown', message='Breakout or Breakdown')

// Long Short conditions
longCondition = not na(bomax) and num >= mintest
if longCondition
    strategy.entry('Long', strategy.long)
shortCondition = not na(bomin) and num1 >= mintest
if shortCondition
    strategy.entry('Short', strategy.short)

// Entry price / Take Profit / Stop Loss
//entryprice = strategy.position_avg_price
entryprice = ta.valuewhen(condition=longCondition or shortCondition, source=close, occurrence=0)
pm = longCondition ? 1 : shortCondition ? -1 : 1 / math.sign(strategy.position_size)
takeprofit = entryprice * (1 + pm * tppercent * 0.01)
stoploss = entryprice * (1 - pm * slpercent * 0.01)
strategy.exit(id='Exit Long', from_entry='Long', stop=issl ? stoploss : na, limit=istp ? takeprofit : na, alert_message='Exit Long')
strategy.exit(id='Exit Short', from_entry='Short', stop=issl ? stoploss : na, limit=istp ? takeprofit : na, alert_message='Exit Short')