Aroon_Alert
Download scriptThis tool is designed to analyze market momentum by identifying how recently the highest and lowest prices have occurred within a specific timeframe. Instead of looking at simple price movements, it focuses on the "freshness" of price extremes to help traders understand the strength and direction of current trends.
How the Logic Works
1. Defining the Observation Window The script looks back over a set number of previous candles (the default is 20). By focusing on this specific window, it filters out old market noise and concentrates on what is happening right now.
2. Identifying Extremes For every candle on your chart, the script performs a scan to find two specific data points:
- The Highest Price: It identifies exactly where the highest closing price occurred within the observation window.
- The Lowest Price: It identifies exactly where the lowest closing price occurred within that same window.
3. Calculating Momentum Scores The script then converts these positions into a percentage score between 0 and 100:
- High Momentum Score: If the highest price happened very recently (close to the current candle), the score moves toward 100. This suggests strong upward pressure.
- Low Momentum Score: If the highest price happened a long time ago (near the start of the window), the score stays low, suggesting that upward momentum is weakening.
- The same logic applies to the lowest price to determine downward momentum strength.
4. Visual Representation and Thresholds The results are displayed in a separate window as two distinct lines. The chart includes pre-set levels at 30 and 70, which act as reference points for identifying significant shifts in market activity.
Automated Alerts
Beyond just providing visual data, the script includes an intelligent notification system. It monitors the momentum scores in real-time:
- Trigger Point: If either of the momentum scores reaches a specific high threshold (set by the user, defaulting to 95), the script triggers a pop-up alert on your platform.
- Smart Notifications: To prevent constant "spamming" of alerts, the logic includes a toggle. Once an alert is triggered, it resets after the condition is no longer met, ensuring you are only notified when a significant momentum peak actually occurs.
//+------------------------------------------------------------------+
//| Momentum.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 DodgerBlue
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 30
#property indicator_level2 70
//---- input parameters
extern int MomPeriod = 20;
extern int maxLevel = 95;
extern int alertSwitch = 1; // Alert 1 - ON, 0 - OFF
//---- buffers
double MomBuffer1[],MomBuffer2[];
int alertA = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MomBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,MomBuffer2);
//---- name for DataWindow and indicator subwindow label
short_name="Aroon("+MomPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,MomPeriod);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Momentum |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
//----
if(Bars<=MomPeriod) return(0); //bar kurang dari 14 keluar..
//---- initial zero
if(counted_bars<1) //..jika bar yang sudah terhitung lebih kecil dari 1 maka nol kan semua
//mulai dari no buffer yang paling besar ke yang paling kecil=0
for(i=1;i<=MomPeriod;i++) {
MomBuffer1[Bars-i]=0.0;
MomBuffer2[Bars-i]=0.0;
}
//----
i=Bars-MomPeriod-1;
if(counted_bars>=MomPeriod) i=Bars-counted_bars-1;//15-14-1=0
int nHigh,nLow;
while(i>=0)
{
double Max=-100000;
double Min=100000;
for(int k=i;k<i+MomPeriod;k++){
double Num=Close[k];
if(Num>Max){
Max=Num;
nHigh=k;
}
if(Num<Min){
Min=Num;
nLow=k;
}
}
//Aroon Indicator math..
MomBuffer1[i]=100.0*(MomPeriod-(nHigh-i))/MomPeriod;
MomBuffer2[i]=100.0*(MomPeriod-(nLow-i))/MomPeriod;
i--;
}
if ((MomBuffer1[0] >= maxLevel || MomBuffer2[0] >= maxLevel) && alertA == 0 && alertSwitch == 1) {
alertA = 1;
Alert("Aroon value are: ", MomBuffer1[0]," - ", MomBuffer2[0]," !!");
}
else if (alertA == 1 && alertSwitch == 1)
alertA =0;
return(0);
}
//+------------------------------------------------------------------+
Comments