i_daymomentum_v1_1
Download scriptThis tool is designed to measure the strength and direction of a market's price movement over a specific period. By calculating "Momentum," it helps traders understand whether an asset is accelerating, slowing down, or reversing its current trend.
Core Logic Overview
The script works by analyzing the relationship between current prices and historical prices based on a user-defined timeframe. Instead of just looking at the last few minutes, it intelligently calculates the progression of movement over a set number of days.
Key Functional Components
-
Time-Based Tracking: The tool is programmed to look back across multiple days of trading history. It automatically adjusts its calculations based on how many days of data you wish to analyze, allowing you to see longer-term trends or shorter-term fluctuations depending on your needs.
-
Smart Day Counting: One of the specific features of this logic is its ability to identify actual calendar days. The script scans through the price history to ensure it accurately counts how many "trading days" have passed, rather than just counting every single candle or bar on the chart. This ensures that the momentum data remains consistent even if there are gaps in trading activity (like weekends or holidays).
-
Price Sensitivity: The calculation can be customized to focus on different types of price data (such as opening, closing, high, or low prices), giving you the flexibility to choose which specific market behavior you want to track most closely.
-
Visual Output: The result is displayed as a continuous line in a separate window below your main chart. This allows you to visualize the "velocity" of the market:
- When the line moves upward, it suggests increasing buying pressure or upward momentum.
- When the line moves downward, it suggests selling pressure or a loss of upward momentum.
Usage Constraints
To ensure accuracy, the script includes a safety check that prevents it from running on timeframes larger than one day (such as weekly or monthly charts). This ensures the internal math remains precise and focused on the daily price movements intended by the developer.
//+------------------------------------------------------------------+
//| DayMomentum.mq4 |
//| Copyright 2010-2015, Excstrategy |
//| http://www.ExcStrategy.ru |
//+------------------------------------------------------------------+
#property copyright "ExcStrategy"
#property link "http://www.ExcStrategy.ru"
#property version "1.1"
#property description "Momentum"
#property strict
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_width1 1
//----
extern int Applied_price=0;
//----
extern int DaysForCalculation=2;
//---- buffers
double Buffer1[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(1);
//---- indicator lines
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Buffer1);
//----
SetIndexLabel(0,"Momentum");
//---
DaysForCalculation=DaysForCalculation+1;
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if(Period()>1400)
{
Alert("Error! Period can not be greater than D1");
return(0);
}
//----
int counted_bars=IndicatorCounted();
int barsday;
bool rangeday;
datetime Time1=Time[0],Time2;
//----
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
//----
for(int i=0; i<limit; i++)
{
//----
rangeday= false;
barsday = 0;
//----
Time2=Time[i]+(1440*60*DaysForCalculation);
if(Time1<Time2)
if(i<Bars-MathRound(1500/Period()))
for(int a=i; a<i+1441; a++)
{
//----
barsday++;
//----
if(TimeDayOfYear(Time[a])!=TimeDayOfYear(Time[a+1])) a=i+1442;
}
//----
Buffer1[i]=iMomentum(NULL,0,barsday,Applied_price,i);
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments