# TrendMagic

## Screenshot

<figure><img src="https://3544659995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frt4AAmaMasenYV2yGlc0%2Fuploads%2FiI3l9u2L3Mvm0RKR4RPL%2Fimage.png?alt=media&#x26;token=877ee6d4-47dc-4bfd-acab-91f270ed8f09" alt="" width="375"><figcaption></figcaption></figure>

<figure><img src="https://3544659995-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Frt4AAmaMasenYV2yGlc0%2Fuploads%2FnhGzRaJeq9o96b8o416h%2Fimage.png?alt=media&#x26;token=43d7ab5a-1519-491f-b601-8affc13fd6c8" alt="" width="375"><figcaption></figcaption></figure>

###

### **TradersAlly TrendMagic Algo - User Documentation**

#### 1. Strategy Overview

Welcome to the TradersAlly TrendMagic Algo! This strategy is a versatile tool designed for automated and discretionary trading within the NinjaTrader 8 platform. Its core logic is built around the popular **TrendMagic indicator**, a powerful tool for identifying trend direction and volatility.

The strategy operates on two primary types of signals:

1. **Crossover Signals:** The main automated entry signal is triggered when the TrendMagic indicator changes color, suggesting a potential shift in trend direction (e.g., from red/bearish to green/bullish).
2. **Pullback Signals:** The strategy can also be configured to identify and trade retracements, entering when the price pulls back to the TrendMagic line within an established trend and then shows signs of resuming that trend.

A key feature of this strategy is its ability to support a hybrid trading approach. While it can run fully automated, it is designed to integrate with the **TATM Control addon**. This allows a trader to "arm" the strategy, telling it to take the next valid signal that appears, providing a perfect blend of algorithmic signal generation and human discretion.

This document will guide you through every parameter available in the strategy's settings, explaining what each one does and how they interact to control the strategy's behavior.

***

#### 2. Strategy Parameters Explained

The settings are organized into logical groups, just as you see them in the NinjaTrader Strategy Settings window.

**Group 1: Strategy Parameters**

This group contains the most fundamental settings for trade management, risk, and position sizing.

* **Allow Long/Short Trades:** Simple on/off switches to enable or disable long or short entries.
* **Stop Loss Placement:** Determines how the initial stop loss is calculated.
  * CurrentBar: Places the stop relative to the high/low of the signal bar itself.
  * PreviousBar: Places the stop relative to the high/low of the bar before the signal bar.
  * PreviousBarMinus1: Uses the lowest low (for longs) or highest high (for shorts) of the last three bars.
  * TrendMagicLineStatic: Places the stop relative to the TrendMagic line's value at the moment of entry. It does not move unless a trailing stop is active.
  * TrendMagicLineTrailing: The stop loss will automatically follow the TrendMagic line as it moves in your favor.
  * Channel / ChannelTrailing: Places the stop relative to the outer channel line. Trailing will follow the channel line as it moves.
* **Stop Loss Extra Ticks:** A buffer added to your stop loss. For a long trade, the stop is placed this many ticks below the calculated price (e.g., below the low of the bar). This helps avoid being stopped out by minor noise.
* **Base/Runner Risk Reward Ratio:** Sets the profit target as a multiple of your initial risk (the distance from your entry to your stop loss). TwoToOne means your profit target is twice as far as your stop loss. This can be set independently for the base and runner positions.
* **Show Indicator On Chart:** Toggles the visibility of the TrendMagic indicator on your chart.
* **Max Risk Points:** A safety filter. If the calculated distance in points from your entry to your initial stop loss exceeds this value, the trade will be rejected. Set to 0 to disable.
* **Base/Runner Position Quantity:** The fixed number of contracts to trade for the base and runner positions. This is only used if Enable Dynamic Sizing is false.
* **Use Runner Position:** If checked, the strategy will open a second, independent position (the "runner") alongside the base position, allowing for different profit targets or trailing stop behaviors.
* **Enable Dynamic Sizing:** A powerful risk management feature. If true, the strategy ignores the fixed quantities and instead calculates the number of contracts to trade based on a fixed monetary risk.
* **Max Monetary Loss / Trade:** The maximum dollar amount you are willing to risk on a single trade. The strategy uses this value, along with the calculated stop loss distance, to determine the appropriate position size.
* **Max Contracts / Component:** The absolute maximum number of contracts that dynamic sizing is allowed to calculate for either the base or the runner.
* **Use Trail Base/Runner:** Enables or disables trailing stops for the base and runner positions.
* **Base/Runner Trailing Behavior:** Defines how the trailing stop behaves.
  * TrailAfterEntry: The stop loss begins trailing immediately after the trade is entered.
  * BreakevenAfterBaseTP: The runner's stop loss will only be moved to breakeven after the base position's profit target is hit.
  * BreakevenThenTrail: The runner's stop is first moved to breakeven (after the base TP is hit), and then it begins to trail price movements.
* **Enable Pullback/Crossover Trades:** Master switches to enable or disable the two main automated signal types.
* **Strategy Label:** A custom name you can give this specific instance of the strategy. This is useful for identification, especially in the addon.

**Group 2: Indicator Settings**

These parameters directly control the calculation and appearance of the core TrendMagic indicator.

