ANN Strategy v2
Nov 8, 2015

The ANN Strategy v2 indicator utilizes a multi-layer Artificial Neural Network (ANN) to predict price movements based on percentage differences across multiple timeframes. This tool processes historical price data through an input layer, two hidden layers, and an output layer to generate non-repainting long and short signals for trend-following strategies.
Usage
The Usage section describes how the script can be used, examples should be provided in this section. This tool is primarily designed to identify trend shifts by analyzing the relationship between a high-timeframe anchor and the current chart timeframe.
- Signal Interpretation: When the ANN output exceeds the positive threshold, the script generates a "Long" signal and highlights the background green. When the output falls below the negative threshold, a "Short" signal is triggered with a red background.
- Timeframe Correlation: Users should set the "Timeframe" setting to a higher period (e.g., 1 Day) while viewing a lower timeframe chart (e.g., 4 Hour). The script calculates the percentage difference between the current price and the previous anchor period's OHLC/4 value to feed the neural network.
- Threshold Adjustment: The threshold setting acts as a filter; increasing it can reduce market noise by requiring a stronger neural network prediction before a signal is triggered.
Details
The script implements a feed-forward neural network architecture directly within Pine Script. The process begins by fetching the ohlc4 (average of Open, High, Low, and Close) from a user-defined higher timeframe using request.security.
The core logic involves:
- Input Layer: Calculates the percentage change between the current price and the previous anchor period.
- Hidden Layers: The input is processed through 5 neurons in the first hidden layer and 33 neurons in the second hidden layer. These layers use a Hyperbolic Tangent (Tanh) activation function to handle non-linear relationships.
- Output Layer: Aggregates the weighted values from the hidden layers into a single prediction value (
l3_0). - Stability: Unlike the previous version, this iteration uses historical data from the anchor timeframe to prevent repainting, ensuring that signals remain fixed once the bar closes.
Settings
- Threshold: Determines the sensitivity of the signals. A value of 0.0000 triggers signals on any polarity flip, while higher values require more significant model confidence.
- Timeframe: Defines the higher timeframe used as the reference point for calculating price deltas.
FAQ
How do I adjust the sensitivity of the ANN Strategy v2? You can adjust the "Threshold" setting in the script inputs. A higher threshold will result in fewer, more selective signals, whereas a lower threshold will increase signal frequency.
Why is the background color changing? The background color reflects the current bias of the neural network. Green indicates a bullish prediction based on the model's weighted calculations, while red indicates a bearish prediction.
How can I access the ANN Strategy v2? 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.