Conversion Pine Script Tradingwiew en PRT

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #225352 quote
    larouedegannlarouedegann
    Participant
    Master

    Bonjour à tous,

    Ci-joint le pine script de tradeforopp de tradingwiew.

    Ne connaissant rien en pine script, si un informaticien pourrait aider

    merci

    /@version=5
    indicator("Protected Highs & Lows [TFO]", "Protected Highs & Lows [TFO]", true, max_lines_count = 500, max_labels_count = 500)
    
    var g_STR = "Structure"
    ps = input.int(1, "Pivot Strength", group = g_STR)
    color_trend = input.bool(true, "Trend Candles", inline = "TREND", group = g_STR)
    show_labels = input.bool(true, "Show Structure Labels", inline = "MSS", group = g_STR)
    label_type = input.string("MSS", "", options = ['MSS', 'BOS', 'All'], inline = "MSS", group = g_STR)
    
    var g_PHL = "Protected Highs & Lows"
    show_phl = input.bool(true, "Show Protected Highs & Lows", inline = "PHL", group = g_PHL)
    trail_phl = input.bool(true, "Show Protected Trail", inline = "TRAIL", group = g_PHL)
    trail_width = input.int(2, "", inline = "TRAIL", group = g_PHL)
    
    ph_color = input.color(color.red, "", inline = "PHL", group = g_PHL)
    pl_color = input.color(color.blue, "", inline = "PHL", group = g_PHL)
    
    bull_color = input.color(color.teal, "", inline = "TREND", group = g_STR)
    bear_color = input.color(color.red, "", inline = "TREND", group = g_STR)
    
    var bool bull = na
    
    var float trail_price = na
    var color trail_color = na
    
    var ph = array.new_float()
    var pl = array.new_float()
    
    var pht = array.new_int()
    var plt = array.new_int()
    
    var float last_high = na
    var float last_low = na
    
    var int last_high_idx = na
    var int last_low_idx = na
    
    var float track_high = na
    var float track_low = na
    
    var int track_high_idx = na
    var int track_low_idx = na
    
    type dwg
        label[] _label
        label[] _phl
        line[] _line
        bool[] _bull
    
    method dwg_add(dwg d, label LB, label PHL, line LN, bool BL) =>
        d._label.unshift(LB)
        d._phl.unshift(PHL)
        d._line.unshift(LN)
        d._bull.unshift(BL)
    
    clear_all() =>
        pl.clear()
        plt.clear()    
        ph.clear()
        pht.clear()
    
    if ta.pivotlow(low, ps, ps) and pl.size() == 0
        pl.unshift(low[ps])
        plt.unshift(time[ps])
    
        if na(last_low)
            last_low := low[ps]
            last_low_idx := bar_index - ps
        else
            if low[ps] < last_low
                last_low := low[ps]
                last_low_idx := bar_index - ps
    if ta.pivothigh(high, ps, ps) and ph.size() == 0
        ph.unshift(high[ps])
        pht.unshift(time[ps])
        
        if na(last_high)
            last_high := high[ps]
            last_high_idx := bar_index - ps
        else
            if high[ps] > last_high
                last_high := high[ps]
                last_high_idx := bar_index - ps
        
    if (high[ps] > track_high or na(track_high) or last_low_idx >= track_high_idx) and not na(ta.pivothigh(high, ps, ps))
        track_high := high[ps]
        track_high_idx := bar_index - ps
    if (low[ps] < track_low or na(track_low) or last_high_idx >= track_low_idx) and not na(ta.pivotlow(low, ps, ps))
        track_low := low[ps]
        track_low_idx := bar_index - ps
    
    bos_bear = false
    bos_bull = false
    mss_bear = false
    mss_bull = false
    change = false
    
    var dwgs = dwg.new(array.new_label(), array.new_label(), array.new_line(), array.new_bool())
    
    if ph.size() > 0 
        if close > ph.get(0)
            label _label = na
            label _phl = na
    
            if show_labels
                save = false
                if label_type == 'MSS' and not bull
                    save := true
                else if label_type == 'BOS' and bull
                    save := true
                else if label_type == 'All'
                    save := true
                if save    
                    _label := label.new(math.floor(math.avg(time, pht.get(0))), ph.get(0), bull ? "BOS" : "MSS", xloc = xloc.bar_time, style = label.style_label_down, color = #ffffff00, textcolor = na)
    
            if bull
                bos_bull := true
            else
                mss_bull := true
    
            _line = line.new(pht.get(0), ph.get(0), time, ph.get(0), color = na, xloc = xloc.bar_time, style = line.style_dashed)
            bull := true
            change := true
    
            clear_all()
    
            if not na(track_low)
                if show_phl
                    _phl := label.new(time[bar_index - track_low_idx], track_low, "▲", xloc = xloc.bar_time, style = label.style_label_up, textcolor = na, color = #ffffff00)
    
                pl.unshift(track_low)
                plt.unshift(time[bar_index - track_low_idx])
                last_high := na
    
            dwgs.dwg_add(_label, _phl, _line, bull)
    
    if pl.size() > 0
        if close < pl.get(0)
            label _label = na
            label _phl = na
    
            if show_labels
                save = false
                if label_type == 'MSS' and bull
                    save := true
                else if label_type == 'BOS' and not bull
                    save := true
                else if label_type == 'All'
                    save := true
                if save    
                    _label := label.new(math.floor(math.avg(time, plt.get(0))), pl.get(0), not bull ? "BOS" : "MSS", xloc = xloc.bar_time, style = label.style_label_up, color = #ffffff00, textcolor = na)
    
            if not bull
                bos_bear := true
            else
                mss_bear := true
    
            _line = line.new(plt.get(0), pl.get(0), time, pl.get(0), color = na, xloc = xloc.bar_time, style = line.style_dashed)
            bull := false
            change := true
                    
            clear_all()
    
            if not na(track_high)
                if show_phl
                    _phl := label.new(time[bar_index - track_high_idx], track_high, "▼", xloc = xloc.bar_time, style = label.style_label_down, textcolor = na, color = #ffffff00)
    
                ph.unshift(track_high)
                pht.unshift(time[bar_index - track_high_idx])                
                last_low := na
                
            dwgs.dwg_add(_label, _phl, _line, bull)
    
    if change[1]
        if bos_bear[1] or mss_bear[1]
            trail_price := track_high
            trail_color := ph_color
        else if bos_bull[1] or mss_bull[1]
            trail_price := track_low
            trail_color := pl_color
            
        _bull = dwgs._bull.get(0)
        dwgs._label.get(0).set_textcolor(_bull ? bull_color : bear_color)
        dwgs._phl.get(0).set_textcolor(_bull ? pl_color : ph_color)
        dwgs._line.get(0).set_color(_bull ? bull_color : bear_color)
    
    barcolor(color_trend ? (bull ? bull_color : bear_color) : na)
    
    plot(trail_phl ? trail_price : na, color = trail_color, linewidth = trail_width)
    
    alertcondition(bos_bear[1] or bos_bull[1], "BOS Any")
    alertcondition(mss_bear[1] or mss_bull[1], "MSS Any")
    
    alertcondition(bos_bear[1], "BOS Bear")
    alertcondition(bos_bull[1], "BOS Bull")
    
    alertcondition(mss_bear[1], "MSS Bear")
    alertcondition(mss_bull[1], "MSS Bull")
    Capture-decran-2023-12-16-205743.png Capture-decran-2023-12-16-205743.png
    #234047 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Mieux vaut tard que jamais 🙂

    //-----------------------------------------------------------//
    //PRC_Protected Highs & Lows
    //version = 0
    //18.06.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-----------------------------------------------------------//
    //-----Inputs------------------------------------------------//
    ps = 1
    src1 = low
    src2 = high
    showLabels=1
    labelType=3 //1=MSS 2=BOS 3=All
    showphl=1
    atr=averagetruerange[14](close)
    coef=0.45
    //-----------------------------------------------------------//
    once lastlow=0
    once lastlowidx=0
    once lasthigh=0
    once lasthighidx=0
    once trackhigh=0
    once trackhighidx=0
    once tracklow=0
    once tracklowidx=0
    //-----------------------------------------------------------//
    //-----Pivots low--------------------------------------------//
    if src1 > src1[ps] and lowest[ps](src1) > src1[ps] and src1[ps] < lowest[ps](src1)[ps+1] and not isset($pl[0]) then
    $pivotl[t+1]=src1[ps]
    t=t+1
    
    $pl[0]=src1[ps]
    $plx[0] = barindex[ps]
    
    pPricelow=high[ps]
    pIdx=barindex[ps]
    pBull=0
    pValidlow=0
    
    if lastlow=0 then
    lastlow = low[ps]
    lastlowidx = barindex[ps]
    else
    if low[ps] < lastlow then
    lastlow = low[ps]
    lastlowidx = barindex[ps]
    endif
    endif
    
    //drawpoint(barindex[ps],src1[ps],2)coloured("blue",150)
    
    endif
    //-----------------------------------------------------------//
    //-----Pivots high-------------------------------------------//
    if src2 < src2[ps] and highest[ps](src2)<src2[ps] and src2[ps]>highest[ps](src2)[ps+1] and not isset($ph[0]) then
    
    $pivoth[z+1]=src2[ps]
    z=z+1
    
    $ph[0]=src2[ps]
    $phx[0] = barindex[ps]
    
    pPricehigh=low[ps]
    pIdx=barindex
    pBull=1
    pValidhigh=0
    
    if lasthigh=0 then
    lasthigh = high[ps]
    lasthighidx = barindex[ps]
    else
    if high[ps] > lasthigh then
    lasthigh = high[ps]
    lasthighidx = barindex[ps]
    endif
    endif
    
    //drawpoint(barindex[ps],src2[ps],2)coloured("red",150)
    endif
    //-----------------------------------------------------------//
    if pBull then
    if close<pPricehigh and pValidhigh=0 then
    pValidhigh=1
    endif
    else
    if close>pPricehigh and pValidhigh=0 then
    pValidhigh=1
    endif
    endif
    
    if pBull then
    if close<pPricelow and pValidlow=0 then
    pValidlow=1
    endif
    else
    if close>pPricelow and pValidlow=0 then
    pValidlow=1
    endif
    endif
    //-----------------------------------------------------------//
    if (high[ps]>trackHigh or trackhigh=0 or lastlowidx>=trackHighidx) and isset($ph[0]) and pValidlow then
    trackhigh=high[ps]
    trackhighidx=barindex[ps]
    endif
    
    if (low[ps]<tracklow or tracklow=0 or lasthighidx>=tracklowidx) and isset($pl[0]) and pValidhigh then
    tracklow=low[ps]
    tracklowidx=barindex[ps]
    endif
    //-----------------------------------------------------------//
    bosbear=0
    bosbull=0
    mssbear=0
    mssbull=0
    change=0
    
    if isset($ph[0]) then
    if close > $ph[0] then
    if showLabels then
    if labelType=1 and not bull then
    drawtext("MSS",(barindex+$phx[0])/2,$ph[0]+coef*atr)coloured("green")
    drawsegment(barindex,$ph[0],$phx[0],$ph[0])style(dottedline)
    elsif labelType=2 and bull then
    drawtext("BOS",(barindex+$phx[0])/2,$ph[0]+coef*atr)coloured("green")
    drawsegment(barindex,$ph[0],$phx[0],$ph[0])style(dottedline)
    elsif labelType=3 and not bull then
    drawtext("MSS",(barindex+$phx[0])/2,$ph[0]+coef*atr)coloured("green")
    drawsegment(barindex,$ph[0],$phx[0],$ph[0])style(dottedline)
    elsif labelType=3 and bull then
    drawtext("BOS",(barindex+$phx[0])/2,$ph[0]+coef*atr)coloured("green")
    drawsegment(barindex,$ph[0],$phx[0],$ph[0])style(dottedline)
    endif
    endif
    
    if bull then
    bosbull=1
    else
    mssbull=1
    endif
    
    bull=1
    change=1
    
    unset($ph)
    unset($phx)
    unset($pl)
    unset($plx)
    
    if tracklow>0 then
    if showphl then
    drawtext("▲",barindex[barindex-tracklowidx],tracklow)
    endif
    $pl[0]=tracklow
    $plx[0]=barindex[barindex-tracklowidx]
    lasthigh=0
    endif
    endif
    endif
    
    if isset($pl[0]) then
    if close < $pl[0] then
    
    if showLabels then
    if labelType=1 and bull then
    drawtext("MSS",(barindex+$plx[0])/2,$pl[0]-coef*atr)coloured("green")
    drawsegment(barindex,$pl[0],$plx[0],$pl[0])style(dottedline)
    elsif labelType=2 and not bull then
    drawtext("BOS",(barindex+$plx[0])/2,$pl[0]-coef*atr)coloured("green")
    drawsegment(barindex,$pl[0],$plx[0],$pl[0])style(dottedline)
    elsif labelType=3 and not bull then
    drawtext("BOS",(barindex+$plx[0])/2,$pl[0]-coef*atr)coloured("green")
    drawsegment(barindex,$pl[0],$plx[0],$pl[0])style(dottedline)
    elsif labelType=3 and bull then
    drawtext("MSS",(barindex+$plx[0])/2,$pl[0]-coef*atr)coloured("green")
    drawsegment(barindex,$pl[0],$plx[0],$pl[0])style(dottedline)
    endif
    endif
    
    if not bull then
    bosbear=1
    else
    mssbear=1
    endif
    
    bull=0
    change=1
    
    unset($ph)
    unset($phx)
    unset($pl)
    unset($plx)
    
    if trackhigh>0 then
    if showphl then
    drawtext("▼",barindex[barindex-trackhighidx],trackhigh)
    endif
    $ph[0]=trackhigh
    $phx[0]=barindex[barindex-trackhighidx]
    lastlow=0
    endif
    endif
    endif
    //-----------------------------------------------------------//
    if change[1] then
    if bosbear[1] or mssbear[1] then
    trailprice=trackhigh
    r=255
    b=0
    elsif bosbull[1] or mssbull[1] then
    trailprice=tracklow
    r=0
    b=255
    endif
    endif
    //-----------------------------------------------------------//
    return trailprice coloured(r,0,b)style(line,2)
    
    #234054 quote
    jacquesgermainjacquesgermain
    Participant
    Veteran

    hello

    une erreur ligne 87 :  pValidhigh=1#PH&F TFO

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

    problèmes de copier-coller

    ligne 87 :  pValidhigh=1

    déjà corrigé ci-dessus

    jacquesgermain thanked this post
Viewing 4 posts - 1 through 4 (of 4 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 Pine Script Tradingwiew en PRT


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by Iván GonzálezIván González
2 years, 3 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 12/16/2023
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...