This script is designed as a visual trading tool for the MetaTrader platform, specifically intended to help traders identify momentum and potential trend exhaustion. It functions by tracking consecutive price movements over a specific period and labeling them directly on your chart.
How the Logic Works
The core objective of this script is to count how many times the market has moved in a single direction relative to a fixed point in the past. Instead of looking at every single candle, it compares the closing price of a previous candle against a price from five candles prior.
1. Identifying Downward Momentum (Bearish Trend) The script monitors whether the market is consistently moving lower. If the closing price of a candle is lower than the closing price from five bars ago, the script begins an incremental count:
- Progressive Counting: It labels the chart with numbers (1 through 9) to show how many consecutive "downward" movements have occurred.
- Visual Cues: As the count increases toward 9, the numbers appear in red to warn of strengthening downward pressure.
- Extended Momentum: If the downward movement continues beyond a count of 10, the labels shift color to orange, signifying an extended trend.
2. Identifying Upward Momentum (Bullish Trend) Simultaneously, the script performs the opposite calculation to track upward movement. If the closing price of a candle is higher than the closing price from five bars ago, it begins a separate count:
- Progressive Counting: It places numbers on the chart to indicate how many consecutive "upward" movements have occurred.
- Visual Cues: These labels typically appear in Royal Blue. When the count reaches 9—a potential point of exhaustion or trend strength—the font size increases for higher visibility.
- Extended Momentum: If the upward move persists beyond a count of 10, the color shifts to Light Sky Blue to indicate an ongoing, sustained trend.
Summary for the Trader
Think of this tool as a "momentum counter." It automatically scans your price history and places numerical labels above or below the candles based on the direction of the market. By observing these numbers, you can visually gauge how long a current trend has been sustaining itself. This helps in identifying whether a move is just beginning, gaining significant strength, or reaching a point where the trend might be overextended.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| TD_Sequential.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "James OBrien"
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 LimeGreen
//#property indicator_color2 Red
//---- input parameters
//int shift=0;
int i;
int num=0;
int num1=0;
string textVar;
//---- buffers
double ExtMapBuffer1[];
//double ExtMapBuffer2[];
//double b4plusdi,b4minusdi,nowplusdi,nowminusdi;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,159);
SetIndexBuffer(0, ExtMapBuffer1);
/*
SetIndexStyle(1,DRAW_ARROW,EMPTY);
SetIndexArrow(1,234);
SetIndexBuffer(1, ExtMapBuffer2);
*/
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
int limit;
limit=1500;
for(int i=limit; i>=0; i--)
{
ObjectDelete(""+i);
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=1500-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=limit; i>=0; i--)
{
if(Close[i+1]<Close[i+5])num = num + 1;
else num = 0;
if (num > 0 && num < 10) {
textVar = num;
ObjectCreate(""+i, OBJ_TEXT, 0, Time[i+1],Low[i+1]-5*Point );
ObjectSetText(""+i, ""+DoubleToStr(num,0), 10, "Arial", Red);
}
if (num == 9) {
ObjectCreate(""+i, OBJ_TEXT, 0, Time[i+1],Low[i+1]-5*Point );
ObjectSetText(""+i, ""+DoubleToStr(num,0), 16, "Arial", Red);
}
else if((Close[i+1]<Close[i+5])&& num>=10)
{
ObjectCreate(""+i, OBJ_TEXT, 0, Time[i+1],Low[i+1]-5*Point );
ObjectSetText(""+i, ""+DoubleToStr(num,0), 10, "Arial", Orange);
}
if(Close[i+1]>Close[i+5]) num1 = num1 + 1;
else num1 = 0;
if (num1 > 0 && num1 < 10)
{
textVar = num1;
ObjectCreate(""+i, OBJ_TEXT, 0, Time[i+1],High[i+1]+10*Point );
ObjectSetText(""+i, ""+DoubleToStr(num1,0), 10, "Arial", RoyalBlue);
}
if (num1 == 9) {
ObjectCreate(""+i, OBJ_TEXT, 0, Time[i+1],High[i+1]+10*Point );
ObjectSetText(""+i, ""+DoubleToStr(num1,0), 16, "Arial", RoyalBlue);
}
else if((Close[i+1]>Close[i+5])&& num1>=10)
{
ObjectCreate(""+i, OBJ_TEXT, 0, Time[i+1],High[i+1]+10*Point );
ObjectSetText(""+i, ""+DoubleToStr(num1,0), 10, "Arial", LightSkyBlue);
}
}
//----
return(0);
}
Comments