Conversion indicateur TradingView / Pinescript

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #237934 quote
    RomainRR
    Participant
    New

    Bonjour à tous,

    Est-ce que quelqu’un aurait le temps et la gentillesse de pouvoir convertir un indicateur TradingView pour PRT.

    C’est un indicateur 2 en 1, il y a un AMDx (Accumulation Manipulation Distribution) cela trace des rectangles à heure fixe. De même pour le second qui est un indicateur OPR, cela trace un rectangle de telle heure à heure, en prenant en compte par exemple le plus haut et le plus bas des bougies de 15h00 et 15h01.

    Je vous poste le code et des captures.
    je vous remercie beaucoup par avance.

     

    /@version=5
    indicator("OPR", overlay=true)
    
    
    // --- Paramètres personnalisables --- //
    inputHour   = input.int(15, "Heure de la bougie (heure de Paris)", minval=0, maxval=23)  // Heure cible que tu peux ajuster (heure de Paris)
    inputMinute = input.int(32, "Minute de la bougie", minval=0, maxval=59) // Minute cible que tu peux ajuster
    endHour     = 18  // Heure de fin fixe (23h59 heure de Paris)
    endMinute   = 48
    
    inputHour1   = input.int(09, "Heure de la bougie (heure de Paris)", minval=0, maxval=23)  // Heure cible que tu peux ajuster (heure de Paris)
    inputMinute1 = input.int(29, "Minute de la bougie", minval=0, maxval=59) // Minute cible que tu peux ajuster
    endHour1     = 15  // Heure de fin fixe (23h59 heure de Paris)
    endMinute1   = 31
    
    inputHour2   = input.int(18, "Heure de la bougie (heure de Paris)", minval=0, maxval=23)  // Heure cible que tu peux ajuster (heure de Paris)
    inputMinute2 = input.int(49, "Minute de la bougie", minval=0, maxval=59) // Minute cible que tu peux ajuster
    endHour2     = 19  // Heure de fin fixe (23h59 heure de Paris)
    endMinute2   = 30
    
    inputHour3   = input.int(19, "Heure de la bougie (heure de Paris)", minval=0, maxval=23)  // Heure cible que tu peux ajuster (heure de Paris)
    inputMinute3 = input.int(30, "Minute de la bougie", minval=0, maxval=59) // Minute cible que tu peux ajuster
    endHour3     = 23  // Heure de fin fixe (23h59 heure de Paris)
    endMinute3   = 59
    
    // --- Fuseau horaire (GMT+2) --- //
    gmt_offset_hours = -7
    
    // Calculer l'heure UTC à partir de l'heure de Paris
    hour_utc = (hour - gmt_offset_hours + 24) % 24  // Ajuste l'heure en UTC (évite les valeurs négatives en ajoutant 24)
    
    // Convertir les heures d'entrée en minutes depuis minuit (heure de Paris)
    target_minutes = inputHour * 60 + inputMinute
    end_minutes = endHour * 60 + endMinute
    
    target_minutes1 = inputHour1 * 60 + inputMinute1
    end_minutes1 = endHour1 * 60 + endMinute1
    
    target_minutes2 = inputHour2 * 60 + inputMinute2
    end_minutes2 = endHour2 * 60 + endMinute2
    
    target_minutes3 = inputHour3 * 60 + inputMinute3
    end_minutes3 = endHour3 * 60 + endMinute3
    
    // --- Variables pour stocker les plus hauts et plus bas de la bougie cible --- //
    var float opr_high = na
    var float opr_low = na
    var int opr_day = na  // Stocker le jour pour chaque rectangle
    var box opr_box = na  // Variable pour tracer le rectangle
    
    var float opr_high1 = na
    var float opr_low1 = na
    var int opr_day1 = na  // Stocker le jour pour chaque rectangle
    var box opr_box1 = na  // Variable pour tracer le rectangle
    
    var float opr_high2 = na
    var float opr_low2 = na
    var int opr_day2 = na  // Stocker le jour pour chaque rectangle
    var box opr_box2 = na  // Variable pour tracer le rectangle
    
    var float opr_high3 = na
    var float opr_low3 = na
    var int opr_day3 = na  // Stocker le jour pour chaque rectangle
    var box opr_box3 = na  // Variable pour tracer le rectangle
    
    // Calcul des minutes depuis minuit pour la bougie actuelle (en UTC)
    current_minutes = hour_utc * 60 + minute
    current_minutes1 = hour_utc * 60 + minute
    current_minutes2 = hour_utc * 60 + minute
    current_minutes3 = hour_utc * 60 + minute
    
    
    
    
    // Détection de la bougie cible (heure de Paris définie par l'utilisateur, convertie en UTC)
    is_target_candle = (hour_utc == inputHour and minute == inputMinute)
    is_target_candle1 = (hour_utc == inputHour1 and minute == inputMinute1)
    is_target_candle2 = (hour_utc == inputHour2 and minute == inputMinute2)
    is_target_candle3 = (hour_utc == inputHour3 and minute == inputMinute3)
    
    // Si la bougie est celle définie (ex : 16h25 heure de Paris), on stocke le plus haut et le plus bas
    if (is_target_candle)
        opr_high := high
        opr_low := low
        opr_day := dayofmonth  // On enregistre le jour où la bougie cible est trouvée
    //    
    if (is_target_candle1)
        opr_high1 := high
        opr_low1 := low
        opr_day1 := dayofmonth  // On enregistre le jour où la bougie cible est trouvée
        //    
    if (is_target_candle2)
        opr_high2 := high
        opr_low2 := low
        opr_day2 := dayofmonth  // On enregistre le jour où la bougie cible est trouvée
    //    
    if (is_target_candle3)
        opr_high3 := high
        opr_low3 := low
        opr_day3 := dayofmonth  // On enregistre le jour où la bougie cible est trouvée
    // Si on est après la bougie cible et avant 23h59 heure de Paris, on trace le rectangle
    is_after_target = (current_minutes >= target_minutes) and (current_minutes <= end_minutes)
    is_after_target1 = (current_minutes1 >= target_minutes1) and (current_minutes1 <= end_minutes1)
    is_after_target2 = (current_minutes2 >= target_minutes2) and (current_minutes2 <= end_minutes2)
    is_after_target3 = (current_minutes3 >= target_minutes3) and (current_minutes3 <= end_minutes3)
    
    if (is_after_target and not na(opr_high) and not na(opr_low) and opr_day == dayofmonth)
        if na(opr_box)
            // Création du rectangle
            opr_box := box.new(left=bar_index, top=opr_high, right=bar_index, bottom=opr_low, border_color=color.orange, bgcolor=color.new(color.orange, 85))
        else
            // Mise à jour du côté droit du rectangle pour le prolonger au fur et à mesure de la journée
            box.set_right(opr_box, bar_index)
    //
    if (is_after_target1 and not na(opr_high1) and not na(opr_low1) and opr_day1 == dayofmonth)
        if na(opr_box1)
            // Création du rectangle
            opr_box1 := box.new(left=bar_index, top=opr_high1, right=bar_index, bottom=opr_low1, border_color=#E9C9B1, bgcolor=color.new(#E9C9B1, 80))
        else
            // Mise à jour du côté droit du rectangle pour le prolonger au fur et à mesure de la journée
            box.set_right(opr_box1, bar_index)        
    //
    if (is_after_target2 and not na(opr_high2) and not na(opr_low2) and opr_day2 == dayofmonth)
        if na(opr_box2)
            // Création du rectangle
            opr_box2 := box.new(left=bar_index, top=opr_high2, right=bar_index, bottom=opr_low2, border_color=color.green, bgcolor=color.new(#A5D152, 85))
        else
            // Mise à jour du côté droit du rectangle pour le prolonger au fur et à mesure de la journée
            box.set_right(opr_box2, bar_index)
    //
    if (is_after_target3 and not na(opr_high3) and not na(opr_low3) and opr_day3 == dayofmonth)
        if na(opr_box3)
            // Création du rectangle
            opr_box3 := box.new(left=bar_index, top=opr_high3, right=bar_index, bottom=opr_low3, border_color=#425320, bgcolor=color.new(#425320, 85))
        else
            // Mise à jour du côté droit du rectangle pour le prolonger au fur et à mesure de la journée
            box.set_right(opr_box3, bar_index)
    
    // Réinitialisation des variables pour le jour suivant
    if (dayofmonth != opr_day)
        opr_high := na
        opr_low := na
        opr_day := na
        opr_box := na  // On réinitialise le rectangle pour le jour suivant
    //
    if (dayofmonth != opr_day1)
        opr_high1 := na
        opr_low1 := na
        opr_day1 := na
        opr_box1 := na  // On réinitialise le rectangle pour le jour suivant
    //
    if (dayofmonth != opr_day2)
        opr_high2 := na
        opr_low2 := na
        opr_day2 := na
        opr_box2 := na  // On réinitialise le rectangle pour le jour suivant 
    //
    if (dayofmonth != opr_day3)
        opr_high3 := na
        opr_low3 := na
        opr_day3 := na
        opr_box3 := na  // On réinitialise le rectangle pour le jour suivant       
    //------------//---------------//----------------//-----------------//----------------//-----------------//----------
    
    
    // Input settings for the session box colors, border width, and transparency
    colorA = input.color(color.new(color.red, 80), title="Color for Session A and Vertical Lines")
    colorM = input.color(color.new(color.green, 80), title="Color for Session M and Vertical Lines")
    colorD = input.color(color.new(color.blue, 80), title="Color for Session D and Vertical Lines")
    colorX = input.color(color.new(color.yellow, 80), title="Color for Session X and Vertical Lines")
    borderWidth = input.int(1, title="Border Width", minval=1, maxval=5)
    transparency = input.int(80, title="Transparency", minval=0, maxval=100)
    
    // Input to choose between AMDX and XAMD sessions
    sessionType = input.string("AMDX", title="Choose Session Type", options=["AMDX", "XAMD"])
    
    // Input to choose the drawing style
    drawingStyle = input.string("Box", title="Drawing Style", options=["Box", "Line"])
    
    // Input to enable or disable vertical dashed lines
    showVerticalLines = input.bool(true, title="Show Vertical Lines")
    showVerticalTimeLabels = input.bool(true, title="Show Vertical Time Labels")
    
    // Input to choose vertical line style
    verticalLineStyle = input.string("Dashed", title="Vertical Line Style", options=["Solid", "Dotted", "Dashed"])
    
    // Convert vertical line style input to line style
    var line_style = line.style_solid
    if verticalLineStyle == "Dotted"
        line_style := line.style_dotted
    else if verticalLineStyle == "Dashed"
        line_style := line.style_dashed
    
    // Input for session time label transparency
    timeLabelTransparency = input.int(80, title="Time Label Transparency", minval=0, maxval=100)
    
    // Define the session start and end times based on the selected session type in UTC-4
    var int startTimeA = na
    var int endTimeA = na
    var int startTimeM = na
    var int endTimeM = na
    var int startTimeD = na
    var int endTimeD = na
    var int startTimeX = na
    var int endTimeX = na
    
    if sessionType == "AMDX"
        startTimeA := timestamp("GMT-4", year, month, dayofmonth - 1, 18, 00)
        endTimeA := timestamp("GMT-4", year, month, dayofmonth, 3, 00)
        startTimeM := timestamp("GMT-4", year, month, dayofmonth, 3, 00)
        endTimeM := timestamp("GMT-4", year, month, dayofmonth, 9, 00)
        startTimeD := timestamp("GMT-4", year, month, dayofmonth, 9, 00)
        endTimeD := timestamp("GMT-4", year, month, dayofmonth, 12, 00)
        startTimeX := timestamp("GMT-4", year, month, dayofmonth, 12, 00)
        endTimeX := timestamp("GMT-4", year, month, dayofmonth, 18, 00)
    else
        startTimeX := timestamp("GMT-4", year, month, dayofmonth - 1, 18, 00)
        endTimeX := timestamp("GMT-4", year, month, dayofmonth, 0, 00)
        startTimeA := timestamp("GMT-4", year, month, dayofmonth, 0, 00)
        endTimeA := timestamp("GMT-4", year, month, dayofmonth, 9, 00)
        startTimeM := timestamp("GMT-4", year, month, dayofmonth, 9, 00)
        endTimeM := timestamp("GMT-4", year, month, dayofmonth, 12, 00)
        startTimeD := timestamp("GMT-4", year, month, dayofmonth, 12, 00)
        endTimeD := timestamp("GMT-4", year, month, dayofmonth, 18, 00)
    
    // Function to format time for labels
    format_time(ts) =>
        hourx = hour(ts, "GMT-4")
        minutex = minute(ts, "GMT-4")
        secondx = second(ts, "GMT-4")
        str.tostring(hour, "00") + ":" + str.tostring(minute, "00") + ":" + str.tostring(second, "00")
    
    // Function to draw session boxes or vertical lines and labels
    drawSession(sessionStartTime, sessionEndTime, color, transparency, labelText) =>
        var float sessionLow = na
        var float sessionHigh = na
        var box sessionBox = na
        var label sessionLabel = na
        if (time >= sessionStartTime and time < sessionEndTime)
            sessionLow := na(sessionLow) ? low : math.min(low, sessionLow)
            sessionHigh := na(sessionHigh) ? high : math.max(high, sessionHigh)
        else if (time == sessionEndTime)
            // Ensure the last bar of the session is included in the high/low calculation
            sessionLow := na(sessionLow) ? low : math.min(low, sessionLow)
            sessionHigh := na(sessionHigh) ? high : math.max(high, sessionHigh)
            if (not na(sessionLow) and not na(sessionHigh))
                if drawingStyle == "Box"
                    // Draw the session box
                    sessionBox := box.new(left=sessionStartTime, top=sessionHigh, right=sessionEndTime, bottom=sessionLow, xloc=xloc.bar_time, border_color=color, border_width=borderWidth, bgcolor=color.new(color, 92))
                    // Draw the session label
                    midTime = (sessionStartTime + sessionEndTime) / 2
                    sessionLabel := label.new(midTime, sessionHigh, text=labelText, xloc=xloc.bar_time, yloc=yloc.abovebar, color=color.new(color.black, 75), textcolor=color.new(color.yellow, 0), style=label.style_label_center)
                    
                    
                     // Draw the session label
                    sessionLabel := label.new(sessionStartTime, high, xloc=xloc.bar_time, yloc=yloc.abovebar, color=color.new(color.black, 100), textcolor=color.new(color.white, 0), style=label.style_label_center)
            sessionLow := na
            sessionHigh := na
    
    // Draw boxes and vertical dashed lines for the specified sessions
    drawSession(startTimeA, endTimeA, colorA, transparency, "A")
    drawSession(startTimeM, endTimeM, colorM, transparency, "M")
    drawSession(startTimeD, endTimeD, colorD, transparency, "D")
    drawSession(startTimeX, endTimeX, colorX, transparency, "X")
    
    2024-09-23-13_28_05-US100-19 8162-▲-0.2-Anonyme.png 2024-09-23-13_28_05-US100-19 8162-▲-0.2-Anonyme.png
    #238429 quote
    Iván González
    Moderator
    Master

    Holà. Il n'y a pas exactement le même indicateur qu'il a créé :

    //timeframe(1minute)
    //------------------------------------------------------------//
    inputHour1=09
    inputMinute1=30
    endhour1=15
    endminute1=30
    //------------------------------------------------------------//
    inputHour2=15
    inputMinute2=30
    endhour2=18
    endminute2=50
    //------------------------------------------------------------//
    inputHour3=18
    inputMinute3=50
    endhour3=19
    endminute3=30
    //------------------------------------------------------------//
    inputHour4=19
    inputMinute4=30
    endhour4=22
    endminute4=00
    //------------------------------------------------------------//
    // Draw Rectangle Range 1
    //------------------------------------------------------------//
    if hour=inputhour1 and minute>=inputminute1 and check1=0 then
    inbar1=barindex
    check1=1
    endif
    if check1=1 then
    bars1=bars1+1
    else
    bars1=0
    endif
    if hour=endhour1 and minute>=endminute1 and check1=1 then
    recH1=highest[max(1,bars1)](high)
    recL1=lowest[max(1,bars1)](low)
    endbar1=barindex
    check1=2
    drawrectangle(inbar1,recH1,endbar1,recL1)coloured("green",80)fillcolor("green",80)
    endif
    //------------------------------------------------------------//
    // Draw Rectangle Range 2
    //------------------------------------------------------------//
    if hour=inputhour2 and minute>=inputminute2 and check2=0 then
    inbar2=barindex
    check2=1
    endif
    if check2=1 then
    bars2=bars2+1
    else
    bars2=0
    endif
    if hour=endhour2 and minute>=endminute2 and check2=1 then
    recH2=highest[max(1,bars2)](high)
    recL2=lowest[max(1,bars2)](low)
    endbar2=barindex
    check2=2
    drawrectangle(inbar2,recL2,endbar2,recH2)coloured("red",80)fillcolor("red",80)
    endif
    //------------------------------------------------------------//
    // Draw Rectangle Range 3
    //------------------------------------------------------------//
    if hour=inputhour3 and minute>=inputminute3 and check3=0 then
    inbar3=barindex
    check3=1
    endif
    if check3=1 then
    bars3=bars3+1
    else
    bars3=0
    endif
    if hour=endhour3 and minute>=endminute3 and check3=1 then
    recH3=highest[max(1,bars3)](high)
    recL3=lowest[max(1,bars3)](low)
    endbar3=barindex
    check3=2
    drawrectangle(inbar3,recL3,endbar3,recH3)coloured("blue",80)fillcolor("blue",80)
    endif
    //------------------------------------------------------------//
    // Draw Rectangle Range 4
    //------------------------------------------------------------//
    if hour=inputhour4 and minute>=inputminute4 and check4=0 then
    inbar4=barindex
    check4=1
    endif
    if check4=1 then
    bars4=bars4+1
    else
    bars4=0
    endif
    if hour>=endhour4 and minute>endminute4 and check4=1 then
    endbar4=barindex
    recH4=highest[max(1,bars4)](high)
    recL4=lowest[max(1,bars4)](low)
    check4=2
    drawrectangle(inbar4,recH4,endbar4,recL4)coloured("yellow",80)fillcolor("yellow",80)
    endif
    //------------------------------------------------------------//
    //  Reset checks
    //------------------------------------------------------------//
    if intradaybarindex=0 then
    check1=0
    check2=0
    check3=0
    check4=0
    endif
    
    return
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Conversion indicateur TradingView / Pinescript


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
RomainRR @romainrr Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
1 year, 5 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 09/23/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...