Skip to main content

Farey Sequence Weighted Moving Average (FSWMA): Complete TradingView Guide

· 11 min read

The Farey Sequence Weighted Moving Average (FSWMA) represents a fascinating intersection of pure mathematics and technical analysis. While most moving averages use simple or exponential weighting schemes, the FSWMA applies the elegant mathematical pattern of the Farey sequence to assign weights to historical price data.

I've been exploring this indicator for some time now, and what strikes me is how the Farey sequence creates a naturally balanced weighting pattern. Unlike arbitrary weight assignments, the Farey sequence follows strict mathematical rules that ensure every fraction is in its simplest form, creating a harmonious distribution of importance across historical prices.

In this guide, I'll walk you through everything you need to know about the FSWMA - from understanding the mathematical foundation to implementing it on TradingView and incorporating it into your trading strategy. Whether you're a math enthusiast or simply looking for a fresh approach to trend analysis, this indicator offers something genuinely different from conventional moving averages.

FSWMA Chart

Understanding the Farey Sequence Weighted Moving Average

Let me explain what makes the FSWMA so mathematically interesting. The Farey sequence is a collection of fractions arranged in order of magnitude, where each fraction is in its simplest form. For example, the Farey sequence of order 4 includes fractions like 1/4, 1/3, 1/2, 2/3, and 3/4 - each representing a specific mathematical relationship.

The brilliance of applying this to moving averages lies in how the sequence naturally balances short-term and long-term weights. Rather than exponentially decaying weights (like EMA) or linear weights (like WMA), the FSWMA creates a more nuanced distribution that captures both recent momentum and longer-term trends simultaneously.

Why FSWMA Works:

  • Mathematical elegance - Uses proven mathematical sequences rather than arbitrary parameters
  • Balanced weighting - Automatically balances short-term and long-term price importance
  • Customizable complexity - Order parameter allows tuning from simple to sophisticated smoothing
  • Trend identification - Higher orders capture longer-term trends while remaining responsive
  • Noise reduction - Farey sequence weighting naturally filters market noise

The order parameter (ranging from 2 to 14) controls how many terms in the Farey sequence are used for weighting. Lower orders respond more quickly to price changes, while higher orders create smoother lines that better represent long-term trends.

The Best Pine Script Generator

How the FSWMA Indicator Works

Now let me explain the mechanics of how the FSWMA calculates its values. Understanding this will help you choose the right order parameter and interpret the indicator effectively.

The Mathematical Foundation:

The FSWMA uses fractions from the Farey sequence to assign weights to historical price data. Each order expands the sequence, incorporating more historical data points with increasingly sophisticated weighting patterns.

For example:

  • Order 2 uses weights based on fractions with denominators up to 2: 1/1, 1/2
  • Order 5 (the default) incorporates fractions up to 1/5, creating a more complex weighting scheme
  • Order 14 uses the most comprehensive set of fractions, resulting in the smoothest output

The Calculation Process:

Looking at the Pine Script code, the indicator calculates weighted averages by multiplying each historical price by its corresponding Farey fraction weight, then dividing by the sum of all weights. This creates a smoothed line that responds to price movements while filtering out short-term volatility.

Visual Representation:

The FSWMA displays as a smooth line on your chart:

  • Typically shown in a distinct color (purple in the default configuration)
  • Line thickness is customizable
  • Can be set to change color based on trend direction
  • Overlays directly on the price chart

Key Parameters:

  • Source - The price data to use (close, open, high, low, etc.)
  • Order - The complexity level (2-14), higher = smoother but more lag
  • Highlight Movements - Optional feature to color-code based on trend direction

How to Add FSWMA to TradingView

Let me walk you through getting this indicator running on your charts. I've found this method gives the best results with minimal hassle.

