Conversion d’un code pour PRT

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #241972 quote
    PoupouillePoupouille
    Participant
    Average

    Bjr, serait-il possible de convertir le code ci-dessous pour pouvoir utiliser cet indicateur sur PRT ?
    L’indicateur se trouve ici => https://www.tradingview.com/script/3O0jn6h9-Dynamic-Trading-Strategy-with-Key-Levels-Entry-Exit-Management/
    Voici le code :

    Dynamic Trading Strategy with Key Levels, Entry/Exit Management

    //@version=5
    indicator(“Dynamic Trading Strategy with Key Levels, Entry/Exit Management”, overlay=true)

    // Input Parameters
    lookbackPeriod = input.int(20, “Lookback Period for Key Levels”)
    atrPeriod = input.int(14, “ATR Period”)
    atrMultiplierSL = input.float(1.5, “SL ATR Multiplier”)
    atrMultiplierTP1 = input.float(1.5, “TP1 ATR Multiplier”)
    atrMultiplierTP2 = input.float(2.0, “TP2 ATR Multiplier”)
    rewardToRisk = input.float(2.0, “Reward to Risk Ratio”)

    // ATR and Volume Calculation
    atr = ta.atr(atrPeriod)
    volumeSMA = ta.sma(volume, atrPeriod)

    // Key Levels Identification (Support & Resistance Zones)
    support = ta.lowest(low, lookbackPeriod)
    resistance = ta.highest(high, lookbackPeriod)
    supportBuffer = support – atr * 0.5
    resistanceBuffer = resistance + atr * 0.5

    // Define Bullish and Bearish Scenario Entry Ranges (Visualized with Boxes)
    var box bullishBox = na
    var box bearishBox = na

    // Bullish Scenario
    isBullishEntry = (close > supportBuffer) and (low volumeSMA)
    if isBullishEntry
    if na(bullishBox)
    bullishBox := box.new(left=bar_index – 10, top=support + atr * 0.5, right=bar_index + 10, bottom=support – atr * 0.5, border_color=color.green, bgcolor=color.new(color.green, 85))
    else
    box.set_left(bullishBox, bar_index – 10)
    box.set_right(bullishBox, bar_index + 10)
    box.set_top(bullishBox, support + atr * 0.5)
    box.set_bottom(bullishBox, support – atr * 0.5)

    // Bearish Scenario
    isBearishEntry = (close = resistance) and (volume > volumeSMA)
    if isBearishEntry
    if na(bearishBox)
    bearishBox := box.new(left=bar_index – 10, top=resistance + atr * 0.5, right=bar_index + 10, bottom=resistance – atr * 0.5, border_color=color.red, bgcolor=color.new(color.red, 85))
    else
    box.set_left(bearishBox, bar_index – 10)
    box.set_right(bearishBox, bar_index + 10)
    box.set_top(bearishBox, resistance + atr * 0.5)
    box.set_bottom(bearishBox, resistance – atr * 0.5)

    // Stop Loss and Take Profit Calculations for Bullish and Bearish Scenarios
    bullishSL = support – atr * atrMultiplierSL
    bullishTP1 = support + atr * rewardToRisk * atrMultiplierTP1
    bullishTP2 = support + atr * rewardToRisk * atrMultiplierTP2

    bearishSL = resistance + atr * atrMultiplierSL
    bearishTP1 = resistance – atr * rewardToRisk * atrMultiplierTP1
    bearishTP2 = resistance – atr * rewardToRisk * atrMultiplierTP2

    // Visualization for Bullish Scenario (TP1, TP2, SL Lines with Labels)
    var line bullishTP1Line = na
    var line bullishTP2Line = na
    var line bullishSLLine = na
    var label bullishTP1Label = na
    var label bullishTP2Label = na
    var label bullishSLLabel = na

    if isBullishEntry
    if na(bullishTP1Line)
    bullishTP1Line := line.new(bar_index – 10, bullishTP1, bar_index + 10, bullishTP1, color=color.green, width=2)
    else
    line.set_xy1(bullishTP1Line, bar_index – 10, bullishTP1)
    line.set_xy2(bullishTP1Line, bar_index + 10, bullishTP1)

    if na(bullishTP1Label)
    bullishTP1Label := label.new(bar_index + 10, bullishTP1, “TP1”, color=color.green, textcolor=color.white, yloc=yloc.price, style=label.style_label_right)
    else
    label.set_xy(bullishTP1Label, bar_index + 10, bullishTP1)

    if na(bullishTP2Line)
    bullishTP2Line := line.new(bar_index – 10, bullishTP2, bar_index + 10, bullishTP2, color=color.green, width=2)
    else
    line.set_xy1(bullishTP2Line, bar_index – 10, bullishTP2)
    line.set_xy2(bullishTP2Line, bar_index + 10, bullishTP2)

    if na(bullishTP2Label)
    bullishTP2Label := label.new(bar_index + 10, bullishTP2, “TP2”, color=color.green, textcolor=color.white, yloc=yloc.price, style=label.style_label_right)
    else
    label.set_xy(bullishTP2Label, bar_index + 10, bullishTP2)

    if na(bullishSLLine)
    bullishSLLine := line.new(bar_index – 10, bullishSL, bar_index + 10, bullishSL, color=color.red, width=2)
    else
    line.set_xy1(bullishSLLine, bar_index – 10, bullishSL)
    line.set_xy2(bullishSLLine, bar_index + 10, bullishSL)

    if na(bullishSLLabel)
    bullishSLLabel := label.new(bar_index + 10, bullishSL, “SL”, color=color.red, textcolor=color.white, yloc=yloc.price, style=label.style_label_right)
    else
    label.set_xy(bullishSLLabel, bar_index + 10, bullishSL)

    // Visualization for Bearish Scenario (TP1, TP2, SL Lines with Labels)
    var line bearishTP1Line = na
    var line bearishTP2Line = na
    var line bearishSLLine = na
    var label bearishTP1Label = na
    var label bearishTP2Label = na
    var label bearishSLLabel = na

    if isBearishEntry
    if na(bearishTP1Line)
    bearishTP1Line := line.new(bar_index – 10, bearishTP1, bar_index + 10, bearishTP1, color=color.red, width=2)
    else
    line.set_xy1(bearishTP1Line, bar_index – 10, bearishTP1)
    line.set_xy2(bearishTP1Line, bar_index + 10, bearishTP1)

    if na(bearishTP1Label)
    bearishTP1Label := label.new(bar_index + 10, bearishTP1, “TP1”, color=color.red, textcolor=color.white, yloc=yloc.price, style=label.style_label_right)
    else
    label.set_xy(bearishTP1Label, bar_index + 10, bearishTP1)

    if na(bearishTP2Line)
    bearishTP2Line := line.new(bar_index – 10, bearishTP2, bar_index + 10, bearishTP2, color=color.red, width=2)
    else
    line.set_xy1(bearishTP2Line, bar_index – 10, bearishTP2)
    line.set_xy2(bearishTP2Line, bar_index + 10, bearishTP2)

    if na(bearishTP2Label)
    bearishTP2Label := label.new(bar_index + 10, bearishTP2, “TP2”, color=color.red, textcolor=color.white, yloc=yloc.price, style=label.style_label_right)
    else
    label.set_xy(bearishTP2Label, bar_index + 10, bearishTP2)

    if na(bearishSLLine)
    bearishSLLine := line.new(bar_index – 10, bearishSL, bar_index + 10, bearishSL, color=color.green, width=2)
    else
    line.set_xy1(bearishSLLine, bar_index – 10, bearishSL)
    line.set_xy2(bearishSLLine, bar_index + 10, bearishSL)

    if na(bearishSLLabel)
    bearishSLLabel := label.new(bar_index + 10, bearishSL, “SL”, color=color.green, textcolor=color.white, yloc=yloc.price, style=label.style_label_right)
    else
    label.set_xy(bearishSLLabel, bar_index + 10, bearishSL)

    #241973 quote
    PoupouillePoupouille
    Participant
    Average

    Je vous remercie d’avance

    #242318 quote
    Iván GonzálezIván González
    Moderator
    Legend

    bonnes tardes. Ici, tu es :

    //----------------------------------------------------------//
    //PRC_Dynamic Strategy with Key Levels
    //version = 0
    //08.01.2025
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //----------------------------------------------------------//
    // inputs
    //----------------------------------------------------------//
    defparam drawonlastbaronly=true
    lookbackperiod=20
    atrperiod=14
    atrmulSL=1.5
    atrmulTP1=1.5
    atrmulTP2=2
    rewardtorisk=2
    //----------------------------------------------------------//
    // atr and volume calculation
    //----------------------------------------------------------//
    atr=averagetruerange[atrperiod](close)
    volumeSMA=average[atrperiod](volume)
    //----------------------------------------------------------//
    // key levels identification (support and resistance zones)
    //----------------------------------------------------------//
    support=lowest[lookbackperiod](low)
    resistance=highest[lookbackperiod](high)
    supportBuffer=support-atr*0.5
    resistanceBuffer=resistance+atr*0.5
    //----------------------------------------------------------//
    // Define Bullish and Bearish scenario entry ranges
    //----------------------------------------------------------//
    //Bullish scenario
    isBullishEntry=close>supportBuffer and low<=support and volume>volumeSMA
    
    if isBullishEntry then
    $suppx1[n+1]=barindex-10
    $suppx2[n+1]=barindex+10
    $suppy1[n+1]=support-atr*0.5
    $suppy2[n+1]=support+atr*0.5
    $bullishSL[n+1]=support-atr*atrmulSL
    $bullishTP1[n+1]=support+atr*rewardtorisk*atrmulTP1
    $bullishTP2[n+1]=support+atr*rewardtorisk*atrmulTP2
    n=n+1
    endif
    //Bearish scenario
    isBearishEntry=close<resistanceBuffer and high>=resistance and volume>volumeSMA
    
    if isBearishEntry then
    $resx1[t+1]=barindex-10
    $resx2[t+1]=barindex+10
    $resy1[t+1]=resistance-atr*0.5
    $resy2[t+1]=resistance+atr*0.5
    $bearishSL[t+1]=resistance+atr*atrmulSL
    $bearishTP1[t+1]=resistance-atr*rewardtorisk*atrmulTP1
    $bearishTP2[t+1]=resistance-atr*rewardtorisk*atrmulTP2
    t=t+1
    endif
    //----------------------------------------------------------//
    // Draw last support and resistance
    //----------------------------------------------------------//
    if islastbarupdate then
    //Support
    drawrectangle($suppx1[n],$suppy1[n],$suppx2[n],$suppy2[n])coloured("green")fillcolor("green",40)
    //Key Levels long
    drawsegment($suppx1[n],$bullishSL[n],$suppx2[n],$bullishSL[n])coloured("red")style(line,2)
    drawtext("SL",$suppx2[n],$bullishSL[n]+0.15*atr)coloured("red")
    drawsegment($suppx1[n],$bullishTP1[n],$suppx2[n],$bullishTP1[n])coloured("green")style(line,2)
    drawtext("TP1",$suppx2[n],$bullishTP1[n]+0.15*atr)coloured("green")
    drawsegment($suppx1[n],$bullishTP2[n],$suppx2[n],$bullishTP2[n])coloured("green")style(line,2)
    drawtext("TP2",$suppx2[n],$bullishTP2[n]+0.15*atr)coloured("green")
    
    //Resistance
    drawrectangle($resx1[t],$resy1[t],$resx2[t],$resy2[t])coloured("red")fillcolor("red",40)
    //Key Levels short
    drawsegment($resx1[t],$bearishSL[t],$resx2[t],$bearishSL[t])coloured("red")style(line,2)
    drawtext("SL",$resx2[t],$bearishSL[t]+0.15*atr)coloured("red")
    drawsegment($resx1[t],$bearishTP1[t],$resx2[t],$bearishTP1[t])coloured("green")style(line,2)
    drawtext("TP1",$resx2[t],$bearishTP1[t]+0.15*atr)coloured("green")
    drawsegment($resx1[t],$bearishTP2[t],$resx2[t],$bearishTP2[t])coloured("green")style(line,2)
    drawtext("TP2",$resx2[t],$bearishTP2[t]+0.15*atr)coloured("green")
    endif
    //----------------------------------------------------------//
    return
    #242321 quote
    PoupouillePoupouille
    Participant
    Average

    Merci beaucoup, ça fonctionne, top.
    Bonne soirée

    #242323 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    @Poupouille

    Vous n’êtes que deux, merci de ne pas citer si ce n’est pas vraiment difficile de dire qui a écrit quoi.
    Cela aidera à garder les sujets plus courts et plus lisibles.
    Merci 🙂

    #242324 quote
    PoupouillePoupouille
    Participant
    Average

    Pas faux.
    Merci

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Conversion d’un code pour PRT


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
Poupouille @poupouille Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by PoupouillePoupouille
1 year, 8 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 12/30/2024
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...