Strategy · Pine Script v6 · On the chart

Fibonacci strategy

by JoelPasapera· code credited to JJPP_Joel

This strategy plots a Fibonacci retracement of the previous day's high-low range on the price chart.

View on GitHub

GitHub stars11on the repository
Pine versionv6current
Lines of code48
Settings4inputs
LicenceApache-2.0
Last update5 months ago23 May 2026

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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

48 lines of Pine Script v6 from Fibonacci strategy/Fibonacci strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

Fibonacci strategy.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JJPP_Joel
// Author: Joel Pasapera Pinto
//@version=6

//@version=6
strategy("Fibonacci strategy", overlay = true, margin_long = 100, initial_capital = 10000)

// ==========================
// Function: obtain the maximum and minimum values from the previous day
// ==========================
get_prev_day_high_low() =>
    high_prev = request.security(syminfo.tickerid, "D", high[1])
    low_prev  = request.security(syminfo.tickerid, "D", low[1])
    [high_prev, low_prev]

// ==========================
// Parameters
// ==========================
float lot_size = input.float(1,"lot_size",step=0.1,minval=0.1)
int hold_hours = input.int(8, "Hours to maintain operation")
float fib_level  = input.float(0.382, "Fibonacci level")
int entry_hour = input.int(8, "entry hour")

// ==========================
// Calc Fibonacci
// ==========================
[high_prev, low_prev] = get_prev_day_high_low()
fib_038 = high_prev - (high_prev - low_prev) * fib_level

long_condition = (hour == entry_hour and close < fib_038)

if long_condition and strategy.opentrades == 0
    strategy.entry("BuyFib", strategy.long, limit = fib_038, qty = lot_size)

// ==========================
// Departure after N hours
// ==========================
bars_in_trade = ta.barssince(strategy.opentrades == 0)

if strategy.position_size > 0 and bars_in_trade >= hold_hours
    strategy.close("BuyFib", comment = "Cierre por tiempo")

// ==========================
// Drawings on the chart
// ==========================

plot(fib_038, "Fib 0.382", color = color.orange, linewidth = 2)

Overview

Fibonacci strategy places a single long limit order at that level when the bar hour matches the chosen entry hour and the close is below the level. Position size follows the lot size input. It closes the trade after a set number of bars rather than using a price stop or profit target. The main settings change the Fibonacci ratio, entry hour, hold length, and lot size. The hold length counts bars, and there is no stop loss by default.

Details

Published by

JoelPasapera on GitHub

Code credit

JJPP_Joel, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Support & resistance, Sessions & time

Markets

Forex, Gold, Stocks

Timeframes

M15-H1, H4 and above

Risk Notes

  • The strategy enters trades without a stop loss

Topics

botpinescriptstrategytradingtradingview

Settings

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

SettingTypeDefaultVariable
lot_sizefloat1lot_size
Hours to maintain operationint8hold_hours
Fibonacci levelfloat0.382fib_level
entry hourint8entry_hour
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

Daily Bias + FVG Strategy

by TradersPost
218 stars

This overlay strategy plots previous-day high and low, the daily open, and fair value gap zones on the price chart. It takes entries on a selectable timeframe when the FVG requirement and an optional session window allow them, then uses an ATR or fixed pip sto

Strategy v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Daily Bias + FVG Strategy
106 stars

This script monitors opening gap conditions and breakout behavior relative to the first candle's range across up to twenty configurable stock tickers. It detects whether following bars remain inside the opening range before breaking out, displaying the status

Strategy v4 Screeners & dashboardsBreakout Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 1St Bar GAP+BkOut Screener v2 by RM

ATOM 1m scalp HK

by dearvn
43 stars

This overlay strategy targets one-minute ATOM scalps. It tracks pivot highs and lows as resistance and support, compares a three-period EMA with a multi-stage smoothed close, and flags long or short when price crosses that curve in the matching direction. Dail

Strategy v5 ScalpingSupport & resistance Repaints
Updated 2 years ago · None stated GitHub repository of ATOM 1m scalp HK

P404 Smoke

by Musyimi97
16 stars

P404 Smoke is a price-chart strategy that sequences an optional higher-timeframe EMA bias, a liquidity range from recent pivots, a sweep of buy-side or sell-side liquidity, and a market structure shift within a set bar window. Comments state it then looks for

Strategy v5 SMC / ICT / price actionSupport & resistance
Updated 6 months ago · MIT GitHub repository of P404 Smoke

1-Min Gold Taylor Technique

by eddiebelaval
7 stars

This intraday strategy implements session-based trading rules tailored for gold on short timeframes. It tracks the Asian session price range, VWAP, 20-period EMA, and previous day high and low levels to identify liquidity sweeps during London and New York trad

Strategy v6 Sessions & timeSupport & resistance
Updated 3 months ago · None stated GitHub repository of 1-Min Gold Taylor Technique
6 stars

This strategy combines Opening Range Breakout (ORB) mechanics with Inner Circle Trader (ICT) concepts like Fair Value Gaps, Order Blocks, and liquidity grabs. It identifies session opening ranges and generates signals when price breaks out with supporting rela

Strategy v5 BreakoutSMC / ICT / price action
Updated 7 months ago · None stated GitHub repository of Advanced ORB + ICT Strategy

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers