SuperFib Manual Edit

Main Features
Creates up to 6 horizontal lines at user-defined price levels
Each line has an associated text label (like "Support 1" or "Superfib")
All visual elements are highly customizable
Configuration Options
Global Line Appearance
Customizable line color and thickness (1-4 pixels)
Label Appearance
Text color
Background color with transparency
Text size (Tiny, Small, Normal, Large, Huge)
Position (Left or Right side of the chart)
Individual Line Settings
Each of the 6 lines has its own settings group
For each line, users can set:
Price level (where the line appears)
Custom label text
Technical Implementation
Uses PineScript version 6
Implements helper functions for label size and alignment options
Efficiently manages label objects to prevent memory leaks
Only updates labels on the last bar for better performance
Lines/labels automatically hide if their price input is disabled
This indicator would be useful for traders who want to manually mark important price levels like support/resistance zones, Fibonacci levels, or other significant price points with clear visual indicators and labels. The "SuperFib" part of the name suggests it might be specifically designed for marking Fibonacci retracement or extension levels, though it allows for completely manual placement rather than automatic calculation.RetryClaude can make mistakes. Please double-check responses.
Added Inputs for Lines 7-10: Copied the input blocks for showX, priceX, and textX up to line 10.
Array Input Section (groupArray):
useArrayInput (bool): A toggle to switch between individual settings and array input.
priceArrayStr (string): Input for comma-separated price values.
textArrayStr (string): Input for comma-separated label texts. Tooltip explains behavior if text count doesn't match price count.
Data Preparation Logic:
Introduced intermediate arrays prices, labels, show (using var to persist their state) and an integer levelsToDraw.
An if useArrayInput block now determines the source of data.
If useArrayInput is true:
str.split() is used to break the input strings into arrays of strings.
It iterates through the price strings (up to MAX_LINES).
str.trim() removes leading/trailing whitespace from parsed values.
str.tonumber() converts price strings to floats. Only valid numbers are processed.
It gets the corresponding text, using a default "Level X" if the text array runs out.
It populates the prices, labels, and show arrays only for valid, parsed levels. show is set to true for all array inputs.
levelsToDraw is calculated based on the number of valid price levels parsed from the string.
If useArrayInput is false:
It gathers the values from the individual input.price, input.string, and input.bool variables (1 through 10) into temporary arrays (priceInputs, etc.).
It copies these values directly into the prices, labels, and show arrays.
levelsToDraw is set to MAX_LINES (meaning all 10 individual settings are potentially active).
Drawing Loop Modification:
The main drawing loop still iterates from 0 to MAX_LINES - 1 to handle all potential drawing slots and ensure proper cleanup.
Inside the loop, it retrieves the currentPrice, currentLabel, and currentShow for index i from the prepared prices, labels, and show arrays.
A shouldDraw variable determines if the line/label at index i should actually be drawn based on:
i < levelsToDraw: Ensures we don't try to draw more lines than configured in the active mode (especially important for array mode).
currentShow: Respects the show toggle (relevant for individual input mode, always true for array mode).
not na(currentPrice): Checks if the price is valid.
If shouldDraw is true, drawUpdateLineAndLabel is called.
If shouldDraw is false, deleteLineAndLabel is called to ensure any old drawings in that slot are removed.
Helper Functions: The drawUpdateLineAndLabel function is slightly simplified as the validity/show checks are done before calling it. A dedicated deleteLineAndLabel function is added for clarity.
Array Initialization: lineLabels and hLines are still initialized with MAX_LINES size using var, ensuring the arrays exist and have the correct capacity regardless of how many lines are actually drawn.
Now you have the flexibility to configure up to 10 lines individually or quickly define multiple levels using the comma-separated array inputs.
Horizontal Line Extension (extend property):
Old Version: Lines were created with extend=extend.right.
New Version: Lines are now created with extend=extend.both.
Purpose: This is the direct change that makes the horizontal lines extend infinitely to the left as well as to the right, fulfilling your request.
Fixing the const Keyword Error (Group Definitions):
Old Version: Used const string groupX = input.string(...) for groups 8, 9, and 10. This incorrectly attempted to assign the result of a dynamic input call (input.string) to a const variable, which requires a value known at compile time.
New Version: Corrected these declarations to const string groupX = "Group Name".
Purpose: This fixes the "A variable declared with the "const" keyword cannot accept values of the "unknown" form" compilation error you encountered. You just need the const string for the group name itself; the group and inline arguments on subsequent inputs within that group handle the UI layout.
Refactoring Data Preparation and Drawing Logic:
Old Version: Had a separate "Data Preparation" section that built intermediate prices, labels, show, and levelsToDraw arrays before the main drawing loop. It also used a helper function drawUpdateLineAndLabel that always deleted and recreated objects. The main drawing loop ran on if barstate.islast or barstate.isrealtime.
New Version: Removed the intermediate data preparation arrays (prices, labels, show, levelsToDraw). Removed the drawUpdateLineAndLabel helper function.
Purpose: This simplifies the code structure by directly determining the showThisLine, priceThisLine, and textThisLine for each line index i inside the drawing loop based on useArrayInput. It also integrates the creation/deletion/update logic directly into the main drawing loop, making it more explicit.
Improved Object Management (Real-time vs. Historical):
Old Version: Managed creation, deletion, and updates within a single if barstate.islast or barstate.isrealtime block, often leading to unnecessary deletion and recreation of drawing objects on every bar (including real-time updates) if the line was enabled.
New Version: Separates the logic into:
if barstate.islast: Handles the initial creation, necessary deletion (if inputs change or line is disabled), and recreation (if price/text changes) only on the last historical bar. It also ensures the line endpoint (x2) and label position (x) are set correctly for the last historical bar.
if barstate.isrealtime: A dedicated block that iterates through existing objects and only updates their positions (line.set_x2, label.set_x) to extend them to the current real-time bar.
Purpose: This is a standard and more efficient pattern for managing drawing objects in Pine Script. You generally want to create/delete objects only when absolutely necessary (usually on barstate.islast when inputs are finalized or change) and just update their position on subsequent real-time bars. This avoids flickering and reduces chart drawing load compared to constant deletion/recreation.
Minor Array Initialization Improvement:
Old Version: Initialized var array objects like array.new_label(MAX_LINES) and array.new_line(MAX_LINES).
New Version: Initialized them more explicitly with na: array.new_label(MAX_LINES, na) and array.new_line(MAX_LINES, na).
Purpose: Explicitly initializes the array elements with na (Not Available/Not Assigned for objects), which is clearer and safer when dealing with object references that might be checked for na.
In essence, the updated code addressed the compilation error, implemented the core functional request (left extension), and improved the internal structure and efficiency of how drawing objects are managed across historical and real-time bars.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.
Declinazione di responsabilità
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.