Welcome, traders! Today’s episode will be focusing on volatility calculations and risk management. We’ll build a basic algorithm that incorporates these concepts for a more informed trading approach.
Step 1: Volatility Calculation with ATR
To determine position size and stop-loss levels, we’ll leverage the Average True Range (ATR) indicator. The ATR measures market volatility by capturing the price range over a specific period.
Building the ATR Risk Calculator
- Dollar Risk: This variable defines the maximum amount you’re willing to risk per trade. We’ll multiply this by your account equity and a chosen percentage risk (e.g., 1%).
- ATR Distance: This considers the ATR period and a stop-loss multiplier (default 1.5). This helps calculate the distance your stop-loss will be placed from the entry price based on volatility.
- Points Multiplier and Lot Multiple: These adjust position sizing depending on the instrument being traded (e.g., stocks vs. forex). We’ll create a separate function for this later.
- Lot Size: This is calculated by dividing your dollar risk by the ATR distance and the lot multiple. Essentially, a higher volatility (larger ATR) will result in a smaller position size to manage risk.
Step 2: Contextualizing Points and Lot Multiple
The points multiplier and lot multiple allow you to customize position sizing based on the instrument type. Here’s a breakdown:
- Commodities and Indices: No multipliers needed (points = 1, lot = 1).
- 5-Digit Forex (e.g., USD/JPY): Points multiplier of 10,000 and lot multiple of 10.
- 3-Digit Forex (e.g., EUR/USD): Points multiplier of 100 and lot multiple of 10.
This flexibility ensures proper position sizing for different instruments with varying pip values.
Step 3: Building a Simple Algorithm with Volatility Stops
Now, let’s create a basic algorithm that utilizes the ATR for both position sizing and stop-loss placement. We’ll use a simple moving average crossover strategy for entry signals.
- Moving Average Crossover: We’ll use a 20-period moving average crossing above a 50-period moving average to identify potential buy opportunities.
- Volatility-Based Stop-Loss: Instead of a fixed stop-loss, we’ll use the ATR distance calculated earlier. This stop-loss will be placed below the entry price (for long trades) based on market volatility.
- Volatility-Based Take Profit (Optional): We can also incorporate a take-profit level based on a multiple of the ATR (e.g., 2x ATR).
Step 4: Backtesting and Refinement
Once the algorithm is built, backtest it on historical data to assess its performance. Analyze the results and fine-tune variables like the moving average periods, stop-loss multiplier, and take-profit multiplier to optimize the strategy for your specific risk tolerance and trading goals.
To see live trading reviews, check out the Traders Results Page.
If you would like to learn more about creating automated trading strategies check out the Trading Talk series which has a new episode each week with different topics and concepts on popular automated trading strategies.
Why wait? Get started today. Sign up for an account today with the Tradeview Forex broker www.tradeview.tech and start creating your own automation.