Skip to main content

Moving Average in the Trade Rule Block

Guide to using Moving Average in Trade Rule block—periods, methods, prices, candle IDs & tips for trend filtering and backtesting.

Updated over 4 months ago

Purpose

The Moving Average (MA) is one of the most commonly used technical indicators in trading. In the Trade Rule block, it allows you to benchmark the current market condition against a smoothed price value over a set period, helping to identify trends or potential reversals.


How It Works

When you select Moving Average as a value type in the Trade Rule block, you can fine-tune its calculation with multiple options:

Moving Average Period

  • Defines the number of candles used in the calculation.

  • Example: A period of 10 calculates the MA based on the last 10 candles.

Moving Average Shift (Advanced Option)

  • Moves the MA forward or backward along the chart by a set number of candles.

  • Often unused, but can be helpful for backtesting or specific pattern recognition

Moving Average Method (Calculation Style)

  • Simple (SMA): Arithmetic average of the selected price over the period.

  • Exponential (EMA): Weights recent prices more heavily for faster reaction to price changes.

  • Smoothed: Similar to SMA but uses a longer smoothing period, reducing noise further.

  • Weighted (WMA): Assigns a linear weight to each price, giving more importance to recent data.

Moving Average Applied Price (What the MA is calculated from)

  • Close Price: Uses the closing price of each candle.

  • Open Price: Uses the opening price of each candle.

  • High Price: Uses the highest price of each candle.

  • Low Price: Uses the lowest price of each candle.

  • Median Price: (High + Low) ÷ 2

  • Typical Price: (High + Low + Close) ÷ 3

  • Weighted Price: (High + Low + Open + Close) ÷ 4

Moving Average Time Frame

  • Set the chart time frame for the MA calculation.

  • Can be tied to a variable or input for faster optimization and backtesting.

Moving Average Candle ID

  • Determines which candle to start from.

  • 0: Current candle (still forming).

  • 1: Most recently closed candle.

  • Higher IDs refer to older candles further back in time.

Moving Average Adjust (Modify the Result)

  • Apply an adjustment to the calculated MA value by adding, subtracting, multiplying, or dividing by a number.


Example

If you set:

  • Period: 10

  • Method: Exponential

  • Applied Price: Close

  • Candle ID: 0
    The block will calculate the 10-period EMA of the closing price, starting from the current candle.


Use Cases

  • Identify bullish trends when price is above the MA.

  • Create crossover strategies (e.g., short-term MA crossing above long-term MA).

  • Use MA as a filter for trade entries, only taking trades in the direction of the trend.


Tip: MA settings can have a big impact on performance. Use variables and inputs to quickly backtest different periods and methods without manually editing your blocks.

Did this answer your question?