Indicator · Pine Script v6 · On the chart

Log Scale Fibonacci (LSF)

by ktg0413· code credited to kimteagyun0413

Draws a Fibonacci channel on a logarithmic price scale on the price chart.

View on GitHub

Repaints

GitHub stars1on the repository
Pine versionv6current
Lines of code136
Settings3inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago12 Oct 2025

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

136 lines of Pine Script v6 from Log Scale Fibonacci(LSF)/Log Scale Fibonacci(LSF).pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Log Scale Fibonacci(LSF).pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kimteagyun0413

//@version=6
indicator("Log Scale Fibonacci(LSF)", overlay=true)

// User input: Set key dates / 사용자 입력: 주요 날짜 설정
x1 = input.time(timestamp("2021-04-01"), title="First High Date")
x2 = input.time(timestamp("2017-12-01"), title="Second High Date")
x3 = input.time(timestamp("2020-03-01"), title="Low Date")

// Fetch monthly data (using request.security) / 월봉 데이터 가져오기 (request.security 사용)
monthlyHigh = request.security(syminfo.tickerid, "1M", high, lookahead=barmerge.lookahead_on)
monthlyLow = request.security(syminfo.tickerid, "1M", low, lookahead=barmerge.lookahead_on)

// Map monthly data to specific dates / 특정 날짜에 해당하는 월봉 데이터 매핑
var float y1 = na
var float y2 = na
var float y3 = na
var int x1_idx = na
var int x2_idx = na
var int x3_idx = na

// Check if current bar's timestamp matches input dates / 현재 봉의 타임스탬프가 입력된 날짜와 일치하는지 확인
if time >= x1 and time < x1 + 30 * 86400000 and na(y1)
    y1 := monthlyHigh
    x1_idx := bar_index
if time >= x2 and time < x2 + 30 * 86400000 and na(y2)
    y2 := monthlyHigh
    x2_idx := bar_index
if time >= x3 and time < x3 + 30 * 86400000 and na(y3)
    y3 := monthlyLow
    x3_idx := bar_index

// Logarithmic transformation / 로그화
var float log_y1 = na
var float log_y2 = na
var float log_y3 = na
if not na(y1) and y1 > 0
    log_y1 := math.log10(y1)
if not na(y2) and y2 > 0
    log_y2 := math.log10(y2)
if not na(y3) and y3 > 0
    log_y3 := math.log10(y3)

// Calculate slope / 기울기 계산
var float slop = na
if not na(log_y1) and not na(log_y2) and not na(x1_idx) and not na(x2_idx) and x1_idx != x2_idx
    slop := (log_y1 - log_y2) / (x1_idx - x2_idx)

// Calculate base points / 기준점 계산
var float base_upper = na
var float base_lower = na
if not na(log_y2) and not na(x2_idx) and not na(slop)
    base_upper := log_y2 - slop * x2_idx  // Upper line (y-intercept based on y2) / 상단선 (y2 기준 y절편)
if not na(log_y3) and not na(x3_idx) and not na(slop)
    base_lower := log_y3 - slop * x3_idx  // Lower line (y-intercept based on y3) / 하단선 (y3 기준 y절편)

// Define Fibonacci levels / 피보나치 레벨 정의
var float[] fib_levels = array.new_float(7)
array.set(fib_levels, 0, 0.0)    // 0%
array.set(fib_levels, 1, 0.236)  // 23.6%
array.set(fib_levels, 2, 0.382)  // 38.2%
array.set(fib_levels, 3, 0.5)    // 50%
array.set(fib_levels, 4, 0.618)  // 61.8%
array.set(fib_levels, 5, 0.764)  // 76.4%
array.set(fib_levels, 6, 1.0)    // 100%

// Variable to store line objects / 라인 객체를 저장할 변수
var line[] fib_lines = array.new_line()

// Get first and last bar_index of current chart (works on all timeframes) / 현재 차트의 처음과 끝 bar_index 가져오기 (모든 시간 프레임에서 동작)
var int first_bar = na
var int last_bar = na
if barstate.isfirst
    first_bar := bar_index
if barstate.islast
    last_bar := bar_index

