Execute Linesw Alert
Download scriptThis script functions as a technical analysis tool designed to identify and visualize market trends by processing price data through several layers of mathematical smoothing. Instead of looking at raw price movements, which can be volatile and noisy, the logic focuses on the underlying momentum to provide clearer signals for upward and downward movements.
Core Processing Logic
The indicator operates using a three-step calculation process:
-
Momentum Vector Calculation: The script first calculates two different weighted moving averages based on your chosen period. It then creates a "vector" by doubling the faster average and subtracting the slower one. This mathematical approach helps highlight the speed and strength of price changes, essentially stripping away minor fluctuations to reveal the core trend.
-
Smoothing the Vector: Once the initial vector is created, the script applies an additional smoothing layer using a square-root calculation based on your input period. This second pass ensures that the resulting data is stable and less prone to "whipsaws" (false signals caused by sudden, minor price spikes).
-
Trend Identification: The final stage compares each point of the smoothed data against the previous point.
- If the current value is higher than the previous one, the script identifies an Uptrend.
- If the current value is lower than the previous one, it identifies a Downtrend.
Visual and Notification Features
To make this information actionable for the user, the script handles the data in the following ways:
- Dynamic Coloring: The indicator maps these trends onto your chart using distinct colors (Blue for upward trends and Red for downward trends). It is designed to show the active trend line while hiding the opposing one, making it easy to see the current market direction at a glance.
- Automated Alerts: One of the primary functions of this script is its ability to notify you in real-time. The logic monitors the transition points where a trend flips from positive to negative (or vice versa). When the script detects that a new trend has officially started, it triggers an immediate "Up Trend" or "Down Trend" alert on your platform.
- Alert Management: To prevent constant notifications during a single candle, the script includes a "memory" feature that ensures you only receive one alert per price bar, providing a clean and professional notification experience.
#property indicator_separate_window
#property link " Alert by Goen "
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int period=40;
int method=3; // MODE_SMA
int price=0; // PRICE_CLOSE
//---- buffers
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(0, Uptrend);
//ArraySetAsSeries(Uptrend, true);
SetIndexBuffer(1, Dntrend);
//ArraySetAsSeries(Dntrend, true);
SetIndexBuffer(2, ExtMapBuffer);
ArraySetAsSeries(ExtMapBuffer, true);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
IndicatorShortName("Execute Line("+period+")");
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
// ???? ????? ?????? ??????
return(0);
}
//+------------------------------------------------------------------+
//| ?????????? ??????? |
//+------------------------------------------------------------------+
double WMA(int x, int p)
{
return(iMA(NULL, 0, p, 0, method, price, x));
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
static datetime lastalert=0;
if(counted_bars < 0)
return(-1);
int x = 0;
int p = MathSqrt(period);
int e = Bars - counted_bars + period + 1;
double vect[], trend[];
if(e > Bars)
e = Bars;
ArrayResize(vect, e);
ArraySetAsSeries(vect, true);
ArrayResize(trend, e);
ArraySetAsSeries(trend, true);
for(x = 0; x < e; x++)
{
vect[x] = 2*WMA(x, period/2) - WMA(x, period);
// Print("Bar date/time: ", TimeToStr(Time[x]), " close: ", Close[x], " vect[", x, "] = ", vect[x], " 2*WMA(p/2) = ", 2*WMA(x, period/2), " WMA(p) = ", WMA(x, period));
}
for(x = 0; x < e-period; x++)
ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x);
for(x = e-period; x >= 0; x--)
{
trend[x] = trend[x+1];
if (ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1;
if (ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1;
if (trend[x]>0)
{ Uptrend[x] = ExtMapBuffer[x];
if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
Dntrend[x] = EMPTY_VALUE;
}
else
if (trend[x]<0)
{
Dntrend[x] = ExtMapBuffer[x];
if (trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
Uptrend[x] = EMPTY_VALUE;
}
if (Uptrend[x+1]!=EMPTY_VALUE && Uptrend[x+2]==EMPTY_VALUE && Time[0]!=lastalert)
{ lastalert=Time[0];
Alert("Up Trend");
}
if (Dntrend[x+1]!=EMPTY_VALUE && Dntrend[x+2]==EMPTY_VALUE && Time[0]!=lastalert)
{ lastalert=Time[0];
Alert("Down Trend");
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments