The Bizzwill ADX Cross Arrow (Non-Repaint) is a trading indicator designed to highlight potential trend changes by tracking the crossovers between the plus DI and minus DI lines of the ADX. This indicator visually displays arrows on the chart to mark these crossover points, providing traders with insights into possible shifts in market direction. The non-repaint feature ensures that the signals remain consistent and reliable as new data is added, allowing for a clear and stable view of trend changes over time.
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 2
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrLightSeaGreen
#property indicator_width1 2
#property indicator_label1 "Bull ADX Cross"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrRed
#property indicator_width2 2
#property indicator_label2 "Bear ADX Cross"
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
input int AdxPeriod = 14; // ADX period
input bool alertsOn = true; // Turn alerts on?
input bool alertsOnCurrent = false; // Alert on current bar?
input bool alertsMessage = true; // Display messages on alerts?
input bool alertsSound = false; // Play sound on alerts?
input bool alertsEmail = false; // Send email on alerts?
input bool alertsNotify = false; // Send push notification on alerts?
// Indicator buffers
double crossUp[], crossDn[], cross[];
// Indicator handles
int _adxHandle;
int _atrHandle;
//+------------------------------------------------------------------+
//| Initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- Indicator buffers mapping
SetIndexBuffer(0, crossUp, INDICATOR_DATA);
PlotIndexSetInteger(0, PLOT_ARROW, 233);
SetIndexBuffer(1, crossDn, INDICATOR_DATA);
PlotIndexSetInteger(1, PLOT_ARROW, 234);
SetIndexBuffer(2, cross);
//--- Create ADX and ATR handles
_adxHandle = iADX(_Symbol, 0, AdxPeriod);
if (_adxHandle == INVALID_HANDLE)
{
return (INIT_FAILED);
}
_atrHandle = iATR(_Symbol, 0, 15);
if (_atrHandle == INVALID_HANDLE)
{
return (INIT_FAILED);
}
//--- Set indicator short name
IndicatorSetString(INDICATOR_SHORTNAME, "ADX cross " + (string)AdxPeriod + ")");
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Cleanup code can be added here if needed
}
//+------------------------------------------------------------------+
//| Calculate function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[],
const double &open[], const double &high[], const double &low[], const double &close[],
const long &tick_volume[], const long &volume[], const int &spread[])
{
// Check for enough bars
if (Bars(_Symbol, _Period) < rates_total) return (prev_calculated);
if (BarsCalculated(_adxHandle) < rates_total) return (prev_calculated);
// Arrays to hold indicator values
double _adxVal[1], _adxpVal[1], _adxmVal[1], _atr[1];
// Iterate through bars
int i = (int)MathMax(prev_calculated - 1, 1);
for (; i < rates_total && !_StopFlag; i++)
{
// Copy indicator buffers
int _adxCopied = CopyBuffer(_adxHandle, 0, time[i], 1, _adxVal);
int _adxpCopied = CopyBuffer(_adxHandle, 1, time[i], 1, _adxpVal);
int _adxmCopied = CopyBuffer(_adxHandle, 2, time[i], 1, _adxmVal);
int _atrCopied = CopyBuffer(_atrHandle, 0, time[i], 1, _atr);
// Determine cross values
cross[i] = (i > 0) ? (_adxpVal[0] > _adxmVal[0]) ? 1 : (_adxpVal[0] < _adxmVal[0]) ? 2 : cross[i - 1] : 0;
crossUp[i] = EMPTY_VALUE;
crossDn[i] = EMPTY_VALUE;
// Set arrow values based on cross
if (i > 0 && cross[i] != cross[i - 1])
{
if (cross[i] == 1) crossUp[i] = low[i] - _atr[0];
if (cross[i] == 2) crossDn[i] = high[i] + _atr[0];
}
}
// Manage alerts
manageAlerts(time, cross, rates_total);
return (rates_total);
}
//+------------------------------------------------------------------+
//| Manage alerts function |
//+------------------------------------------------------------------+
void manageAlerts(const datetime & _time[], double & _trend[], int bars)
{
if (alertsOn)
{
int whichBar = bars - 1;
if (!alertsOnCurrent) whichBar = bars - 2;
datetime time1 = _time[whichBar];
// Trigger alerts based on trend changes
if (_trend[whichBar] != _trend[whichBar - 1])
{
if (_trend[whichBar] == 1) doAlert(time1, " plus DI crossing minus DI up");
if (_trend[whichBar] == 2) doAlert(time1, " plus DI crossing minus DI down");
}
}
}
//+------------------------------------------------------------------+
//| Send alert function |
//+------------------------------------------------------------------+
void doAlert(datetime forTime, string doWhat)
{
static string previousAlert = "nothing";
static datetime previousTime;
if (previousAlert != doWhat || previousTime != forTime)
{
previousAlert = doWhat;
previousTime = forTime;
// Construct alert message
string message = TimeToString(TimeLocal(), TIME_SECONDS) + " " + _Symbol + " Adx " + doWhat;
// Send alerts based on user settings
if (alertsMessage) Alert(message);
if (alertsEmail) SendMail(_Symbol + " Adx", message);
if (alertsNotify) SendNotification(message);
if (alertsSound) PlaySound("alert2.wav");
}
}
What is the ADX Cross Indicator?
The ADX Cross Indicator is designed to visualize crossovers between the plus DI (Directional Indicator) and minus DI (Directional Indicator) lines of the ADX. These lines represent the strength of upward and downward trends, respectively. When the plus DI crosses above the minus DI, it might indicate a bullish trend, and when it crosses below, it might suggest a bearish trend.
How Does the Indicator Work?
The indicator relies on the ADX and ATR (Average True Range) to generate visual signals on the chart. These signals help traders identify moments when the market’s direction might change. Here’s a closer look at the different parts of the indicator and how they function:
Initialization
When the indicator is first set up, it initializes several parameters and buffers:
- Buffers: These are memory areas used to store the indicator’s output values.
- Handles: These are references to the ADX and ATR calculations that will be used to determine the indicator’s output.
Calculating the Indicator
The core function of the indicator is to calculate values based on the ADX and ATR data. Here’s a breakdown of the calculation process:
- Copy Data: The indicator fetches current values for the ADX and ATR using their respective handles. This includes:
- ADX Value: Measures the strength of the trend.
- Plus DI and Minus DI Values: Indicate the direction of the trend.
- ATR Value: Used to adjust the placement of the arrows on the chart.
- Determine Crossovers: The indicator checks for crossovers between the plus DI and minus DI lines. A crossover occurs when one line moves above or below the other, signaling a potential change in the trend.
- Set Arrows: Based on the crossover information, arrows are plotted on the chart:
- Bullish Arrows: Placed below the price when the plus DI crosses above the minus DI.
- Bearish Arrows: Placed above the price when the plus DI crosses below the minus DI.
Managing Alerts
The indicator includes a feature to notify traders about significant events:
- Alerts: These can be customized to include messages, sounds, emails, or push notifications.
- Conditions for Alerts: Alerts are triggered when there is a change in the trend direction as indicated by the crossover of the plus DI and minus DI lines.
Customizing the Indicator
Users have options to adjust the indicator’s behavior through various input parameters:
- ADX Period: Defines the number of bars used to calculate the ADX.
- Alerts Settings: Allow users to enable or disable notifications and customize how they are received.
Final Thought
The ADX Cross Indicator is a valuable tool for traders looking to spot changes in market trends based on ADX line crossovers. By visualizing these crossovers and providing customizable alerts, the indicator helps traders stay informed about potential buying or selling opportunities.
In the code behind this indicator, careful attention is given to ensure accurate calculations and timely alerts. This allows traders to make decisions based on clear signals rather than relying on subjective interpretations of market data.
By understanding how the ADX Cross Indicator works and how to interpret its signals, traders can enhance their trading strategies and make more informed decisions.