MOM-TC_v2
Download scriptThis indicator is designed to help traders identify the strength and direction of market momentum by visually mapping out trends and providing real-time notifications when those trends shift. It simplifies complex price movements into a clear, visual representation on your trading platform.
How the Logic Works
The script functions by analyzing the "Momentum" of the market over a specific number of periods (which can be customized). Essentially, it looks at how fast the price is moving in a given direction and compares that movement against a central baseline level.
Trend Detection & Visualization The indicator continuously monitors the current momentum. It categorizes the market into two primary states:
- Uptrend: When the momentum rises above the designated level, the script identifies an upward trend. This is highlighted on your chart using a green histogram.
- Downtrend: When the momentum falls below the level, the script identifies a downward trend, which is represented by an orange histogram.
Signal Generation Beyond just showing you the current trend, the script is designed to identify "crosses." A cross occurs at the exact moment the momentum shifts from one state to another (e.g., moving from below the level to above it).
- The indicator places specific visual markers (arrows) on the chart to pinpoint these transition moments.
- This allows traders to see exactly where a new trend began without having to guess if the momentum has actually flipped.
Automated Alerts To ensure you don't have to watch the screen every second, the script includes a built-in alert system. When a significant momentum cross occurs—meaning the market has officially switched from an upward bias to a downward bias, or vice versa—the script can trigger a real-time pop-up notification.
Summary for Traders
Think of this tool as a "trend filter." It takes raw price data and smooths it out to tell you:
- Direction: Is the market currently gaining strength (Up) or losing it (Down)?
- Timing: At what exact point did the trend change?
- Notification: Notify me immediately when the trend flips so I can react quickly to new price action.
/*
//+------------------------------------------------------------------+
//| Momentum with Alert Cross and signal.mq4 |
//| |
//| Original: RSI with Trend Catcher signal by Matsu |
//| Modified: Momentum with cross signal by Linuxser for Forex-TSD |
//| Modified by kalenzo, bartlomiej.gorski@gmail.com
//+------------------------------------------------------------------+
*/
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 LimeGreen
#property indicator_color2 LimeGreen
#property indicator_color3 Orange
#property indicator_color4 Orange
#property indicator_color5 LimeGreen
#property indicator_color6 Orange
#property indicator_level1 100
#property indicator_levelstyle STYLE_DOT
#property indicator_levelcolor Red
extern int MOMPeriod=14;
extern bool AlertOn = true;
double MOM[];
double Buy[];
double Sell[];
double DnMOM[];
double Levela[];
double hUP[],hDN[];
int Level= 0;
int init()
{
IndicatorBuffers(6);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MOM);
SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID);
SetIndexArrow(1,159);
SetIndexBuffer(1,Buy);
SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID);
SetIndexArrow(2,159);
SetIndexBuffer(2,Sell);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,DnMOM);
SetIndexBuffer(4,hUP);
SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexBuffer(5,hDN);
SetIndexStyle(5,DRAW_HISTOGRAM,STYLE_SOLID,1);
IndicatorShortName("Momentum("+MOMPeriod+")");
IndicatorDigits(2);
return(0);
}
int start()
{
int counted_bars=IndicatorCounted();
int shift,limit,ob,os;
bool TrendUp, TrendDn;
bool dn = false;
double BuyNow, BuyPrevious, SellNow, SellPrevious;
static datetime prevtime = 0;
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
limit=Bars-31;
if(counted_bars>=31) limit=Bars-counted_bars-1;
for (shift=limit;shift>=0;shift--)
{
MOM[shift]=iMomentum(NULL,0,MOMPeriod,PRICE_CLOSE,shift)-100;
ob = Level;
os = Level;
TrendUp=false;
TrendDn=false;
if(MOM[shift]>Level)
{
TrendUp=true;
hUP[shift] = MOM[shift];
hDN[shift] = 0;
}
else if(MOM[shift]<=Level)
{
TrendDn=true;
hDN[shift] = MOM[shift];
hUP[shift] = 0;
}
if (dn==true)
{
if (MOM[shift]>Level)
{
dn=false;
DnMOM[shift]=EMPTY_VALUE;
}
else
{
dn=true;
DnMOM[shift]=MOM[shift];
}
}
else
{
if (MOM[shift]<Level)
{
dn=true;
DnMOM[shift]=MOM[shift];
}
else
{
dn=false;
DnMOM[shift]=EMPTY_VALUE;
}
}
if(TrendUp==true)
{
Buy[shift]=ob;
Sell[shift]=EMPTY_VALUE;
}
else
if(TrendDn==true)
{
Buy[shift]=EMPTY_VALUE;
Sell[shift]=os;
}
else
{
Buy[shift]=EMPTY_VALUE;
Sell[shift]=EMPTY_VALUE;
}
}
// ======= Alert =========
if(AlertOn)
{
if(prevtime == Time[0])
{
return(0);
}
prevtime = Time[0];
BuyNow = Buy[0];
BuyPrevious = Buy[1];
SellNow = Sell[0];
SellPrevious = Sell[1];
if((BuyNow ==ob) && (BuyPrevious ==EMPTY_VALUE) )
{
Alert(Symbol(), " M", Period(), " Momentum Cross UP Alert");
}
else
if((SellNow ==os) && (SellPrevious ==EMPTY_VALUE) )
{
Alert(Symbol(), " M", Period(), " Momentum Cross Down Alert");
}
IndicatorShortName("Momentum("+MOMPeriod+") (Alert on)");
}
// ======= Alert End =========
return(0);
}
Comments