Fibonacci Trading Bot: Define the Rules Before the Code
A Fibonacci trading bot applies a written retracement or extension rule. Define the swing before the code, for example a pullback into the 50% to 61.8% zone and a close back above 50%. The ratios do not create the strategy. The bot still needs exits, position sizing, and failure handling, and those ratios do not make the bot profitable.
Direct answer
A five-right-bar pivot is confirmed only after those five later bars finish. On uninterrupted five-minute bars, that wait is 25 minutes after the candidate bar closes. Put the stop beyond the swing low and size the trade to a fixed account risk before you generate code. This specification does not claim the bot will make money.
Rules the bot needs before it can trade
Swing logic
Confirmed pivots or a fixed session range
Entry
Exact level plus a bar-close condition
Exit
Stop, target, timeout, and cancellation
Risk
Position size from stop distance
A testable Fibonacci bot specification
The baseline uses a close above EMA(200) and pivots with five bars on the left and five on the right. It is a research specification, not a recommended live strategy, and it does not promise a profit. Every value should be an input and should be tested with realistic costs.
| Decision | Example rule | Why it must be explicit |
|---|---|---|
| Trend | Close above EMA(200) | Limits long setups to one regime |
| Swing | Five left and five right pivot bars | Defines confirmation delay; freeze selected anchors separately |
| Entry | Close back above the 50% level | Defines the trigger bar |
| Stop | Below the confirmed swing low | Defines invalidation |
| Target | Prior high, then 1.272 extension | Defines the exit sequence |
| Risk | 0.5% of equity per trade | Connects stop distance to size |
From chart idea to bot specification
- 1
Write the market and timeframe
A SPY daily strategy and an ETH five-minute strategy need different sessions, costs, and risk assumptions. Build one system at a time.
- 2
Make the swing rule deterministic
Use confirmed pivots, such as five bars on each side, a fixed opening range, or another rule the code can calculate without hindsight. A five-right-bar pivot is not available until those five bars have closed.
- 3
Define entry and cancellation
State the exact level, confirmation event, and the condition that cancels an unfilled setup.
- 4
Define every exit
Include the protective stop, profit target, time exit, and what happens if the chart gaps beyond an order.
- 5
Backtest before automation
Use actual commission, spread, and slippage assumptions. Keep holdout data separate from the period used to choose settings.
Checks before generating bot code
Write the pivot-selection and confirmation rule before generating code. Include tie handling and the moment the anchors become available.
Keep the risk budget separate from the signal rule and cap quantity by buying power as well as stop distance.
Retain rejected setups, cancellations and filled trades. Evaluate each rule change on a fixed sample rather than assuming cancellations improve results.
A bot should expose its assumptions
A black-box signal can hide how swings were chosen or when a level moved. An inspectable strategy shows the anchor rule, active ratio, confirmation event, stop, target, and order timing.
Pine Script strategies simulate chart-based orders and can trigger alerts; they do not by themselves submit live broker orders. A separate execution bridge needs permissions, duplicate-order handling and risk controls. An MQL5 Expert Advisor can use trading APIs under terminal and broker permissions, but an indicator is not itself an EA.
Avoid lookahead in swing detection
A five-right-bar pivot is confirmed only after those five subsequent bars complete. On uninterrupted five-minute bars, that is 25 minutes after the candidate bar closes, or 30 minutes after its opening timestamp. Code must wait for those bars before using the pivot.
Plotting a pivot back on the original bar is fine for display, but the strategy cannot act as if it knew the pivot earlier. The exact extreme occurred somewhere within that candidate bar. Session breaks can make the wall-clock delay longer.
- Place orders only after the selected confirmation is available.
- Use bar magnifier or lower-timeframe data only when the test documents it.
- Reject fills that depend on prices unavailable under the chosen order model.
Automation does not remove trading risk
A bot can apply rules consistently and still lose money. Market regime changes, gaps, spread, latency, and bad parameter choices remain part of the system.
Start with paper trading or alerts. Compare live paper fills with the backtest before considering broker-connected execution.
Position sizing from stop distance
This illustrative example uses a $20,000 account, a 0.5% risk limit, a $510 entry, and a $505 stop.
Risk-based share ceiling = planned dollar risk / abs(entry price - stop price)
Account equity = $20,000 Risk limit = 0.5% Risk budget = $100 Entry = $510 Stop = $505 Risk per share = $5 Maximum size before costs = 20 shares
Twenty shares cost $10,200 at the example $510 entry. Also apply buying-power, lot-size and fee constraints. Gaps can produce a realized loss larger than the planned $100 budget.
Generate an editable Fibonacci strategy
Pineify can draft a strategy for source review and TradingView simulation. Complete the unspecified order details before treating the draft as an automated trading system.
Create a Pine Script v6 strategy for long setups on SPY. Use EMA(200) as a trend filter and confirmed pivots with five left and five right bars. Draw the 50%, 61.8%, and 78.6% retracement levels from the latest confirmed upswing. Enter only after a bar closes back above 50% following a touch of the 50% to 61.8% zone. Stop below the swing low, take partial profit at the prior high, and exit the remainder at the 1.272 extension. Size each trade to 0.5% of equity and include commission and slippage inputs. Explicitly choose strict or tie-inclusive pivots and define which confirmed low/high pair is frozen for each setup. Do not backdate signals to anchor bars. Expose a tick buffer for stops, percentage quantity for the partial exit, setup expiry and timeout, and cancel unfilled orders when invalidated. Keep signals, simulated fills and external live orders separate. Cap quantity by buying power and skip cases with missing inputs or invalid stop distance.Open the MQL5 workflow
Continue the analysis
Tools for the next check
Vibe Coding a Trading Bot
Turn a plain-language bot idea into a bounded specification, reviewed source, realistic backtest, and paper-trading plan.
Fibonacci Auto Indicator for MT5
Define an automatic Fibonacci indicator for MetaTrader 5 with explicit pivot and redraw rules.
Fibonacci Strategy Optimization
Generate and compare Fibonacci TradingView strategy parameters with documented entry, exit, and cost assumptions.
Fibonacci Day Trading Strategy
Test a SPY five-minute Fibonacci pullback rule with fixed anchors, invalidation, costs, and TradingView automation.
Trend-Based Fibonacci Extension
Draw a three-point Fibonacci extension, calculate common targets, and keep TradingView anchors consistent.
Sources and method notes
This page is an information tool, not investment advice. Automated strategies can lose money. Backtests, paper trades, and generated code do not guarantee live execution or returns.