1. Inputs lookbackPeriod: Defines the number of bars to consider for calculating swing highs and lows. Default is 20. fibLevel1 to fibLevel5: Fibonacci retracement levels to calculate price levels (23.6%, 38.2%, 50%, 61.8%, 78.6%). useTime: Enables or disables time-based Fibonacci projections. riskPercent: Defines the percentage of risk for trading purposes (currently not used in calculations). 2. Functions isSwingHigh(index): Identifies a swing high at the given index, where the high of that candle is higher than both its previous and subsequent candles. isSwingLow(index): Identifies a swing low at the given index, where the low of that candle is lower than both its previous and subsequent candles. 3. Variables swingHigh and swingLow: Store the most recent swing high and swing low prices. swingHighTime and swingLowTime: Store the timestamps of the swing high and swing low. fib1 to fib5: Fibonacci levels based on the difference between swingHigh and swingLow. 4. Swing Point Detection The script checks if the last bar is a swing high or swing low using the isSwingHigh() and isSwingLow() functions. If a swing high is detected: The high price is stored in swingHigh. The timestamp of the swing high is stored in swingHighTime. If a swing low is detected: The low price is stored in swingLow. The timestamp of the swing low is stored in swingLowTime. 5. Fibonacci Levels Calculation If both swingHigh and swingLow are defined, the script calculates the Fibonacci retracement levels (fib1 to fib5) based on the price difference (priceDiff = swingHigh - swingLow). 6. Plotting Fibonacci Levels Fibonacci levels (fib1 to fib5) are plotted as horizontal lines using the line.new() function. Labels (e.g., "23.6%") are added near the lines to indicate the level. Lines and labels are color-coded: 23.6% → Blue 38.2% → Green 50.0% → Yellow 61.8% → Orange 78.6% → Red 7. Filling Between Fibonacci Levels The plot() function creates lines for each Fibonacci level. The fill() function is used to fill the space between two levels with semi-transparent colors: Blue → Between fib1 and fib2 Green → Between fib2 and fib3 Yellow → Between fib3 and fib4 Orange → Between fib4 and fib5 8. Time-Based Fibonacci Projections If useTime is enabled: The time difference (timeDiff) between the swing high and swing low is calculated. Fibonacci time projections are added based on multiples of 23.6%. If the current time reaches a projected time, a label (e.g., "T1", "T2") is displayed near the high price. 9. Trading Logic Two placeholder variables are defined for trading logic: longCondition: Tracks whether a condition for a long trade is met (currently not implemented). shortCondition: Tracks whether a condition for a short trade is met (currently not implemented). These variables can be extended to define entry/exit signals based on Fibonacci levels. How It Works Detect Swing Points: It identifies recent swing high and swing low points on the chart. Calculate Fibonacci Levels: Based on the swing points, it computes retracement levels. Visualize Levels: Plots the levels on the chart with labels and fills between them. Time Projections: Optionally calculates time-based projections for future price movements. Trading Opportunities: The framework provides tools for detecting potential reversal or breakout zones using Fibonacci levels.