The Smart Way (Using Pineify):

  1. Access Pineify - Go to Pineify.app and set up your account
  2. Search the library - Look for "FSWMA" or "Farey Sequence Weighted Moving Average"
  3. Generate clean code - The platform creates optimized Pine Script code automatically
  4. Deploy to TradingView - Copy the code to TradingView's Pine Script Editor and add to your chart

What you'll get:

The generated FSWMA indicator comes with customizable parameters - you can adjust the order, source, and visual styling directly from the indicator settings.

Manual Installation Steps:

If you prefer the DIY approach:

  1. Open TradingView and go to the Pine Script Editor
  2. Create a new indicator script
  3. Paste the FSWMA code
  4. Save and add to your chart
  5. Adjust the order parameter to your preference

The Pine Script implementation handles all the mathematical calculations correctly. Getting this right manually can be tricky, which is why using Pineify's generated code ensures accuracy.

How to Use the FSWMA Indicator Effectively

Once you have the FSWMA on your chart, here's how to actually use it to make better trading decisions. I'll focus on the applications that matter most in real trading.

Reading the Basic Signals:

The FSWMA provides several key pieces of information:

  • Trend direction - When price is above the FSWMA line, the trend is bullish
  • Trend strength - The distance between price and the FSWMA indicates momentum
  • Support and resistance - The FSWMA line itself can act as dynamic support/resistance
  • Trend changes - When price crosses the FSWMA line, it signals potential trend reversals

Order Parameter Selection:

The order parameter is your primary adjustment tool:

Lower Orders (2-5):

  • More responsive to price changes
  • Good for shorter-term trading
  • Generates more trading signals
  • Less smooth, more whipsaws

Higher Orders (10-14):

  • Smoother line with less noise
  • Better for long-term trend identification
  • Fewer but more reliable signals
  • More lag, later entry points

My Recommendation:

Start with order 5 (the default) and adjust based on your trading timeframe. Day traders might prefer orders 3-4, while swing traders often find orders 7-10 work best.

Trading Strategies That Work:

Trend Following:

  • Enter long when price crosses above the FSWMA
  • Enter short when price crosses below the FSWMA
  • Use the FSWMA angle to confirm trend strength
  • Ride the trend until price breaks the FSWMA in the opposite direction

Dynamic Support and Resistance:

  • Use the FSWMA line as a trailing support level in uptrends
  • Use it as dynamic resistance in downtrends
  • Wait for price to test the FSWMA and bounce
  • Enter on confirmation candles

Multi-Timeframe Analysis:

  • Use higher-order FSWMA on higher timeframes for trend direction
  • Use lower-order FSWMA on lower timeframes for entry timing
  • Only trade in the direction of the higher timeframe trend

Confluence Trading:

The most powerful setups occur when FSWMA signals align with other technical factors:

  • Horizontal support and resistance levels
  • Other moving averages (e.g., 50 EMA, 200 SMA)
  • Fibonacci retracement levels
  • Trend line breaks

Risk Management:

  • Always use stops - FSWMA signals aren't guarantees
  • Don't risk more than 1-2% on any single trade
  • Wait for confirmation before entering
  • The FSWMA is a trend indicator, not a prediction tool

Best FSWMA Indicator Settings

Here's what you need to know about FSWMA settings - the order parameter is your main adjustment knob, and understanding its impact is key to getting the most from this indicator.

Understanding the Order Parameter:

The order determines how many terms from the Farey sequence are used in the calculation:

  • Each increase in order adds more weight combinations
  • Higher orders incorporate more historical data
  • The smoothing effect becomes more pronounced

Practical Settings by Timeframe:

For Day Trading (5-minute to 1-hour charts):

  • Order 3-4 provides good balance of responsiveness and smoothness
  • Focus on crossovers with price for entry signals
  • Combine with volume confirmation

For Swing Trading (4-hour to daily charts):

  • Order 5-7 works well for most markets
  • Use the FSWMA as dynamic support/resistance
  • Look for trend continuations after pullbacks to the line

