La stratégie de suivi de tendance multi-indicateur avec stop loss et take profit intègre des indicateurs tels que EMA, MACD, OBV et PSAR pour déterminer la direction de la tendance, et définit un stop loss et un profit après avoir entré dans les transactions pour contrôler les risques.
Déterminer la direction de la tendance: lorsque l'EMA, le MACD, l'OBV et le PSAR sont alignés pour donner des signaux haussiers ou baissiers.
Règles d'entrée: long sur les signaux de taureaux, court sur les signaux d'ours.
Stop-loss/take profit: définissez le stop-loss et le take profit pour chaque transaction en fonction des niveaux de PSAR après l'entrée.
Règles de sortie: fermeture des positions lorsque le stop loss ou le take profit est déclenché.
L'avantage de cette stratégie est l'utilisation de plusieurs indicateurs pour la génération de signaux à haute probabilité, tandis que les règles de stop loss / take profit contrôlent activement les risques tout en bloquant les bénéfices.
Plusieurs indicateurs combinés pour des signaux à forte probabilité
L'établissement de crédit est un établissement de crédit.
Prise de profit/arrêt de perte basée sur les niveaux de PSAR
Optimisation flexible des indicateurs et paramètres
Bénéfices soutenus dans les tendances
Combinaison complexe de plusieurs indicateurs
Risques potentiels de décalage du signal
Attention aux retours en arrière.
Des tests et une optimisation constants des paramètres sont nécessaires
La stratégie de suivi de tendance multi-indicateur avec stop loss et take profit améliore globalement le trading de tendance en améliorant la précision et la gestion active des risques.
/*backtest start: 2023-08-15 00:00:00 end: 2023-09-14 00:00:00 period: 1h basePeriod: 15m 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/ // © exlux99 //@version=4 strategy("Scalping FOrex full strategy with risk management",overlay=true,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.cash_per_contract ,commission_value=0.00005) //VOLUME o shortlen = input(1, minval=1, title = "Short Length OBV") longlen = input(8, minval=1, title = "Long Length OBV") upColor = #2196F3//input(#2196F3, "Color Up") dnColor = #6B1599//input(#6B1599, "Color Down") f_normGradientColor(_series, _crossesZero, _colorNormLen, _dnColor, _upColor) => _dnValue = _crossesZero?-100:0 _mult = 0.0 _lowest = lowest(_colorNormLen) _highest = highest(_colorNormLen) _diff1 = close - _lowest _diff2 = _highest - _lowest if _diff2 > 0 _mult := _diff1 / _diff2 * 100 color.from_gradient(sign(_series) * _mult, _dnValue, 100, _dnColor, _upColor) shorta = ema(volume, shortlen) longa = ema(volume, longlen) osc = 100 * (shorta - longa) / longa start = input(0.1, title="PSAR START") increment = input(0.05,title="PSAR INC") maximum = input(0.3, title="PSAR MAX") // multitp=input(1) // multisl=input(1) var bool uptrend = na var float EP = na var float SAR = na var float AF = start var float nextBarSAR = na if bar_index > 0 firstTrendBar = false SAR := nextBarSAR if bar_index == 1 float prevSAR = na float prevEP = na lowPrev = low[1] highPrev = high[1] closeCur = close closePrev = close[1] if closeCur > closePrev uptrend := true EP := high prevSAR := lowPrev prevEP := high else uptrend := false EP := low prevSAR := highPrev prevEP := low firstTrendBar := true SAR := prevSAR + start * (prevEP - prevSAR) if uptrend if SAR > low firstTrendBar := true uptrend := false SAR := max(EP, high) EP := low AF := start else if SAR < high firstTrendBar := true uptrend := true SAR := min(EP, low) EP := high AF := start if not firstTrendBar if uptrend if high > EP EP := high AF := min(AF + increment, maximum) else if low < EP EP := low AF := min(AF + increment, maximum) if uptrend SAR := min(SAR, low[1]) if bar_index > 1 SAR := min(SAR, low[2]) else SAR := max(SAR, high[1]) if bar_index > 1 SAR := max(SAR, high[2]) nextBarSAR := SAR + AF * (EP - SAR) // if barstate.isconfirmed // if uptrend // strategy.entry("ParSE", strategy.short, stop=nextBarSAR, comment="ParSE") // strategy.cancel("ParLE") // else // strategy.entry("ParLE", strategy.long, stop=nextBarSAR, comment="ParLE") // strategy.cancel("ParSE") //plot(SAR, style=plot.style_cross, linewidth=3, color=color.orange) psarshort = close- SAR psarlong= SAR-close lena = input(200, minval=1, title="Length EMA") srca = input(close, title="Source") out = ema(srca, lena) fast_length = input(title="Fast Length MACD", type=input.integer, defval=12) slow_length = input(title="Slow Length MACD", type=input.integer, defval=25) src = input(title="Source", type=input.source, defval=close) signal_length = input(title="Signal Smoothing MACD", type=input.integer, minval = 1, maxval = 50, defval = 9) sma_source = input(title="Simple MA (Oscillator)", type=input.bool, defval=true) sma_signal = input(title="Simple MA (Signal Line)", type=input.bool, defval=true) // Calculating fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length) slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length) macd = fast_ma - slow_ma signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length) hist = macd - signal long = hist[1]<0 and hist > 0 and close > out and uptrend and osc < 0 short = hist[1]>0 and hist< 0 and close < out and not uptrend and osc >0 // ------------------------- Strategy Logic --------------------------------- // var longOpeneds = false var shortOpeneds = false var int timeOfBuys = na var float tpLong = na var float slLong = na var int entrys = na longConditions = long and not longOpeneds and entrys<100 if longConditions longOpeneds := true timeOfBuys := time tpLong := close+ (psarshort) //* multitp) slLong := close- (psarshort)//*multisl) entrys:=entrys+1 tpLongTrigger = (longOpeneds[1] and (crossover(close, tpLong) or crossover( high,tpLong))) slLongTrigger = (longOpeneds[1] and (crossunder(close, slLong) or crossunder( low,slLong))) longExitSignals = slLongTrigger or tpLongTrigger or short exitLongConditions = longOpeneds[1] and longExitSignals if exitLongConditions longOpeneds := false timeOfBuys := na tpLong := na slLong := na if(short) entrys:=0 //short // ------------------------- Strategy Logic --------------------------------- // var longOpenedss = false // var shortOpeneds = false var int timeOfBuyss = na var float tpLongs = na var float slLongs = na var int entry = na longConditionss = short and not longOpenedss and entry<100 if longConditionss longOpenedss := true timeOfBuyss := time tpLongs := close- (psarlong)//*multitp ) slLongs := close+ (psarlong)//*multisl) entry:=1 tpLongTriggers = (longOpenedss[1] and ( crossunder(close, tpLongs) or crossunder( low,tpLongs))) slLongTriggers = (longOpenedss[1] and (crossover(close, slLongs) or crossover( high,slLongs))) longExitSignalss = slLongTriggers or tpLongTriggers or long exitLongConditionss = longOpenedss[1] and longExitSignalss if exitLongConditionss longOpenedss := false timeOfBuyss := na tpLongs := na slLongs := na if(long) entry:=0 longEntry=input(true) shortEntry=input(true) if(longEntry) strategy.entry("long",1,when=longConditions) strategy.close('long',when=exitLongConditions) if(shortEntry) strategy.entry("short",0,when=longConditionss) strategy.close("short",when=exitLongConditionss)