Conversion code ICT CISD pour ProRealTime

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #248671 quote
    Alai-n
    Participant
    New

    Bonjour,

    Serait-il possible de convertir le code joint en langage ProBuilder pour ProRealTime.
    Je joins le lien original pour voir ce que devrait faire le code selon l’auteur!
    Merci
    https://fr.tradingview.com/script/vUg295KM-CISD-Levels-by-HAZED/

    //@version=6
    indicator("CISD Levels by HAZED", "CISD →", overlay=true, max_lines_count=500, max_labels_count=500)
    
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    // 🎯 CISD LEVEL SETTINGS
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    
    g_cisd = "🎯 CISD Level Settings"
    bullishBreakColor = input.color(color.lime, "Bullish Color", group=g_cisd, inline="bull")
    bullStr = input.string("+CISD", "Text", group=g_cisd, inline="bull")
    bullishAlerts = input.bool(false, "Alert", group=g_cisd, inline="bull")
    
    bearishBreakColor = input.color(color.red, "Bearish Color", group=g_cisd, inline="bear")
    bearStr = input.string("-CISD", "Text", group=g_cisd, inline="bear")
    bearishAlerts = input.bool(false, "Alert", group=g_cisd, inline="bear")
    
    keepLevels = input.bool(false, "Historical Levels", group=g_cisd)
    maxLevels = input.int(15, "Max Historical Levels", minval=1, maxval=50, group=g_cisd)
    
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    // 🎨 LINE APPEARANCE
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    
    g_line = "🎨 Line Appearance"
    lineWidth = input.int(2, "Line Width", minval=1, maxval=5, group=g_line)
    styleOption = input.string("Solid (─)", "Line Style", ["Solid (─)", "Dotted (┈)", "Dashed (╌)"], group=g_line)
    lineTransparency = input.int(0, "Line Transparency", minval=0, maxval=100, group=g_line)
    lookAheadBars = input.int(15, "Line Extension Bars", minval=1, maxval=50, group=g_line)
    
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    // 📝 TEXT APPEARANCE
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    
    g_text = "📝 Text Appearance"
    showLabels = input.bool(true, "Show Labels", group=g_text)
    labelOffset = input.int(0, "Label Offset (Bars)", minval=0, maxval=20, group=g_text)
    textSizeOption = input.string("Small", "Text Size", ["Tiny", "Small", "Normal", "Large", "Huge"], group=g_text)
    textFontOption = input.string("Default", "Text Font", ["Default", "Monospace"], group=g_text)
    textBoldOption = input.bool(true, "Bold Text", group=g_text)
    
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    // 📊 STATISTICS TABLE
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    
    g_stats = "📊 Statistics Table"
    showTable = input.bool(true, "Enable Statistics Table", group=g_stats)
    tablePosition = input.string("Top Right", "Table Position", ["Top Right", "Bottom Right", "Middle Right", "Bottom Center", "Middle Left"], group=g_stats)
    tableFontOption = input.string("Default", "Table Font", ["Default", "Monospace"], group=g_stats)
    
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    // 🚨 ALERT SETTINGS
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    
    g_alerts = "🚨 Alert Settings"
    alertFrequency = input.string("Once Per Bar Close", "Alert Frequency", ["Once Per Bar", "Once Per Bar Close"], group=g_alerts)
    
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    // CONSTANTS & CACHED VALUES - OPTIMIZATION
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    
    // Pre-calculate constants to avoid repeated switch operations
    lineStyle = styleOption == "Dotted (┈)" ? line.style_dotted : styleOption == "Dashed (╌)" ? line.style_dashed : line.style_solid
    textSize = textSizeOption == "Tiny" ? size.tiny : textSizeOption == "Small" ? size.small : textSizeOption == "Normal" ? size.normal : textSizeOption == "Large" ? size.large : size.huge
    textFont = textFontOption == "Default" ? font.family_default : font.family_monospace
    tableFont = tableFontOption == "Default" ? font.family_default : font.family_monospace
    tablePos = tablePosition == "Top Right" ? position.top_right : tablePosition == "Bottom Right" ? position.bottom_right : tablePosition == "Middle Right" ? position.middle_right : tablePosition == "Bottom Center" ? position.bottom_center : position.middle_left
    
    // Pre-calculate colors to avoid repeated color.new() calls
    bullLineColor = color.new(bullishBreakColor, lineTransparency)
    bearLineColor = color.new(bearishBreakColor, lineTransparency)
    transparentWhite = color.new(color.white, 100)
    
    // Cache commonly used values
    maxKeep = keepLevels ? maxLevels : 1
    adjustedOffset = labelOffset == 0 ? 0 : labelOffset
    lookAheadX = bar_index + lookAheadBars
    labelX = lookAheadX + adjustedOffset
    
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    // TYPE DEFINITIONS & HELPER FUNCTIONS - OPTIMIZED
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    
    type MarketStructure
        float topPrice
        float bottomPrice
        bool isBullish
    
    type CisdLevel
        line levelLine
        label levelLabel
        bool isCompleted
        int creationBar
    
    // Optimized label creation - single function call path
    createOptimizedLabel(x, y, txt, txtColor) =>
        if showLabels
            if textBoldOption
                label.new(x, y, txt, color=transparentWhite, textcolor=txtColor, style=label.style_label_left, text_font_family=textFont, size=textSize, text_formatting=text.format_bold)
            else
                label.new(x, y, txt, color=transparentWhite, textcolor=txtColor, style=label.style_label_left, text_font_family=textFont, size=textSize, text_formatting=text.format_none)
        else
            na
    
    // Optimized cleanup with early exit
    cleanupOptimized(levels) =>
        levelCount = array.size(levels)
        if levelCount > maxKeep
            deleteCount = levelCount - maxKeep
            for i = 1 to deleteCount
                if array.size(levels) > 0
                    oldLevel = array.shift(levels)
                    line.delete(oldLevel.levelLine)
                    if not na(oldLevel.levelLabel)
                        label.delete(oldLevel.levelLabel)
    
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    // STATE VARIABLES - ORIGINAL LOGIC PRESERVED
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    
    var MarketStructure currentStructure = MarketStructure.new(0, 0, false)
    var array<CisdLevel> bullishLevels = array.new<CisdLevel>()
    var array<CisdLevel> bearishLevels = array.new<CisdLevel>()
    
    var bool isBullishPullback = false
    var bool isBearishPullback = false
    var float potentialTopPrice = na
    var float potentialBottomPrice = na
    var int bullishBreakIndex = na
    var int bearishBreakIndex = na
    var bool currentState = false
    
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    // MAIN CISD LOGIC - ORIGINAL ALGORITHM WITH OPTIMIZATIONS
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    
    // Cache OHLC values to avoid repeated lookups
    c = close
    o = open
    c1 = close[1]
    o1 = open[1]
    h = high
    l = low
    h1 = high[1]
    l1 = low[1]
    bi = bar_index
    bi1 = bar_index[1]
    
    // Optimized candle type detection
    isBullishCandle = c > o
    isBearishCandle = c < o
    prevBullishCandle = c1 > o1
    prevBearishCandle = c1 < o1
    
    // Optimized pullback detection
    bearishPullbackDetected = prevBullishCandle and not isBearishPullback
    bullishPullbackDetected = prevBearishCandle and not isBullishPullback
    
    // Bearish Pullback Logic - ORIGINAL
    if bearishPullbackDetected
        isBearishPullback := true
        potentialTopPrice := o1
        bullishBreakIndex := bi1
    
    // Bullish Pullback Logic - ORIGINAL
    if bullishPullbackDetected
        isBullishPullback := true
        potentialBottomPrice := o1
        bearishBreakIndex := bi1
    
    // Update Potential Levels During Pullbacks - ORIGINAL with optimizations
    if isBullishPullback
        if o < potentialBottomPrice
            potentialBottomPrice := o
            bearishBreakIndex := bi
        else if isBearishCandle and o > potentialBottomPrice
            potentialBottomPrice := o
            bearishBreakIndex := bi
    
    if isBearishPullback
        if o > potentialTopPrice
            potentialTopPrice := o
            bullishBreakIndex := bi
        else if isBullishCandle and o < potentialTopPrice
            potentialTopPrice := o
            bullishBreakIndex := bi
    
    // Structure Updates - Bearish Break - ORIGINAL with optimizations
    if l < currentStructure.bottomPrice
        currentStructure.bottomPrice := l
        currentStructure.isBullish := false
        
        if isBearishPullback and (bi - bullishBreakIndex != 0)
            indexDiff = bi - bullishBreakIndex
            currentStructure.topPrice := math.max(high[indexDiff], high[indexDiff - 1])
            isBearishPullback := false
            
            bearishLine = line.new(bullishBreakIndex, potentialTopPrice, lookAheadX, potentialTopPrice, color=bullLineColor, width=lineWidth, style=lineStyle)
            bearishLabel = createOptimizedLabel(labelX, potentialTopPrice, bullStr, bullishBreakColor)
            
            newLevel = CisdLevel.new(bearishLine, bearishLabel, false, bi)
            array.push(bearishLevels, newLevel)
        else if prevBullishCandle and isBearishCandle
            currentStructure.topPrice := h1
            isBearishPullback := false
            
            bearishLine = line.new(bullishBreakIndex, potentialTopPrice, lookAheadX, potentialTopPrice, color=bullLineColor, width=lineWidth, style=lineStyle)
            bearishLabel = createOptimizedLabel(labelX, potentialTopPrice, bullStr, bullishBreakColor)
            
            newLevel = CisdLevel.new(bearishLine, bearishLabel, false, bi)
            array.push(bearishLevels, newLevel)
    
    // Structure Updates - Bullish Break - ORIGINAL with optimizations
    if h > currentStructure.topPrice
        currentStructure.isBullish := true
        currentStructure.topPrice := h
        
        if isBullishPullback and (bi - bearishBreakIndex != 0)
            indexDiff = bi - bearishBreakIndex
            currentStructure.bottomPrice := math.min(low[indexDiff], low[indexDiff - 1])
            isBullishPullback := false
            
            bullishLine = line.new(bearishBreakIndex, potentialBottomPrice, lookAheadX, potentialBottomPrice, color=bearLineColor, width=lineWidth, style=lineStyle)
            bullishLabel = createOptimizedLabel(labelX, potentialBottomPrice, bearStr, bearishBreakColor)
            
            newLevel = CisdLevel.new(bullishLine, bullishLabel, false, bi)
            array.push(bullishLevels, newLevel)
        else if prevBearishCandle and isBullishCandle
            currentStructure.bottomPrice := l1
            isBullishPullback := false
            
            bullishLine = line.new(bearishBreakIndex, potentialBottomPrice, lookAheadX, potentialBottomPrice, color=bearLineColor, width=lineWidth, style=lineStyle)
            bullishLabel = createOptimizedLabel(labelX, potentialBottomPrice, bearStr, bearishBreakColor)
            
            newLevel = CisdLevel.new(bullishLine, bullishLabel, false, bi)
            array.push(bullishLevels, newLevel)
    
    // Optimized cleanup
    cleanupOptimized(bullishLevels)
    cleanupOptimized(bearishLevels)
    
    // Update active levels and handle alerts - ORIGINAL LOGIC with optimizations
    bullishSize = array.size(bullishLevels)
    if bullishSize >= 1
        latest = array.get(bullishLevels, bullishSize - 1)
        if not latest.isCompleted
            levelPrice = latest.levelLine.get_y2()
            
            // Optimized level management
            if c >= levelPrice
                line.set_x2(latest.levelLine, lookAheadX)
                if not na(latest.levelLabel)
                    label.set_x(latest.levelLabel, labelX)
            else
                latest.isCompleted := true
                currentState := false
                
                // Optimized alert condition
                if bearishAlerts and (alertFrequency == "Once Per Bar" or barstate.isconfirmed)
                    alert("🔴 Bearish CISD Level Broken at " + str.tostring(levelPrice))
                
                bearishLine = line.new(bullishBreakIndex, potentialTopPrice, lookAheadX, potentialTopPrice, color=bullLineColor, width=lineWidth, style=lineStyle)
                bearishLabel = createOptimizedLabel(labelX, potentialTopPrice, bullStr, bullishBreakColor)
                
                newLevel = CisdLevel.new(bearishLine, bearishLabel, false, bi)
                array.push(bearishLevels, newLevel)
    
    bearishSize = array.size(bearishLevels)
    if bearishSize >= 1
        latest = array.get(bearishLevels, bearishSize - 1)
        if not latest.isCompleted
            levelPrice = latest.levelLine.get_y2()
            
            // Optimized level management
            if c <= levelPrice
                line.set_x2(latest.levelLine, lookAheadX)
                if not na(latest.levelLabel)
                    label.set_x(latest.levelLabel, labelX)
            else
                latest.isCompleted := true
                currentState := true
                
                // Optimized alert condition
                if bullishAlerts and (alertFrequency == "Once Per Bar" or barstate.isconfirmed)
                    alert("🟢 Bullish CISD Level Broken at " + str.tostring(levelPrice))
                
                bullishLine = line.new(bearishBreakIndex, potentialBottomPrice, lookAheadX, potentialBottomPrice, color=bearLineColor, width=lineWidth, style=lineStyle)
                bullishLabel = createOptimizedLabel(labelX, potentialBottomPrice, bearStr, bearishBreakColor)
                
                newLevel = CisdLevel.new(bullishLine, bullishLabel, false, bi)
                array.push(bullishLevels, newLevel)
    
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    // 📊 OPTIMIZED STATISTICS TABLE
    // ═══════════════════════════════════════════════════════════════════════════════════════════════
    
    if showTable and barstate.islast
        var table statsTable = table.new(tablePos, 2, 3, 
             bgcolor=color.new(color.white, 0), 
             border_color=color.new(color.gray, 50), 
             frame_color=color.new(color.gray, 30), 
             frame_width=1, border_width=1)
        
        // Pre-calculate table colors
        labelBg = color.new(color.gray, 90)
        valueBg = color.new(color.white, 0)
        stateColor = currentState ? color.new(color.green, 25) : color.new(color.red, 25)
        
        // Market State Row
        table.cell(statsTable, 0, 0, "Market State", 
             text_size=size.small, text_color=color.black, text_font_family=tableFont, 
             bgcolor=labelBg, text_formatting=text.format_bold)
        
        stateText = currentState ? "BULLISH 📈" : "BEARISH 📉"
        table.cell(statsTable, 1, 0, stateText, 
             text_size=size.small, text_color=color.white, 
             text_font_family=tableFont, text_formatting=text.format_bold, bgcolor=stateColor)
        
        // Bullish Level Row
        table.cell(statsTable, 0, 1, "+CISD Level", 
             text_size=size.small, text_color=color.black, text_font_family=tableFont, 
             bgcolor=labelBg, text_formatting=text.format_bold)
        
        bullText = "--"
        if bullishSize > 0
            latestBull = array.get(bullishLevels, bullishSize - 1)
            bullText := str.tostring(latestBull.levelLine.get_y2(), format.mintick)
        
        table.cell(statsTable, 1, 1, bullText, 
             text_size=size.small, text_color=color.new(color.green, 0), text_font_family=tableFont, 
             text_formatting=text.format_bold, bgcolor=valueBg)
        
        // Bearish Level Row
        table.cell(statsTable, 0, 2, "-CISD Level", 
             text_size=size.small, text_color=color.black, text_font_family=tableFont, 
             bgcolor=labelBg, text_formatting=text.format_bold)
        
        bearText = "--"
        if bearishSize > 0
            latestBear = array.get(bearishLevels, bearishSize - 1)
            bearText := str.tostring(latestBear.levelLine.get_y2(), format.mintick)
        
        table.cell(statsTable, 1, 2, bearText, 
             text_size=size.small, text_color=color.new(color.red, 0), text_font_family=tableFont, 
             text_formatting=text.format_bold, bgcolor=valueBg)
    #248705 quote
    Iván González
    Moderator
    New

    Le voilà.

    // -----------------------------------------
    // PRC_CISD Levels by HAZED
    //version = 0
    //07.07.25
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    // ---------------------------------------------
    // ---------------------------------------------
    // INPUTS
    // ---------------------------------------------
    maxLevels = 15
    lookAheadBars = 15
    labelOffset = 5
    // ---------------------------------------------
    // CALCULATION
    // ---------------------------------------------
    ONCE bullLevelCount = 0
    ONCE bearLevelCount = 0
    
    isBullishCandle = close > open
    isBearishCandle = close < open
    prevBullishCandle = close[1] > open[1]
    prevBearishCandle = close[1] < open[1]
    
    
    ONCE isBullishPullback = 0
    ONCE isBearishPullback = 0
    
    bearishPullbackDetected = prevBullishCandle AND not isBearishPullback
    bullishPullbackDetected = prevBearishCandle AND not isBullishPullback
    
    
    IF bearishPullbackDetected THEN
       isBearishPullback = 1
       potentialTopPrice = open[1]
       bullishBreakIndex = barindex[1]
    ENDIF
    
    
    IF bullishPullbackDetected THEN
       isBullishPullback = 1
       potentialBottomPrice = open[1]
       bearishBreakIndex = barindex[1]
    ENDIF
    
    IF isBullishPullback THEN
       IF open < potentialBottomPrice THEN
          potentialBottomPrice = open
          bearishBreakIndex = barindex
       ELSIF isBearishCandle AND open > potentialBottomPrice THEN
          potentialBottomPrice = open
          bearishBreakIndex = barindex
       ENDIF
    ENDIF
    
    IF isBearishPullback THEN
       IF open > potentialTopPrice THEN
          potentialTopPrice = open
          bullishBreakIndex = barindex
       ELSIF isBullishCandle AND open < potentialTopPrice THEN
          potentialTopPrice = open
          bullishBreakIndex = barindex
       ENDIF
    ENDIF
    
    ONCE isBullishStructure = 1
    
    
    ONCE currentBottomPrice = low
    
    IF low < currentBottomPrice THEN
       
       currentBottomPrice = low
       isBullishStructure = 0
       
       IF isBearishPullback AND (barindex - bullishBreakIndex > 0) THEN
          
          indexDiff=barindex-bullishBreakIndex
          isBearishPullback = 0
          currentTopPrice = max(high[indexDiff],high[indexDiff-1])
          
          // New level
          $bearPrice[bearLevelCount] = potentialTopPrice
          $bearStartIndex[bearLevelCount] = bullishBreakIndex
          $bearEndIndex[bearLevelCount]=barindex+lookAheadBars
          $bearIsCompleted[bearLevelCount] = 0
          $bearCreationBar[bearLevelCount]=barindex
          bearLevelCount = bearLevelCount + 1
          
       elsif prevBullishCandle and isBearishcandle then
          
          currentTopPrice=high[1]
          isBearishPullback=0
          
          // New level
          
          $bearPrice[bearLevelCount] = potentialTopPrice
          $bearStartIndex[bearLevelCount] = bullishBreakIndex
          $bearEndIndex[bearLevelCount]=barindex+lookAheadBars
          $bearIsCompleted[bearLevelCount] = 0
          $bearCreationBar[bearLevelCount]=barindex
          bearLevelCount = bearLevelCount + 1
          
       ENDIF
    ENDIF
    
    
    ONCE currentTopPrice = high
    
    IF high > currentTopPrice THEN
       
       currentTopPrice = high
       isBullishStructure = 1
       
       IF isBullishPullback AND (barindex - bearishBreakIndex > 0) THEN
          indexDiff=barindex-bearishBreakIndex
          currentBottomPrice=min(low[indexDiff],low[indexDiff-1])
          isBullishPullback = 0
          
          // New level
          bullLevelCount = bullLevelCount + 1
          $bullPrice[bullLevelCount] = potentialBottomPrice
          $bullStartIndex[bullLevelCount] = bearishBreakIndex
          $bullEndIndex[bullLevelCount]=barindex+lookAheadBars
          $bullIsCompleted[bullLevelCount] = 0
          $bullCreationBar[bullLevelCount]=barindex
          
       elsif prevBearishCandle and isBullishCandle then
          
          currentBottomPrice=low[1]
          isBullishPullback = 0
          
          // New level
          
          bullLevelCount = bullLevelCount + 1
          $bullPrice[bullLevelCount] = potentialBottomPrice
          $bullStartIndex[bullLevelCount] = bearishBreakIndex
          $bullEndIndex[bullLevelCount]=barindex+lookAheadBars
          $bullIsCompleted[bullLevelCount] = 0
          $bullCreationBar[bullLevelCount]=barindex
          
       ENDIF
    ENDIF
    
    if islastbarupdate then
       
       for i=bullLevelCount downto bullLevelCount-maxLevels do
          idx=barindex-$bullStartIndex[i]
          
          if $bullIsCompleted[i] = 0 then
             for j=idx-1 downto 0 do
                if close[j]<=$bullPrice[i] then
                   $bullIsCompleted[i] = 1
                   $bullEndIndex[i]=barindex[j]
                   break
                endif
             next
             drawsegment($bullStartIndex[i],$bullPrice[i],$bullEndIndex[i],$bullPrice[i])coloured("red")
             drawtext("-CISD",$bullEndIndex[i]+labelOffset,$bullPrice[i])coloured("red")
          else
             drawsegment($bullStartIndex[i],$bullPrice[i],$bullEndIndex[i],$bullPrice[i])coloured("red")
             drawtext("-CISD",$bullEndIndex[i]+labelOffset,$bullPrice[i])coloured("red")
          endif
       next
       
       for i=bearLevelCount downto bearLevelCount-maxLevels do
          idx=barindex-$bearStartIndex[i]
          
          if $bearIsCompleted[i] = 0 then
             for j=idx-1 downto 0 do
                if close[j]>=$bearPrice[i] then
                   $bearIsCompleted[i] = 1
                   $bearEndIndex[i]=barindex[j]
                   break
                endif
             next
             drawsegment($bearStartIndex[i],$bearPrice[i],$bearEndIndex[i],$bearPrice[i])coloured("green")
             drawtext("+CISD",$bearEndIndex[i]+labelOffset,$bearPrice[i])coloured("green")
          else
             drawsegment($bearStartIndex[i],$bearPrice[i],$bearEndIndex[i],$bearPrice[i])coloured("green")
             drawtext("+CISD",$bearEndIndex[i]+labelOffset,$bearPrice[i])coloured("green")
          endif
       next
       
    endif
    
    return
    
    Alai-n thanked this post
    #248714 quote
    Alai-n
    Participant
    New

    Bonjour Iván merci pour la conversion du code.

    J’ai cependant un petit soucis dans le paramétrage ligne 11, pour des raisons de lisibilité du graphique je souhaiterais n’afficher que le dernier +CISD et le dernier -CISD !

    Mais sur les images jointes on peut voir que c’est les deux derniers -CISD qui s’affichent toujours!

    Aurais-tu une idée pour résoudre ce problème ?

    // -----------------------------------------
    // PRC_CISD Levels by HAZED
    //version = 0
    //07.07.25
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    // ---------------------------------------------
    // ---------------------------------------------
    // INPUTS
    // ---------------------------------------------
    maxLevels = 1
    lookAheadBars = 15
    labelOffset = 5
    // ---------------------------------------------
    // CALCULATION
    // ---------------------------------------------
    ONCE bullLevelCount = 0
    ONCE bearLevelCount = 0
     
    isBullishCandle = close > open
    isBearishCandle = close < open
    prevBullishCandle = close[1] > open[1]
    prevBearishCandle = close[1] < open[1]
     
     
    ONCE isBullishPullback = 0
    ONCE isBearishPullback = 0
     
    bearishPullbackDetected = prevBullishCandle AND not isBearishPullback
    bullishPullbackDetected = prevBearishCandle AND not isBullishPullback
     
     
    IF bearishPullbackDetected THEN
    isBearishPullback = 1
    potentialTopPrice = open[1]
    bullishBreakIndex = barindex[1]
    ENDIF
     
     
    IF bullishPullbackDetected THEN
    isBullishPullback = 1
    potentialBottomPrice = open[1]
    bearishBreakIndex = barindex[1]
    ENDIF
     
    IF isBullishPullback THEN
    IF open < potentialBottomPrice THEN
    potentialBottomPrice = open
    bearishBreakIndex = barindex
    ELSIF isBearishCandle AND open > potentialBottomPrice THEN
    potentialBottomPrice = open
    bearishBreakIndex = barindex
    ENDIF
    ENDIF
     
    IF isBearishPullback THEN
    IF open > potentialTopPrice THEN
    potentialTopPrice = open
    bullishBreakIndex = barindex
    ELSIF isBullishCandle AND open < potentialTopPrice THEN
    potentialTopPrice = open
    bullishBreakIndex = barindex
    ENDIF
    ENDIF
     
    ONCE isBullishStructure = 1
     
     
    ONCE currentBottomPrice = low
     
    IF low < currentBottomPrice THEN
       
    currentBottomPrice = low
    isBullishStructure = 0
       
    IF isBearishPullback AND (barindex - bullishBreakIndex > 0) THEN
          
    indexDiff=barindex-bullishBreakIndex
    isBearishPullback = 0
    currentTopPrice = max(high[indexDiff],high[indexDiff-1])
          
    // New level
    $bearPrice[bearLevelCount] = potentialTopPrice
    $bearStartIndex[bearLevelCount] = bullishBreakIndex
    $bearEndIndex[bearLevelCount]=barindex+lookAheadBars
    $bearIsCompleted[bearLevelCount] = 0
    $bearCreationBar[bearLevelCount]=barindex
    bearLevelCount = bearLevelCount + 1
          
    elsif prevBullishCandle and isBearishcandle then
          
    currentTopPrice=high[1]
    isBearishPullback=0
          
    // New level
          
    $bearPrice[bearLevelCount] = potentialTopPrice
    $bearStartIndex[bearLevelCount] = bullishBreakIndex
    $bearEndIndex[bearLevelCount]=barindex+lookAheadBars
    $bearIsCompleted[bearLevelCount] = 0
    $bearCreationBar[bearLevelCount]=barindex
    bearLevelCount = bearLevelCount + 1
          
    ENDIF
    ENDIF
     
     
    ONCE currentTopPrice = high
     
    IF high > currentTopPrice THEN
       
    currentTopPrice = high
    isBullishStructure = 1
       
    IF isBullishPullback AND (barindex - bearishBreakIndex > 0) THEN
    indexDiff=barindex-bearishBreakIndex
    currentBottomPrice=min(low[indexDiff],low[indexDiff-1])
    isBullishPullback = 0
          
    // New level
    bullLevelCount = bullLevelCount + 1
    $bullPrice[bullLevelCount] = potentialBottomPrice
    $bullStartIndex[bullLevelCount] = bearishBreakIndex
    $bullEndIndex[bullLevelCount]=barindex+lookAheadBars
    $bullIsCompleted[bullLevelCount] = 0
    $bullCreationBar[bullLevelCount]=barindex
          
    elsif prevBearishCandle and isBullishCandle then
          
    currentBottomPrice=low[1]
    isBullishPullback = 0
          
    // New level
          
    bullLevelCount = bullLevelCount + 1
    $bullPrice[bullLevelCount] = potentialBottomPrice
    $bullStartIndex[bullLevelCount] = bearishBreakIndex
    $bullEndIndex[bullLevelCount]=barindex+lookAheadBars
    $bullIsCompleted[bullLevelCount] = 0
    $bullCreationBar[bullLevelCount]=barindex
          
    ENDIF
    ENDIF
     
    if islastbarupdate then
       
    for i=bullLevelCount downto bullLevelCount-maxLevels do
    idx=barindex-$bullStartIndex[i]
          
    if $bullIsCompleted[i] = 0 then
    for j=idx-1 downto 0 do
    if close[j]<=$bullPrice[i] then
    $bullIsCompleted[i] = 1
    $bullEndIndex[i]=barindex[j]
    break
    endif
    next
    drawsegment($bullStartIndex[i],$bullPrice[i],$bullEndIndex[i],$bullPrice[i])coloured("red")
    drawtext("-CISD",$bullEndIndex[i]+labelOffset,$bullPrice[i])coloured("red")
    else
    drawsegment($bullStartIndex[i],$bullPrice[i],$bullEndIndex[i],$bullPrice[i])coloured("red")
    drawtext("-CISD",$bullEndIndex[i]+labelOffset,$bullPrice[i])coloured("red")
    endif
    next
       
    for i=bearLevelCount downto bearLevelCount-maxLevels do
    idx=barindex-$bearStartIndex[i]
          
    if $bearIsCompleted[i] = 0 then
    for j=idx-1 downto 0 do
    if close[j]>=$bearPrice[i] then
    $bearIsCompleted[i] = 1
    $bearEndIndex[i]=barindex[j]
    break
    endif
    next
    drawsegment($bearStartIndex[i],$bearPrice[i],$bearEndIndex[i],$bearPrice[i])coloured("green")
    drawtext("+CISD",$bearEndIndex[i]+labelOffset,$bearPrice[i])coloured("green")
    else
    drawsegment($bearStartIndex[i],$bearPrice[i],$bearEndIndex[i],$bearPrice[i])coloured("green")
    drawtext("+CISD",$bearEndIndex[i]+labelOffset,$bearPrice[i])coloured("green")
    endif
    next
       
    endif
     
    return
    #248728 quote
    Iván González
    Moderator
    New

    ok.

    // -----------------------------------------
    // PRC_CISD Levels by HAZED
    //version = 0
    //07.07.25
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    // ---------------------------------------------
    // ---------------------------------------------
    // INPUTS
    // ---------------------------------------------
    maxLevels = 3
    lookAheadBars = 15
    labelOffset = 5
    // ---------------------------------------------
    // CALCULATION
    // ---------------------------------------------
    ONCE bullLevelCount = 0
    ONCE bearLevelCount = 0
    
    isBullishCandle = close > open
    isBearishCandle = close < open
    prevBullishCandle = close[1] > open[1]
    prevBearishCandle = close[1] < open[1]
    
    
    ONCE isBullishPullback = 0
    ONCE isBearishPullback = 0
    
    bearishPullbackDetected = prevBullishCandle AND not isBearishPullback
    bullishPullbackDetected = prevBearishCandle AND not isBullishPullback
    
    
    IF bearishPullbackDetected THEN
       isBearishPullback = 1
       potentialTopPrice = open[1]
       bullishBreakIndex = barindex[1]
    ENDIF
    
    
    IF bullishPullbackDetected THEN
       isBullishPullback = 1
       potentialBottomPrice = open[1]
       bearishBreakIndex = barindex[1]
    ENDIF
    
    IF isBullishPullback THEN
       IF open < potentialBottomPrice THEN
          potentialBottomPrice = open
          bearishBreakIndex = barindex
       ELSIF isBearishCandle AND open > potentialBottomPrice THEN
          potentialBottomPrice = open
          bearishBreakIndex = barindex
       ENDIF
    ENDIF
    
    IF isBearishPullback THEN
       IF open > potentialTopPrice THEN
          potentialTopPrice = open
          bullishBreakIndex = barindex
       ELSIF isBullishCandle AND open < potentialTopPrice THEN
          potentialTopPrice = open
          bullishBreakIndex = barindex
       ENDIF
    ENDIF
    
    ONCE isBullishStructure = 1
    
    
    ONCE currentBottomPrice = low
    
    IF low < currentBottomPrice THEN
       
       currentBottomPrice = low
       isBullishStructure = 0
       
       IF isBearishPullback AND (barindex - bullishBreakIndex > 0) THEN
          
          indexDiff=barindex-bullishBreakIndex
          isBearishPullback = 0
          currentTopPrice = max(high[indexDiff],high[indexDiff-1])
          
          // New level
          bearLevelCount = bearLevelCount + 1
          $bearPrice[bearLevelCount] = potentialTopPrice
          $bearStartIndex[bearLevelCount] = bullishBreakIndex
          $bearEndIndex[bearLevelCount]=barindex+lookAheadBars
          $bearIsCompleted[bearLevelCount] = 0
          $bearCreationBar[bearLevelCount]=barindex
          
          
       elsif prevBullishCandle and isBearishcandle then
          
          currentTopPrice=high[1]
          isBearishPullback=0
          
          // New level
          bearLevelCount = bearLevelCount + 1
          $bearPrice[bearLevelCount] = potentialTopPrice
          $bearStartIndex[bearLevelCount] = bullishBreakIndex
          $bearEndIndex[bearLevelCount]=barindex+lookAheadBars
          $bearIsCompleted[bearLevelCount] = 0
          $bearCreationBar[bearLevelCount]=barindex
          
       ENDIF
    ENDIF
    
    
    ONCE currentTopPrice = high
    
    IF high > currentTopPrice THEN
       
       currentTopPrice = high
       isBullishStructure = 1
       
       IF isBullishPullback AND (barindex - bearishBreakIndex > 0) THEN
          indexDiff=barindex-bearishBreakIndex
          currentBottomPrice=min(low[indexDiff],low[indexDiff-1])
          isBullishPullback = 0
          
          // New level
          bullLevelCount = bullLevelCount + 1
          $bullPrice[bullLevelCount] = potentialBottomPrice
          $bullStartIndex[bullLevelCount] = bearishBreakIndex
          $bullEndIndex[bullLevelCount]=barindex+lookAheadBars
          $bullIsCompleted[bullLevelCount] = 0
          $bullCreationBar[bullLevelCount]=barindex
          
       elsif prevBearishCandle and isBullishCandle then
          
          currentBottomPrice=low[1]
          isBullishPullback = 0
          
          // New level
          
          bullLevelCount = bullLevelCount + 1
          $bullPrice[bullLevelCount] = potentialBottomPrice
          $bullStartIndex[bullLevelCount] = bearishBreakIndex
          $bullEndIndex[bullLevelCount]=barindex+lookAheadBars
          $bullIsCompleted[bullLevelCount] = 0
          $bullCreationBar[bullLevelCount]=barindex
          
       ENDIF
    ENDIF
    
    if islastbarupdate then
       
       for i=bullLevelCount downto bullLevelCount+1-maxLevels do
          idx=barindex-$bullStartIndex[i]
          
          if $bullIsCompleted[i] = 0 then
             for j=idx-1 downto 0 do
                if close[j]<=$bullPrice[i] then
                   $bullIsCompleted[i] = 1
                   $bullEndIndex[i]=barindex[j]
                   break
                endif
             next
             drawsegment($bullStartIndex[i],$bullPrice[i],$bullEndIndex[i],$bullPrice[i])coloured("red")
             drawtext("-CISD",$bullEndIndex[i]+labelOffset,$bullPrice[i])coloured("red")
          else
             drawsegment($bullStartIndex[i],$bullPrice[i],$bullEndIndex[i],$bullPrice[i])coloured("red")
             drawtext("-CISD",$bullEndIndex[i]+labelOffset,$bullPrice[i])coloured("red")
          endif
       next
       
       for i=bearLevelCount downto bearLevelCount+1-maxLevels do
          idx=barindex-$bearStartIndex[i]
          
          if $bearIsCompleted[i] = 0 then
             for j=idx-1 downto 0 do
                if close[j]>=$bearPrice[i] then
                   $bearIsCompleted[i] = 1
                   $bearEndIndex[i]=barindex[j]
                   break
                endif
             next
             drawsegment($bearStartIndex[i],$bearPrice[i],$bearEndIndex[i],$bearPrice[i])coloured("green")
             drawtext("+CISD",$bearEndIndex[i]+labelOffset,$bearPrice[i])coloured("green")
          else
             drawsegment($bearStartIndex[i],$bearPrice[i],$bearEndIndex[i],$bearPrice[i])coloured("green")
             drawtext("+CISD",$bearEndIndex[i]+labelOffset,$bearPrice[i])coloured("green")
          endif
       next
       
    endif
    
    return
    
    Alai-n thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Conversion code ICT CISD pour ProRealTime


Support ProBuilder

New Reply
Author
author-avatar
Alai-n @alai-n Participant
Summary

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

Topic Details
Forum: Support ProBuilder
Language: French
Started: 07/05/2025
Status: Active
Attachments: 2 files
Logo Logo
Loading...