0bps

Strategy vault / Other

Fibonacci Retracement Trading Strategy Script

Pine Script strategy by Zer3192.

Pine ScriptOtherFibonacci
Author
Zer3192
Complexity
Starter · 38 lines
Parameters
4
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

The original spec has no written description. Read the source below.

Parameters

NameDefaultWhat it controls
v_input_150Fibonacci cycle length
v_input_20.236Fibonacci levels1
v_input_30.382Fibonacci levels2
v_input_40.618Fibonacci levels3

Source Pine Script

/*backtest
start: 2022-10-27 00:00:00
end: 2023-11-02 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Fibonacci retracement trading strategy", overlay=true, initial_capital=10000)

// Parameters
length = input(50, title="Fibonacci cycle length")
fib1 = input(0.236, title="Fibonacci levels1")
fib2 = input(0.382, title="Fibonacci levels2")
fib3 = input(0.618, title="Fibonacci levels3")

// Calculate Fibonacci levels
highLevel = ta.highest(high, length)
lowLevel = ta.lowest(low, length)
range1 = highLevel - lowLevel
fibLevel1 = highLevel - range1 * fib1
fibLevel2 = highLevel - range1 * fib2
fibLevel3 = highLevel - range1 * fib3

// condition
longCondition = ta.crossover(close, fibLevel3)
shortCondition = ta.crossunder(close, fibLevel1)

// Place Order
strategy.entry("Buy", strategy.long, when=longCondition)
strategy.close("Buy", when=shortCondition)

// Chart Marker
plot(fibLevel1, title="Fib 0.236", color=color.red)
plot(fibLevel2, title="Fib 0.382", color=color.orange)
plot(fibLevel3, title="Fib 0.618", color=color.green)

Published by Zer3192 on the FMZ strategy square · last modified 2023-11-03. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Fibonacci-Retracement-Trading-Strategy-Script.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open