Auto Trailing stoploss By InvestYourAsset

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #260567 quote
    Harley82
    Participant
    Senior

    Buongiorno chiedo cortesemente di trascrivere se possibile, il codice di cui sopra che consentirebbe, tra l altro) di utilizzare indicatore di fornire segnali di buy/ sell.

    Grazie

    Cordiali saluti



    //@version=5

    indicator(“Auto Trailing SL By InvestYourAsset”, shorttitle=”Auto Trailing Stoploss by InvestYourAsset”, overlay=true)


    // Input parameters

    p = input(14, title=”ATR Period”)

    q = input(20, title=”Stop Period”)

    x = input(1.5, title=”Multiplier”)


    // Calculate ATR

    atr_value = ta.atr(p)


    // Calculate Initial High Stop and Initial Low Stop

    initial_high_stop = ta.highest(high, p) – x * atr_value

    initial_low_stop = ta.lowest(low, p) + x * atr_value


    // Calculate Short Stop and Long Stop

    short_stop = ta.highest(initial_high_stop, q)

    long_stop = ta.lowest(initial_low_stop, q)


    // Short Stoploss Hit signal

    short_stoploss_hit = ta.crossover(close, short_stop)


    // Long Stoploss Hit signal

    long_stoploss_hit = ta.crossunder(close, long_stop)


    // Long signal

    long_signal = ta.crossover(close, short_stop) and ta.crossover(close, long_stop)


    // Short signal

    short_signal = ta.crossunder(close, short_stop) and ta.crossunder(close, long_stop)


    // Plotting

    plot(short_stop, color=color.red, title=”Short Stop”)

    plot(long_stop, color=color.green, title=”Long Stop”)


    // Plot signals

    plotshape(series=short_stoploss_hit, title=”Short Stoploss Hit”, color=color.red, style=shape.triangleup, location=location.belowbar)

    plotshape(series=long_stoploss_hit, title=”Long Stoploss Hit”, color=color.green, style=shape.triangledown, location=location.abovebar)


    // Highlight signals

    bgcolor(long_signal ? color.new(color.green, 90) : na)

    bgcolor(short_signal ? color.new(color.red, 90) : na)


    #260595 quote
    Nicolas
    Keymaster
    Master

    Ciao, di seguito trovi il codice convertito dello script “auto trailing sl” che hai condiviso:

    // Auto Trailing SL - converti depuis Pine Script
    // Parametres
    p = 14  // ATR Period
    q = 20  // Stop Period
    x = 1.5 // Multiplier
    
    // ATR
    atrval = AverageTrueRange[p](close)
    
    // Stops initiaux
    inithighstop = Highest[p](high) - x * atrval
    initlowstop  = Lowest[p](low)  + x * atrval
    
    // Stops finaux
    shortstop = Highest[q](inithighstop)
    longstop  = Lowest[q](initlowstop)
    
    // Signaux de croisement
    shortstoplosskit = close crosses over shortstop
    longstoplosskit  = close crosses under longstop
    
    longsig  = close crosses over shortstop AND close crosses over longstop
    shortsig = close crosses under shortstop AND close crosses under longstop
    
    // Fleches sur signaux
    IF shortstoplosskit THEN
       DRAWARROWUP(barindex, low) COLOURED(255, 0, 0, 200)
    ENDIF
    
    IF longstoplosskit THEN
       DRAWARROWDOWN(barindex, high) COLOURED(0, 180, 0, 200)
    ENDIF
    
    // Fond de barre
    IF longsig THEN
       BACKGROUNDCOLOR(0, 200, 0, 220)
    ELSIF shortsig THEN
       BACKGROUNDCOLOR(200, 0, 0, 220)
    ENDIF
    
    RETURN shortstop COLOURED(255, 0, 0) AS "Short Stop", longstop COLOURED(0, 180, 0) AS "Long Stop"
    
    
    Iván González thanked this post
    auto-trailing-sl.png auto-trailing-sl.png
    #260613 quote
    Harley82
    Participant
    Senior

    Buongiorno, ringrazio per la tempestiva risposta. Sarà mia cura effettuare dei backtest per valutarne l efficacia,

    Grazie di nuovo.

    cordiali saluti


Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

TradingView to ProRealTime Translation Center

New Reply
Author
author-avatar
Harley82 @harley82 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by Harley82
2 weeks, 5 days ago.

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 04/26/2026
Status: Active
Attachments: 1 files
Logo Logo
Loading...