This tool is designed to help traders visualize and react to the "momentum" of a financial asset—essentially measuring how quickly the price is moving in a specific direction over a set period of time.
How It Works
The logic is built around comparing current prices to historical prices. By looking back at a user-defined number of candles (the "Momentum Period"), the script calculates the difference between where the price is now and where it was several steps ago.
- Positive Momentum: If the current price is higher than the price from the previous period, the indicator shows a positive value. This suggests upward pressure.
- Negative Momentum: If the current price is lower than the price from the previous period, the indicator shows a negative value. This suggests downward pressure.
Visual Representation
The script creates a dedicated window on your trading platform featuring a continuous line. As the market moves, this line fluctuates above and below a center point (zero).
- When the line climbs above zero, it indicates that the asset's price is gaining ground compared to its past position.
- When the line drops below zero, it indicates that the asset's price is losing ground.
Automated Alerts
Beyond just providing a visual guide, the script includes an intelligent notification system. It monitors the "crossings" of the zero line in real-time.
Specifically, if the momentum shifts from negative to positive (crossing upward) or from positive to negative (crossing downward), the tool can trigger an immediate alert. This ensures that you are notified the moment the trend's strength switches direction, allowing for faster decision-making without having to constantly watch the screen manually.
//+--------------------------------------------------------------------+
//| MomentumVT.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//| Conversion from VT to MT4 by Skyline (glicci@yahoo.it) |
//+--------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern bool AlertsEnabled = false;
extern string AlertsSound = "alert.wav";
extern int MomPeriod = 10;
//---- buffers
double MomBuffer[];
void init()
{
//---- indicator line
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, MomBuffer);
//---- name for DataWindow and indicator subwindow label
string short_name="MomentumVT alert(" + MomPeriod + ")";
IndicatorShortName(short_name);
SetIndexLabel(0, short_name);
//----
SetIndexDrawBegin(0, MomPeriod);
}
//+------------------------------------------------------------------+
//| Momentum |
//+------------------------------------------------------------------+
void start()
{
static datetime AlertTime = 0;
int counted_bars = IndicatorCounted();
if (Bars <= MomPeriod)
return;
//---- initial zero
if (counted_bars < 1)
for (int i = 1; i <= MomPeriod; i++)
MomBuffer[Bars - i] = 0.0;
//----
i = Bars - MomPeriod - 1;
if (counted_bars >= MomPeriod)
i = Bars - counted_bars - 1;
while (i >= 0) {
MomBuffer[i] = Close[i] - Close[i + MomPeriod];
i--;
if (AlertsEnabled && i == 0 && AlertTime != Time[0]) {
if ((MomBuffer[0] > 0 && MomBuffer[1] <= 0) || (MomBuffer[0] < 0 && MomBuffer[1] >= 0)) {
AlertTime = Time[0];
Alert("MomentumVT Indicator! ", Symbol(), " M", Period());
if (StringLen(AlertsSound) > 0)
PlaySound(AlertsSound);
}
}
}
}
Comments