// Draw Fibonacci levels based on monthly data in lower timeframes / 하위 시간대에서 월봉 기반 피보나치 레벨 그리기
if not na(first_bar) and not na(last_bar) and not na(slop) and not na(base_upper) and not na(base_lower)
    past_extend_bars = -1000  // Extend to the left (negative value) / 왼쪽으로 연장 (음수 값)
    future_extend_bars = 20   // Extend to the right / 오른쪽 연장
    extended_first_bar = first_bar + past_extend_bars
    extended_last_bar = last_bar + future_extend_bars
    
    step = (extended_last_bar - extended_first_bar) / 50
    
    // Define sub-Fibonacci levels (ratios to use within each channel) / 서브 피보나치 레벨 정의 (각 채널 내에서 사용할 비율)
    var float[] sub_fib_levels = array.new_float(4)
    array.set(sub_fib_levels, 0, 0.236)  // 23.6%
    array.set(sub_fib_levels, 1, 0.382)  // 38.2%
    array.set(sub_fib_levels, 2, 0.5)    // 50%
    array.set(sub_fib_levels, 3, 0.618)  // 61.8%
    
    // Remove previously drawn lines / 이전에 그려진 라인 제거
    if array.size(fib_lines) > 0
        for i = 0 to array.size(fib_lines) - 1
            line.delete(array.get(fib_lines, i))
        array.clear(fib_lines)
    
    // Draw lines / 라인 그리기
    for i = 0 to 49
        x_start = extended_first_bar + i * step
        x_end = extended_first_bar + (i + 1) * step
        
        // Draw main Fibonacci levels / 주요 피보나치 레벨 그리기
        for j = 0 to array.size(fib_levels) - 1
            fib_level = array.get(fib_levels, j)
            fib_log_level = base_lower + (base_upper - base_lower) * fib_level
            fib_start = math.pow(10, slop * x_start + fib_log_level)
            fib_end = math.pow(10, slop * x_end + fib_log_level)
            
            fib_color = j == 0 ? color.green :    // 0%
                       j == 6 ? color.red :       // 100%
                       j == 3 ? color.blue :      // 50%
                       color.gray                 // Others / 나머지
            fib_line = line.new(x_start, fib_start, x_end, fib_end, color=fib_color, width=2)
            array.push(fib_lines, fib_line)
            
            // Draw sub-Fibonacci levels (excluding the last main level) / 서브 피보나치 레벨 그리기 (마지막 주요 레벨 제외)
            if j < array.size(fib_levels) - 1
                next_fib_level = array.get(fib_levels, j + 1)
                next_fib_log_level = base_lower + (base_upper - base_lower) * next_fib_level
                
                // Calculate and draw sub-Fibonacci levels within each channel / 각 채널 내에서 서브 피보나치 레벨 계산 및 그리기
                for k = 0 to array.size(sub_fib_levels) - 1
                    sub_fib_ratio = array.get(sub_fib_levels, k)
                    sub_fib_log_level = fib_log_level + (next_fib_log_level - fib_log_level) * sub_fib_ratio
                    sub_fib_start = math.pow(10, slop * x_start + sub_fib_log_level)
                    sub_fib_end = math.pow(10, slop * x_end + sub_fib_log_level)
                    
                    // Distinguish sub-levels with lighter color or different style / 서브 레벨은 더 연한 색상 또는 다른 스타일로 구분
                    sub_fib_color = color.new(fib_color, 70)  // Lighter with 70% transparency / 투명도 70으로 연하게
                    sub_fib_line = line.new(x_start, sub_fib_start, x_end, sub_fib_end, color=sub_fib_color, width=1, style=line.style_dashed)
                    array.push(fib_lines, sub_fib_line)

Overview

The user sets two high dates and one low date; the script reads monthly highs and lows around those dates, converts them to base-10 logarithms and derives a sloped channel from the two highs and the low. Fibonacci levels from 0 to 1, including 0.236, 0.382, 0.5 and 0.618, are drawn between the lines and extended left and forward. Monthly data is requested with lookahead on.

Details

Published by

ktg0413 on GitHub

Code credit

kimteagyun0413, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Support & resistance

Markets

Any symbol

Timeframes

H4 and above

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
First High Datetimetimestamp("2021-04-01")x1
Second High Datetimetimestamp("2017-12-01")x2
Low Datetimetimestamp("2020-03-01")x3
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us

Indicator v4 Moving averagesSupport & resistance
Updated 11 days ago · GPL-3.0 GitHub repository of Moving Average Channel

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows
330 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 2 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

BZ-tracker

by Allen1212
303 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 2 years ago · None stated GitHub repository of BZ-tracker

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 4 years ago · None stated GitHub repository of Function - Linear Regression

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers