PINE LIBRARY
Zaktualizowano

BecakFloatingPanels

243
Library "BecakFloatingPanels"
Library for creating floating indicator panels with MACD, RSI, and Stochastic indicators

calculateMacd(source, fastLength, slowLength, signalLength)
  Calculate MACD components
  Parameters:
    source (float): Price source for calculation
    fastLength (simple int): Fast EMA period
    slowLength (simple int): Slow EMA period
    signalLength (simple int): Signal line period
  Returns: MacdData MACD calculation results

calculateRsi(source, length)
  Calculate RSI
  Parameters:
    source (float): Price source for calculation
    length (simple int): RSI period
  Returns: float RSI value

calculateStochastic(source, high, low, kLength, kSmoothing, dSmoothing)
  Calculate Stochastic components
  Parameters:
    source (float): Price source for calculation
    high (float): High prices
    low (float): Low prices
    kLength (int): %K period
    kSmoothing (int): %K smoothing period
    dSmoothing (int): %D smoothing period
  Returns: StochData Stochastic calculation results

calculateStochSignals(stochK, stochD, overboughtLevel, oversoldLevel)
  Calculate Stochastic signals
  Parameters:
    stochK (float): Stochastic %K series
    stochD (float): Stochastic %D series
    overboughtLevel (float): Overbought threshold
    oversoldLevel (float): Oversold threshold
  Returns: StochSignals Signal flags

calculateChartMetrics(high, low, lookbackLength)
  Calculate chart range and positioning metrics
  Parameters:
    high (float): High prices
    low (float): Low prices
    lookbackLength (int): Lookback period
  Returns: ChartMetrics Chart positioning data

calculateMacdRange(macdLine, signalLine, histogram, safeLookback)
  Calculate MACD range for normalization
  Parameters:
    macdLine (float): MACD line series
    signalLine (float): Signal line series
    histogram (float): Histogram series
    safeLookback (int): Lookback period
  Returns: MacdRange MACD range metrics

initVisualArrays()
  Initialize visual arrays
  Returns: VisualArrays Container with initialized arrays

clearVisuals(visuals)
  Clear all visual elements
  Parameters:
    visuals (VisualArrays): VisualArrays container
  Returns: void

calculatePanelPositions(chartMetrics, oscPlacement, panelHeight, panelSpacing, centerOffset)
  Calculate panel positions based on placement option
  Parameters:
    chartMetrics (ChartMetrics): Chart metrics object
    oscPlacement (string): Panel placement option
    panelHeight (float): Panel height percentage
    panelSpacing (float): Panel spacing percentage
    centerOffset (float): Center offset percentage
  Returns: PanelPositions Panel boundary coordinates

createPanelBackgrounds(visuals, positions, panelLeft, panelRight, showBackground, transparency)
  Create panel backgrounds
  Parameters:
    visuals (VisualArrays): VisualArrays container
    positions (PanelPositions): PanelPositions object
    panelLeft (int): Left boundary
    panelRight (int): Right boundary
    showBackground (bool): Show background flag
    transparency (int): Background transparency
  Returns: void

drawReferenceLines(visuals, positions, chartMetrics, macdRange, dataLeft, dataRight, panelHeight, rsiOverbought, rsiOversold, stochOverbought, stochOversold)
  Draw reference lines for all panels
  Parameters:
    visuals (VisualArrays): VisualArrays container
    positions (PanelPositions): PanelPositions object
    chartMetrics (ChartMetrics): ChartMetrics object
    macdRange (MacdRange): MacdRange object
    dataLeft (int): Left data boundary
    dataRight (int): Right data boundary
    panelHeight (float): Panel height percentage
    rsiOverbought (int): RSI overbought level
    rsiOversold (int): RSI oversold level
    stochOverbought (int): Stochastic overbought level
    stochOversold (int): Stochastic oversold level
  Returns: void

drawMacdIndicator(visuals, macdLine, signalLine, histogram, macdRange, positions, chartMetrics, barIndex, nextBarIndex, barIndexOffset, panelHeight)
  Draw MACD indicator
  Parameters:
    visuals (VisualArrays): VisualArrays container
    macdLine (float): MACD line series
    signalLine (float): Signal line series
    histogram (float): Histogram series
    macdRange (MacdRange): MacdRange object
    positions (PanelPositions): PanelPositions object
    chartMetrics (ChartMetrics): ChartMetrics object
    barIndex (int): Current bar index
    nextBarIndex (int): Next bar index
    barIndexOffset (int): Horizontal offset
    panelHeight (float): Panel height percentage
  Returns: void

drawRsiIndicator(visuals, rsiValue, positions, chartMetrics, barIndex, nextBarIndex, barIndexOffset, panelHeight)
  Draw RSI indicator
  Parameters:
    visuals (VisualArrays): VisualArrays container
    rsiValue (float): RSI value
    positions (PanelPositions): PanelPositions object
    chartMetrics (ChartMetrics): ChartMetrics object
    barIndex (int): Current bar index
    nextBarIndex (int): Next bar index
    barIndexOffset (int): Horizontal offset
    panelHeight (float): Panel height percentage
  Returns: void

