MACD controlled risk strategy example
Jan 28, 2021

The MACD controlled risk strategy example tool demonstrates how to build a trading strategy focused on fixed risk per trade and dynamic position sizing rather than simple equity flipping. It utilizes the Moving Average Convergence Divergence (MACD) for signal generation while strictly managing exposure through stop-loss-based calculations.
Usage
The strategy is used to illustrate how to size positions based on a specific percentage of account equity. When a long signal is generated—defined by a MACD crossover occurring below the zero line while price is above a Weighted Moving Average (WMA)—the script identifies a recent low as a stop loss. It then calculates the distance to that stop and determines the exact position size required to ensure that a stop-out only loses the user-defined percentage of total equity. Examples of use include backtesting risk management techniques or filtering trend-following entries using a WMA bias.
Details
The strategy calculates risk dynamically for every trade. Unlike fixed-lot or fixed-percentage-of-equity sizing, this method uses the distance between the entry price and the stopPrice (the "range") to derive the contract quantity. The formula positionSizeInUsd = (equity * risk) / (range / price) ensures that the monetary loss is constant regardless of volatility. Additionally, the script includes a feature to close all positions if the strategy's equity curve falls below its own Exponential Moving Average (EMA), acting as a "circuit breaker" for the strategy during periods of significant drawdown.
Settings
- % capital risk per trade: The percentage of current strategy equity to risk if the stop loss is hit.
- Take Profit in 'R': The reward-to-risk ratio used to set the limit order (e.g., a setting of 4.0 aims for 4x the amount risked).
- WMA Bias Length: The period for the Weighted Moving Average used to determine the overall trend direction.
- Use EQ Curve average crossunder to close: When enabled, the strategy will exit open trades if the equity curve crosses below its moving average.
- Equity Curve average length: The period used to calculate the EMA of the strategy's equity curve.
FAQ
How do I use this strategy for my own trading?
You can use the logic within this script as a template for building more robust systems that prioritize risk management over raw entry signals.
What is 'R' in the take profit setting?
'R' represents the initial risk. If you risk $100 on a trade, a 4R take profit would result in a $400 gain.
How can I access the MACD controlled risk strategy example?
You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.
Free indicator
Get free access to this indicator on the platforms below.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.