TW code translation ( MKT Structure Trend Matrix)

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

    Good morning,

    I would kindly request a translation of the code in question, which displays Choch with a clearer graphic layout, similar to Supertrend .

    Thank you and regards


    https://it.tradingview.com/script/EdtttXPC-Market-Structure-Trend-Matrix-BigBeluga/





    Screenshot-2026-06-09-at-17-50-36-Market-Structure-Trend-Matrix-BigBeluga-—-Indicatore-di-BigBeluga-—-TradingView.png Screenshot-2026-06-09-at-17-50-36-Market-Structure-Trend-Matrix-BigBeluga-—-Indicatore-di-BigBeluga-—-TradingView.png
    #261865 quote
    Iván González
    Moderator
    Legend

    Here you have:

    //----------------------------------------------
    // PRC_Market Structure Trend Matrix
    // version = 0
    // 10.06.26
    // Iván González @ www.prorealcode.com
    //Original author: BigBeluga
    //Sharing ProRealTime knowledge
    //----------------------------------------------
    // === Parametros (exponer como variables del indicador) ===
    //----------------------------------------------
    msLen = 10           // longitud de estructura (pivots: lookback y lookahead)
    atrLength = 14       // periodo del ATR
    atrMult = 4.0        // multiplicador ATR del trailing stop
    targetStepMult = 2.0 // distancia entre targets consecutivos (x ATR)
    showHistory = 1      // 1 = dibujar los targets ya alcanzados
    showStop = 1         // 1 = dibujar trailing stop + relleno
    //----------------------------------------------
    // === Colores (alcista verde / bajista magenta) ===
    //----------------------------------------------
    bullR = 52
    bullG = 230
    bullB = 126
    bearR = 255
    bearG = 82
    bearB = 241
    //----------------------------------------------
    myAtr = averagetruerange[atrLength]
    pivotWindow = 2 * msLen + 1
    
    once direction = 0   // 0 = estructura bajista, 1 = alcista
    once started = 0     // 1 tras el primer ChoCh
    once phVal = 0
    once plVal = 0
    once phIndx = 0
    once plIndx = 0
    once phReady = 0
    once plReady = 0
    once atrTS = 0
    once entryPrice = 0
    once currentTarget = 0
    once trendStart = 0
    once hitCount = 0
    //----------------------------------------------
    // === Deteccion de pivots (confirmados msLen barras tarde) ===
    //----------------------------------------------
    if barindex > 2 * msLen then
       if high[msLen] >= highest[pivotWindow](high) then
          phVal = high[msLen]
          phIndx = barindex - msLen
          phReady = 1
       endif
       if low[msLen] <= lowest[pivotWindow](low) then
          plVal = low[msLen]
          plIndx = barindex - msLen
          plReady = 1
       endif
    endif
    //----------------------------------------------
    // === ChoCh alcista: cierre cruza el ultimo pivot high en estructura bajista ===
    //----------------------------------------------
    if phReady = 1 and direction = 0 and close crosses over phVal then
       direction = 1
       started = 1
       hitCount = 0
       atrTS = close - myAtr * atrMult
       entryPrice = phVal
       currentTarget = entryPrice + myAtr * targetStepMult
       trendStart = barindex
       labelX = round((phIndx + barindex) / 2)
       drawsegment(phIndx, phVal, barindex, phVal) coloured(bullR, bullG, bullB) style(line, 2)
       drawtext("ChoCh ↑", labelX, phVal + myAtr * 0.4) coloured(bullR, bullG, bullB)
    endif
    //----------------------------------------------
    // === ChoCh bajista: cierre cruza el ultimo pivot low en estructura alcista ===
    //----------------------------------------------
    if plReady = 1 and direction = 1 and close crosses under plVal then
       direction = 0
       started = 1
       hitCount = 0
       atrTS = close + myAtr * atrMult
       entryPrice = plVal
       currentTarget = entryPrice - myAtr * targetStepMult
       trendStart = barindex
       labelX = round((plIndx + barindex) / 2)
       drawsegment(plIndx, plVal, barindex, plVal) coloured(bearR, bearG, bearB) style(line, 2)
       drawtext("ChoCh ↓", labelX, plVal - myAtr * 0.4) coloured(bearR, bearG, bearB)
    endif
    //----------------------------------------------
    directionChange = 0
    if started = 1 and direction <> direction[1] then
       directionChange = 1
    endif
    //----------------------------------------------
    // === Trailing stop + cascada de targets ===
    //----------------------------------------------
    if started = 1 then
       if direction = 1 then
          atrTS = max(atrTS, close - myAtr * atrMult)
          if high >= currentTarget then
             if showHistory = 1 then
                perc = round((currentTarget - entryPrice) / entryPrice * 10000) / 100
                drawsegment(trendStart, currentTarget, barindex, currentTarget) coloured(bullR, bullG, bullB) style(dottedline, 1)
                drawtext("+#perc#%", trendStart, currentTarget) coloured(bullR, bullG, bullB)
             endif
             currentTarget = currentTarget + myAtr * targetStepMult
             hitCount = hitCount + 1
          endif
       else
          atrTS = min(atrTS, close + myAtr * atrMult)
          if low <= currentTarget then
             if showHistory = 1 then
                perc = round((currentTarget - entryPrice) / entryPrice * 10000) / 100
                drawsegment(trendStart, currentTarget, barindex, currentTarget) coloured(bearR, bearG, bearB) style(dottedline, 1)
                drawtext("#perc#%", trendStart, currentTarget) coloured(bearR, bearG, bearB)
             endif
             currentTarget = currentTarget - myAtr * targetStepMult
             hitCount = hitCount + 1
          endif
       endif
    else
       atrTS = close   // antes del primer ChoCh: pegado al precio (alpha 0, no distorsiona escala)
    endif
    //----------------------------------------------
    // === Target activo: solo en la ultima barra, proyectado 10 barras ===
    //----------------------------------------------
    if islastbarupdate and started = 1 then
       if hitCount = 0 then
          activeAlpha = 255
       else
          activeAlpha = 153
       endif
       if direction = 1 then
          drawsegment(trendStart, currentTarget, barindex + 10, currentTarget) coloured(bullR, bullG, bullB, activeAlpha) style(line, 2)
       else
          drawsegment(trendStart, currentTarget, barindex + 10, currentTarget) coloured(bearR, bearG, bearB, activeAlpha) style(line, 2)
       endif
    endif
    //----------------------------------------------
    // === Color + visibilidad del trailing stop (alpha toggle) ===
    //----------------------------------------------
    if direction = 1 then
       r = bullR
       g = bullG
       b = bullB
    else
       r = bearR
       g = bearG
       b = bearB
    endif
    
    stopAlpha = 255
    if showStop = 0 or started = 0 or directionChange = 1 then
       stopAlpha = 0
    endif
    
    areaAlpha = 60
    if showStop = 0 or started = 0 then
       areaAlpha = 0
    endif
    
    colorbetween(close, atrTS, r, g, b, areaAlpha)
    //----------------------------------------------
    return atrTS as "ATR Trailing Stop" coloured(r, g, b, stopAlpha) style(line, 2)
    


    Msport71 thanked this post
    #261869 quote
    Msport71
    Participant
    Senior

    Thanks al lot!

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
Msport71 @carlo-pasca Participant
Summary

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

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