drawStochasticIndicator(visuals, stochK, stochD, positions, chartMetrics, barIndex, nextBarIndex, barIndexOffset, panelHeight, stochOverbought, stochOversold)
  Draw Stochastic indicator
  Parameters:
    visuals (VisualArrays): VisualArrays container
    stochK (float): Stochastic %K series
    stochD (float): Stochastic %D series
    positions (PanelPositions): PanelPositions object
    chartMetrics (ChartMetrics): ChartMetrics object
    barIndex (int): Current bar index
    nextBarIndex (int): Next bar index
    barIndexOffset (int): Horizontal offset
    panelHeight (float): Panel height percentage
    stochOverbought (int): Overbought level
    stochOversold (int): Oversold level
  Returns: void

addStochasticSignals(visuals, buySignal, sellSignal, positions, chartMetrics, currentBarIndex, barIndexOffset, panelHeight, signalIndex)
  Add Stochastic buy/sell signals
  Parameters:
    visuals (VisualArrays): VisualArrays container
    buySignal (bool): Buy signal series
    sellSignal (bool): Sell signal series
    positions (PanelPositions): PanelPositions object
    chartMetrics (ChartMetrics): ChartMetrics object
    currentBarIndex (int): Current bar index
    barIndexOffset (int): Horizontal offset
    panelHeight (float): Panel height percentage
    signalIndex (int): Signal index for lookback
  Returns: void

setPanelLabels(macdLabel, rsiLabel, stochLabel, positions, chartMetrics, labelOffset, panelHeight, barIndexOffset)
  Set panel title labels
  Parameters:
    macdLabel (label): MACD label reference
    rsiLabel (label): RSI label reference
    stochLabel (label): Stochastic label reference
    positions (PanelPositions): PanelPositions object
    chartMetrics (ChartMetrics): ChartMetrics object
    labelOffset (int): Label horizontal offset
    panelHeight (float): Panel height percentage
    barIndexOffset (int): Horizontal offset
  Returns: void

showDebugInfo(chartMetrics, debugMode)
  Display debug information
  Parameters:
    chartMetrics (ChartMetrics): ChartMetrics object
    debugMode (bool): Debug mode flag
  Returns: void

ChartMetrics
  Chart metrics container
  Fields:
    visibleHigh (series float): Highest visible price
    visibleLow (series float): Lowest visible price
    chartRange (series float): Price range of chart
    chartCenter (series float): Center point of chart

MacdData
  MACD calculation results
  Fields:
    macdLine (series float): Main MACD line
    signalLine (series float): Signal line
    histogram (series float): MACD histogram

MacdRange
  MACD range metrics for normalization
  Fields:
    highest (series float): Highest MACD value
    lowest (series float): Lowest MACD value
    BRange (series float): Total range

StochData
  Stochastic calculation results
  Fields:
    k_smooth (series float): Smoothed %K line
    d (series float): %D line

StochSignals
  Stochastic signals
  Fields:
    buySignal (series bool): Buy signal flag
    sellSignal (series bool): Sell signal flag

PanelPositions
  Panel positioning data
  Fields:
    macdTop (series float): MACD panel top
    macdBottom (series float): MACD panel bottom
    rsiTop (series float): RSI panel top
    rsiBottom (series float): RSI panel bottom
    stochTop (series float): Stochastic panel top
    stochBottom (series float): Stochastic panel bottom

VisualArrays
  Visual elements arrays container
  Fields:
    macdLines (array<line>): Array of MACD lines
    macdHist (array<box>): Array of MACD histogram boxes
    rsiLines (array<line>): Array of RSI lines
    stochLines (array<line>): Array of Stochastic lines
    stochAreas (array<box>): Array of Stochastic areas
    stochSignals (array<label>): Array of Stochastic signals
    panelBackgrounds (array<box>): Array of panel backgrounds
Informacje o Wersji
v2 change the chart to make it clear
Informacje o Wersji
v3fixed the main issue with the indicator lines not showing properly. The problem was in how the bar indices were being calculated for drawing the lines.
🔧 Key Fixes Made:
1. Bar Index Calculation:
Before:

Pine Script®
pinescriptbar_index[barIndex] + barIndexOffset

After:
Pine Script®
pinescriptbar_index - barIndex + barIndexOffset


2. What Was Wrong:
The original code was using bar_index[barIndex] which tries to get a historical value of bar_index itself
This was causing incorrect X-coordinates for the lines, making them not visible or positioned incorrectly

3. What's Fixed Now:

MACD Lines: Blue MACD line and orange signal line will now draw properly
RSI Line: Purple RSI line will show correctly in the middle panel
Stochastic Lines: Blue %K and orange %D lines will display properly
Histogram: MACD histogram bars will appear correctly
Signals: Buy/sell signals will be positioned correctly

🎯Fix Works:
The corrected formula bar_index - barIndex + barIndexOffset properly calculates the X-coordinate by:

Pine Script®
Taking the current bar index (bar_index) Subtracting the historical offset (barIndex) Adding the positioning offset (barIndexOffset)


This ensures the lines are drawn at the correct horizontal positions within the floating panels.
✅ Expected Results:
MACD Panel: Clear blue and orange lines with histogram bars
RSI Panel: Smooth purple RSI line oscillating between 0-100
Stochastic Panel: Blue %K and orange %D lines with overbought/oversold areas

Wyłączenie odpowiedzialności

Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.