* **CCI Period:** The lookback period for the Commodity Channel Index (CCI) used within the TrendMagic calculation.
* **ATR Period:** The lookback period for the Average True Range (ATR) calculation.
* **ATR Multiplier:** The value by which the ATR is multiplied. A larger multiplier creates a wider, less sensitive TrendMagic line that is further from the price.
* **Use CCI Trend Color:** If true, the indicator's color is based on the CCI being above or below zero, rather than the standard up/down trend logic.
* **Show Arrows / Arrow Offset:** Toggles the visibility of the trend change arrows on the indicator and sets their distance from the bar.
* **Show Channel Line / ATR Period / ATR Multiplier:** These settings control the optional outer channel line, which is based on a separate ATR calculation.

**Group 3: Entry Filters**

These are powerful confirmation tools that can be layered on top of the base signals to improve quality.

* **Enable Trend Filter:** Activates a simple EMA as an overall trend filter.
* **EMA Filter Condition:** Determines how the EMA filter is evaluated:
  * PriceVsEma: Requires the closing price to be on the correct side of the EMA.
  * TrendMagicVsEma: Requires the TrendMagic line itself to be on the correct side of the EMA.
* **Trend Filter Period:** The lookback period for the EMA.
* **Enable Secondary EMA Filter:** Activates a second, independent EMA filter, often used in combination with the first to gauge momentum.
* **Enable Consecutive Bar Filter:** A filter to avoid entering a trade after a market is already very extended. If, for a long signal, the previous X bars were all bullish, the trade is blocked.
* **Max Consecutive Bars:** The number of bars (X) to check for the filter above.
* **Enable Momentum Entry Filter:** Requires the signal bar to close strong, breaking the high of the prior two bars for a long, or the low of the prior two bars for a short.
* **Enable Channel Filter:** Requires the outer channel line to be below the main trend line for longs (indicating expansion) and above for shorts.
* **Enable Trade Mode Filter:** Activates a sophisticated filter based on the relationship between the TrendMagic and Channel lines on the Higher Timeframe (see HTF Settings). This helps identify if the market is in a strong trend, a volatile "scalp" mode, or a mixed/neutral state.

**Group 4: Time Filters**

These settings control when the strategy is allowed to operate.

* **Enable Time Filter:** Enables the primary trading session window.
* **Filter Start/End Time:** The time window during which the strategy is allowed to initiate new trades.
* **Enable Block Time Filter:** Enables a "no-trade" window, such as a lunch hour, where new trades will be blocked even if it's within the main session.
* **Block Start/End Time:** The start and end time for the no-trade window.
* **Exit on Session Close (Sec):** How many seconds before the official session end the strategy should flatten any open positions.

**Group 5: HTF (Higher Timeframe) Settings**

This powerful set of filters requires all trade signals to be in agreement with the trend on a higher timeframe chart.

* **Use HTF Filter:** The master switch to turn all HTF confirmations on or off.
* **Use Bounce Bars for HTF:** Allows you to use custom Bounce Bars as your HTF instead of standard time-based bars.
* **HTF Period Type / Value:** If not using Bounce Bars, this sets the timeframe for the HTF chart (e.g., Minute, 15).
* **HTF Bull/Bear Bar:** The primary HTF confirmation. If checked, a long trade requires the current HTF bar to be bullish (green), and a short trade requires it to be bearish (red).
* **Enable Opposite HTF Bar:** A sub-filter for the one above. If checked, it adds a requirement that the previous HTF bar must have been the opposite color (e.g., a long trade needs a green bar now that was preceded by a red bar).
* **Max Points Closure:** A sophisticated sub-filter that measures the distance from the current price to the body of the previous HTF bar. It prevents trades after the price has already moved too far. The exact measurement method changes intelligently based on whether "Enable Opposite HTF Bar" is active. Set to 0 to disable.
* **HTF Direction Agreement:** Requires the TrendMagic indicator on the HTF chart to be the same color (i.e., in the same direction) as the main chart's signal.

**Group 6: Logging Settings**

These are essential for debugging and understanding the strategy's behavior.

* **Print... Logs:** Check these boxes to print detailed information to the NinjaScript Output window. Print Trade Signal Logs is especially useful for seeing exactly why a trade was taken or, more importantly, rejected by a filter.

**Group 7: Daily P/L Management**

Provides simple but effective daily risk management.

* **Enable Daily Limit:** If checked, the strategy will stop opening new positions for the rest of the session after a daily profit or loss limit is hit.
* **Max Daily Profit/Loss:** The dollar amounts that trigger the daily limit.

**Group 8: Alert Settings**

* **Enable Email Alerts:** If true, the strategy will send an email when a new trade is executed.
* **Recipient Email Address:** The address to send the alert to.

***

#### 3. Discretionary Trading with the TATM Control Addon

While the strategy can run fully automated, its settings can also be controlled in real-time via the TATM Control addon. This is where the true hybrid power comes in. The addon allows you to:

* **Arm Manual TM Trade:** Tell the strategy you are ready and it should take the very next crossover signal that appears and passes all filters.
* **Arm Manual Pullback Trade:** Tell the strategy you want to enter on a pullback to the TrendMagic line.

This workflow allows you to analyze the market and decide when conditions are favorable, then let the algorithm handle the precise entry timing and trade management.
