MA_directionALERT3
Download scriptThis tool is designed to monitor price trends on a trading chart by tracking the behavior of a Moving Average (MA). Its primary purpose is to identify specific moments when the trend changes direction—specifically, when the average price begins to "bend" or pivot.
How it Works
The script continuously calculates a Moving Average based on settings you choose (such as the length of the period and the calculation method). It looks specifically at the most recent three data points of this moving average to determine its current trajectory.
Instead of just showing you where the average is, the logic focuses on the relationship between these consecutive points:
- Trend Reversal Detection: The tool monitors for a "V" or "Inverted V" shape in the moving average. It looks for instances where the previous point was lower than the one before it, but the current point has moved higher (indicating an upward turn). Conversely, it looks for points where the average was previously rising but has just tucked downward (indicating a downward turn).
- Smart Alerting: When the script detects one of these specific structural turns in the moving average, it triggers an instant alert notification. This allows you to see potential shifts in momentum in real-time without having to manually watch every candle.
Key Features for the User
- Frequency Control: To prevent your workspace from being overwhelmed with notifications, the logic includes a built-in timer. It ensures that you only receive one alert per candle, meaning it won't spam you with repeated messages during the same time period.
- Customizable Inputs: You can adjust the sensitivity of the tool by changing the Moving Average period and method. A shorter period will make the tool more responsive to small price wobbles, while a longer period will focus on broader, more significant trend shifts.
- Visual Feedback: In addition to providing alerts, the script draws the moving average directly onto your chart in gold, providing a clear visual reference of the current price flow.
In short, this tool acts as a "trend sentinel." It watches the curvature of the moving average and notifies you the moment the trend shows signs of turning, helping you stay ahead of momentum shifts.
//+------------------------------------------------------------------+
//| MA_ALERT.mq4 |
//| Kalenzo |
//| simone@konto.pl |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link "simone@konto.pl"
extern int maPeriod = 3;
extern int maMethod = 0;
extern int appiledPrice = 0;
extern int maShift = 0;
extern bool makeItPlay = true;
int PrevAlertTime = 0;
#property indicator_chart_window
#property indicator_color1 Gold
#property indicator_buffers 1
double maBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,0,1);
SetIndexBuffer(0,maBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) counted_bars=0;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
for(int i = 0 ;i < limit ;i++)
{
maBuffer[i]=iMA(Symbol(),0,maPeriod,maShift,maMethod,appiledPrice,i);
}
double ppMA = NormalizeDouble(iMA(Symbol(),0,maPeriod,maShift,maMethod,appiledPrice,3),4);
double pMA = NormalizeDouble(iMA(Symbol(),0,maPeriod,maShift,maMethod,appiledPrice,2),4);
double cMA = NormalizeDouble(iMA(Symbol(),0,maPeriod,maShift,maMethod,appiledPrice,1),4);
if (CurTime() - PrevAlertTime > Period()*60)
{
if(ppMA < pMA && pMA > cMA)
{
Alert( "MA "+maPeriod+","+maMethod+" decerasing on " + Symbol() + " M" + Period() );
PrevAlertTime = CurTime();
}
else if(ppMA > pMA && pMA < cMA)
{
Alert( "MA "+maPeriod+","+maMethod+" incerasing on " + Symbol() + " M" + Period() );
PrevAlertTime = CurTime();
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments