Momentum_v3
Download scriptThis tool is designed to help traders visualize the "speed" and strength of price movements over a specific period. By analyzing how quickly an asset's price is changing, it provides a clearer picture of market trends than looking at raw price action alone.
Core Functionality
The script operates by comparing the current closing price of a financial instrument to its closing price from a fixed number of bars (periods) in the past. Instead of just showing you the price difference, it calculates a percentage-based value.
For example, if you set the indicator to look back over 14 periods, the tool takes today’s closing price, multiplies it by 100, and divides it by the closing price from 14 periods ago.
How to Interpret the Results
- Positive Momentum: When the resulting line on your chart is above zero and rising, it indicates that the price is currently higher than it was at the start of the selected period, suggesting a bullish trend.
- Negative Momentum: When the line falls below zero, it signifies that the current price is lower than the price from the previous period, indicating a bearish trend.
- Trend Strength: The steeper the slope of the line, the faster the price is moving in that direction. A flattening line suggests that the momentum is slowing down, even if the price is still moving up or down.
Key Features
- Customizable Lookback: You can adjust the "Momentum Period" to change how much historical data the tool considers. A shorter period makes the indicator more sensitive to recent price changes, while a longer period smooths out the data to show broader trends.
- Visual Clarity: The script generates a dedicated line in a separate window on your trading platform, allowing you to monitor momentum independently of the main price chart.
- Real-time Updates: The logic automatically recalculates with every new price tick, ensuring that you see the most current momentum data as the market moves.
//+------------------------------------------------------------------+
//| Momentum.mq4 |
//| Copyright 2005-2014, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2005-2014, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property description "Momentum"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//--- input parameter
input int InpMomPeriod=14; // Momentum Period
//--- buffers
double ExtMomBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
string short_name;
//--- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ExtMomBuffer);
//--- name for DataWindow and indicator subwindow label
short_name="Mom("+IntegerToString(InpMomPeriod)+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//--- check for input parameter
if(InpMomPeriod<=0)
{
Print("Wrong input parameter Momentum Period=",InpMomPeriod);
return(INIT_FAILED);
}
//---
SetIndexDrawBegin(0,InpMomPeriod);
//--- initialization done
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Momentum |
//+------------------------------------------------------------------+
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[])
{
int i,limit;
//--- check for bars count and input parameter
if(rates_total<=InpMomPeriod || InpMomPeriod<=0)
return(0);
//--- counting from 0 to rates_total
ArraySetAsSeries(ExtMomBuffer,false);
ArraySetAsSeries(close,false);
//--- initial zero
if(prev_calculated<=0)
{
for(i=0; i<InpMomPeriod; i++)
ExtMomBuffer[i]=0.0;
limit=InpMomPeriod;
}
else
limit=prev_calculated-1;
//--- the main loop of calculations
for(i=limit; i<rates_total; i++)
ExtMomBuffer[i]=close[i]*100/close[i-InpMomPeriod];
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+
Comments