For Position Trading (weekly charts):

  • Order 8-10 captures major trends
  • Less noise, more reliable signals
  • Use for long-term directional bias

Display Customization:

  • Line color - Match your chart theme or use contrasting colors
  • Line width - Thicker lines are easier to see on busy charts
  • Highlight movements - Enable to see color changes based on trend direction

Combining with Other Indicators:

RSI Confirmation:

  • Wait for RSI oversold/overbought conditions alongside FSWMA signals
  • Adds confluence to entries

MACD Divergence:

  • Look for divergences between price and MACD
  • Confirm with FSWMA crossovers

ATR for Stops:

  • Use ATR to set stop distances below/above the FSWMA
  • Adapts to market volatility

My Honest Assessment:

The FSWMA isn't a magic bullet - no indicator is. But it offers a genuinely different approach to moving averages that can capture trends more smoothly than traditional options. The mathematical foundation gives it a logical basis rather than just being another variation on exponential smoothing.

How to Backtest the FSWMA Indicator

Now let me show you how to properly backtest this indicator to understand its effectiveness in different market conditions. This is where smart traders separate themselves from the rest.

Setting Up Your FSWMA Strategy:

Basic Entry Rules:

  • Long entries: Enter when price crosses above the FSWMA line
  • Short entries: Enter when price crosses below the FSWMA line
  • Confirmation: Wait for the candle to close before entering

Exit Rules:

  • Stop loss: Place stops below recent swings or use ATR
  • Take profit: Target the next significant level or use risk/reward ratios
  • Time-based: Exit if no movement occurs within expected timeframe

Using Pineify for Strategy Development:

The platform makes it easy to create complete trading systems from your FSWMA rules. You can specify entry conditions, exit rules, position sizing, and test across extensive historical data.

Strategy Components to Test:

Order Optimization:

  • Test different orders on your chosen timeframe
  • Find the order that maximizes your risk-adjusted returns
  • Remember that higher orders mean more lag but fewer false signals

Timeframe Analysis:

  • Test the same order across multiple timeframes
  • Find which timeframe provides the best edge
  • Consider multi-timeframe confirmation

Market Condition Testing:

  • Test separately in trending vs. ranging markets
  • FSWMA will likely perform differently in each condition
  • Optimize for your primary market conditions

What to Track:

  • Win Rate: Target 40-60% depending on risk/reward
  • Average Win vs Loss: At least 1.5:1 risk/reward
  • Maximum Drawdown: Know your worst-case scenario
  • Trade Frequency: Ensure enough signals for statistical validity

The Reality Check:

No indicator works perfectly in all market conditions. The FSWMA is a valuable tool but should be combined with proper risk management and market context analysis. Backtesting helps you understand when the indicator works best and what parameters suit your trading style.

Final Thoughts

The Farey Sequence Weighted Moving Average is a refreshing departure from conventional moving average approaches. By applying mathematical elegance to price smoothing, it offers traders a unique tool for trend identification and analysis.

What makes FSWMA special:

  • Mathematical foundation provides logical basis for weighting
  • Order parameter offers flexible customization
  • Smooths noise while remaining responsive
  • Works across all markets and timeframes
  • Can be combined with any trading approach

Key takeaways:

Start with the default order 5 and experiment to find what works best for your timeframe and market. The beauty of the Farey sequence is its natural balance - it doesn't overweight recent prices like EMA does, nor does it treat all prices equally like SMA.

The real power comes from combining FSWMA signals with other technical analysis tools. Support and resistance, trend lines, and momentum indicators all work well alongside the FSWMA to confirm potential entry points.

Practical advice:

Don't just take my word for it - backtest the FSWMA against your current moving average and see if it improves your results. The mathematical approach might just give you an edge you've been looking for.

Ready to start building your own FSWMA strategies? Pineify makes it simple to customize, backtest, and deploy your trading ideas. The indicator is waiting - time to put it to work.