).
The basis of this indicator is the Volatility method described in Wilders book from 1975 "New Concepts in Technical Trading Systems".
I have used this on Crypto and Stocks and Forex. The ACC (Acceleration Factor) is setup to run on Crypto (BTC,ETH) M1, but it also works on all other timeframes. It works well on Forex as well as Stocks. Ideally you want to trade when the volatility is higher as to avoid side ways trading. So you want to look at other indicators to provide you a good idea of when it is worthwhile to trade.
My main motivation for improving the existing indicator by Wilders was that while it serves as a good entry point to trades its exit of the trades is usually way too relaxed and needs to be more precise and aggressive. This is why I have included an adaptive Stop-Loss that tightens aggressively once the Risk-Reward ratio breaches 1.0 up to a user set max RR. This is what we want to be doing if we are trading manually once your RR has exceeded 1:1. While the original Wilder algorithm leaves the ACC factor constant we are instead reducing the ACC factor using a smooth function to start increasingly tighten the StopLoss towards our set max RR.
# Wilders Volatility Trend Following Optimised Indicator Documentation
## Introduction
The Wilders Volatility Trend Following Optimised indicator is a sophisticated trend-following technical analysis tool for MetaTrader 5. It implements an advanced adaptive trend-following system that dynamically adjusts to market conditions, providing traders with clear entry and exit signals while automatically calculating optimal take profit and stop loss levels.
This indicator is designed for traders who follow trend-based strategies and seek to optimize their trade management with adaptive risk parameters that respond to changing market volatility.
## Key Features
- **Adaptive Trend Following**: Automatically identifies and follows market trends
- **Dynamic Position Management**: Calculates optimal entry, exit, stop loss, and take profit levels
- **Volatility-Based Parameters**: Uses Average True Range (ATR) to adapt to market volatility
- **Adaptive Acceleration Factor (AFX)**: Implements a sigmoid-based transition between acceleration factors
- **Smooth Take Profit Calculation**: Uses hyperbolic tangent function for natural profit target transitions
- **Trailing Stop Loss**: Implements an intelligent trailing stop mechanism that locks in profits
- **Visual Feedback**: Provides comprehensive visual elements including arrows, lines, and text annotations
- **Global Variable Export**: Makes key values available to other indicators and EAs
## Technical Approach
### Trend Following Methodology
The indicator follows a trend-based approach using a Stop-And-Reverse (SAR) mechanism. It maintains a current position (long or short) and tracks a Significant Close (SIC) value, which represents the most extreme favorable price since entering the current position.
The SAR level is calculated as:
```
SAR = SIC - FLIP * ACC * ATR
```
Where:
- `SIC` is the Significant Close value
- `FLIP` is the position direction (1 for long, -1 for short)
- `ACC` is the Acceleration Factor
- `ATR` is the Average True Range
When price crosses the SAR level in the opposite direction of the current position, the indicator generates a signal to reverse the position.
### Adaptive Acceleration Factor (AFX)
One of the most innovative aspects of this indicator is the Adaptive Acceleration Factor (AFX) calculation. This uses a sigmoid function to create a smooth transition between different acceleration factor values based on price movement:
```
AF_X = af_start + (af_end - af_start) * sigmoid_x
```
The sigmoid function creates an S-shaped curve that makes transitions smooth rather than abrupt. This adaptive approach allows the indicator to:
1. Start with wider stops to give trades room to breathe
2. Gradually tighten as the trade moves favorably
3. Lock in profits with a trailing mechanism once certain thresholds are crossed
4. Adapt to market volatility through ATR
### Dynamic Take Profit Calculation
The indicator implements a sophisticated take profit calculation using a hyperbolic tangent function:
```
profitMultiplier = 1.0 + profitRange * transitionFactor
```
Where `transitionFactor` is calculated using a custom hyperbolic tangent implementation. This creates a dynamic take profit that:
- Starts at a minimum level (SIC_SNAP ± ATR * ACC * PROFIT_MIN)
- Gradually increases toward a maximum level (SIC_SNAP ± ATR * ACC * PROFIT_MAX)
- Uses a smooth transition based on how far price has moved from the base level
- Adapts to market volatility through the ATR value
## Key Components
### Significant Close (SIC)
The Significant Close (SIC) is a key concept in this indicator. It represents the most favorable price level since entering the current position:
- For long positions: SIC is the highest close price since entering the position
- For short positions: SIC is the lowest close price since entering the position
The SIC serves as a reference point for calculating the SAR level and other important values.
### Average True Range (ATR)
The indicator uses ATR to measure market volatility and scale various calculations accordingly. The ATR is calculated using a smoothed approach:
```
ATR = Alpha * TR + (1 - Alpha) * previous_ATR
```
Where:
- `TR` (True Range) is the maximum of: current high-low range, current high-previous close, or current low-previous close
- `Alpha` is the smoothing factor (default 1/7)
### Position Tracking and Signal Generation
The indicator tracks the current market position (long, short, or none) and generates signals based on four conditions:
1. If long position and current price is less than or equal to StopLoss, switch to short
2. If short position and current price is greater than or equal to StopLoss, switch to long
3. If long position and current price is less than or equal to SAR, switch to short
4. If short position and current price is greater than or equal to SAR, switch to long
When a position change occurs, the indicator:
- Updates the SIC and ATR_SNAP values
- Resets bound breach flags
- Draws arrows and vertical lines on the chart
- Updates all visual elements
### Bound Breaching Mechanism
The indicator implements an upper and lower bound system:
```
upperBound = SIC_SNAP + ATR_SNAP * ACC
lowerBound = SIC_SNAP - ATR_SNAP * ACC
```
When price breaches these bounds in a favorable direction, the indicator activates a trailing stop mechanism that only moves in the favorable direction, locking in profits.
## Visual Elements
The indicator creates several visual elements on the chart:
### Arrows and Lines
- **Long/Short Arrows**: Green (long) or red (short) arrows indicating position changes
- **SAR Line**: A horizontal line showing the current SAR level
- **SIC Line**: A horizontal line showing the current Significant Close level
- **Upper/Lower Bound Lines**: Horizontal lines showing the upper and lower bounds
- **Take Profit Line**: A magenta dashed line showing the calculated take profit level
- **Stop Loss Line**: An orange dashed line showing the calculated stop loss level
- **Vertical Lines**: Dotted vertical lines marking position change points
### Text Annotations
The indicator adds text annotations to the chart explaining various values:
- SAR level and calculation details
- SIC value and related parameters
- Upper and lower bound values
- Take profit and stop loss levels with calculation details
## Input Parameters
| Parameter | Default | Description |
|-----------|---------|-------------|
| Timeframe | PERIOD_M1 | Time frame to run the indicator on |
| UseATRSnap | true | Use ATR Snapshot (true) or Live ATR (false) for calculations |
| UseGlobalATRTR | false | Use global TF1_ATRTR_TR and TF1_ATRTR_ATR variables |
| SARLineColor | clrWhite | Color of the SAR line |
| SICLineColor | clrYellow | Color of the SIC line |
| ACC | 10.0 | Base Acceleration Factor |
| Alpha | 1.0/7.0 | ATR smoothing factor |
| ArrowSize | 3 | Size of arrow symbols |
| LongColor | clrLime | Color for long signals |
| ShortColor | clrRed | Color for short signals |
| LongArrowCode | 233 | Long arrow symbol code |
| ShortArrowCode | 234 | Short arrow symbol code |
| AF_MIN | 1.0 | Minimum acceleration factor for AFX calculation |
| AF_MAX | 15.0 | Maximum acceleration factor for AFX calculation |
| K_Smooth | 3.0 | Smoothing parameter for AFX calculation |
| StopLossColor | clrOrange | StopLoss line color |
## Global Variables
The indicator exports several global variables that can be used by other indicators or EAs:
| Global Variable | Description |
|-----------------|-------------|
| TF_TF_O_[ChartID]_currentPrice | Current price |
| TF_TF_O_[ChartID]_TR | True Range value |
| TF_TF_O_[ChartID]_ATR | Average True Range value |
| TF_TF_O_[ChartID]_SIC | Significant Close value |
| TF_TF_O_[ChartID]_SIC_SNAP | SIC value at position change |
| TF_TF_O_[ChartID]_ATR_SNAP | ATR value at position change |
| TF_TF_O_[ChartID]_ACC | Acceleration Factor |
| TF_TF_O_[ChartID]_afx | Adaptive Acceleration Factor |
| TF_TF_O_[ChartID]_FLIP | Position direction (1 or -1) |
| TF_TF_O_[ChartID]_CurrentPosition | Current position (1 for long, -1 for short) |
| TF_TF_O_[ChartID]_K | Smoothing parameter |
| TF_TF_O_[ChartID]_SAR | Stop and Reverse level |
| TF_TF_O_[ChartID]_upperBound | Upper bound value |
| TF_TF_O_[ChartID]_upperBoundBreached | Flag indicating if upper bound is breached |
| TF_TF_O_[ChartID]_lowerBound | Lower bound value |
| TF_TF_O_[ChartID]_lowerBoundBreached | Flag indicating if lower bound is breached |
| TF_TF_O_[ChartID]_TakeProfit | Take profit level |
| TF_TF_O_[ChartID]_StopLoss | Stop loss level |
## Trading Signals Interpretation
### Entry Signals
- **Long Entry**: When price crosses above the SAR level while in a short position, or when price crosses above the stop loss level while in a short position
- **Short Entry**: When price crosses below the SAR level while in a long position, or when price crosses below the stop loss level while in a long position
### Exit Signals
- **Long Exit**: When price crosses below the SAR level or the stop loss level
- **Short Exit**: When price crosses above the SAR level or the stop loss level
### Risk Management
The indicator provides dynamic stop loss and take profit levels that adapt to market conditions:
- **Stop Loss**: Initially set at a distance of ATR * ACC from the SIC, but adapts using the AFX calculation as the trade progresses
- **Take Profit**: Calculated using a smooth transition function that starts at a minimum level and increases as the trade moves favorably
## Advanced Concepts
### Sigmoid-Based Transitions
The AFX calculation uses a sigmoid function to create smooth transitions between acceleration factor values:
```
sigmoid_x = ((1 / (1 + MathExp(-k * (2*normalized_x - 1)))) - (1 / (1 + MathExp(k)))) / t
```
This creates an S-shaped curve that avoids abrupt changes in stop loss levels, providing more natural and effective trade management.
### Hyperbolic Tangent Smoothing
The take profit calculation uses a custom hyperbolic tangent implementation:
```
CustomTanh(x) = (exp2x - 1.0) / (exp2x + 1.0)
```
This creates a smooth transition for take profit levels, making them more natural and effective.
### Trailing Stop Loss Implementation
The indicator implements an intelligent trailing stop mechanism that:
1. Tracks whether upper or lower bounds have been breached
2. Once a bound is breached, only allows the stop loss to move in the favorable direction
3. Uses the adaptive acceleration factor (AFX) to determine the stop loss distance
## Practical Usage
### Trend Following Strategy
1. Wait for the indicator to generate a long or short signal (arrows)
2. Enter a position in the direction of the signal
3. Set stop loss at the indicator's stop loss level (orange line)
4. Set take profit at the indicator's take profit level (magenta line)
5. Monitor the position as the indicator updates stop loss and take profit levels
6. Exit when the indicator generates a reversal signal
### Integration with Other Tools
The indicator can be used alongside other technical analysis tools:
- **Support/Resistance Levels**: Confirm signals with key support and resistance levels
- **Volume Indicators**: Validate signals with volume confirmation
- **Oscillators**: Use oscillators like RSI or Stochastic to confirm overbought/oversold conditions
## Conclusion
The Wilders Volatility Trend Following Optimised indicator provides a comprehensive trend-following system with advanced adaptive features. By dynamically adjusting to market conditions and providing clear visual feedback, it helps traders identify and manage trend-based trades with optimized risk parameters.
The indicator's sophisticated algorithms for calculating adaptive acceleration factors, smooth take profit levels, and intelligent trailing stops make it a powerful tool for trend followers seeking to optimize their trading approach.
---