Execute Linesw-1(Alert)

Download script
Execute Linesw-1(Alert)

This technical indicator is designed to identify and visualize market trends by analyzing price momentum through a multi-layered smoothing process. Instead of simply looking at the raw price, it processes data through several mathematical stages to filter out "noise" and highlight significant movements.

Core Logic Overview

The script operates using a three-step calculation process:

1. Momentum Calculation The indicator first calculates a specific momentum value by comparing two different moving averages. It takes twice the value of a shorter-term average and subtracts a longer-term average from it. This helps determine the "velocity" of price changes relative to the established trend.

2. Secondary Smoothing (Mapping) To ensure the signals aren't too erratic, the script takes that momentum data and applies an additional smoothing layer (an average of the averages). This results in a refined "Map Buffer"—a smoother line that represents the core underlying direction of the market movement.

3. Trend Identification & Signaling The script constantly monitors the direction of this "Map Buffer" line:

  • Upward Trend: When the buffer line moves higher than its previous point, the logic identifies an upward trend. It then plots a blue line on your chart to represent this growth.
  • Downward Trend: When the buffer line moves lower than its previous point, it identifies a downward trend and plots a red line.

Key Features for the User

  • Visual Differentiation: The indicator clearly separates "Up" and "Down" movements into distinct colors (Blue for Up, Red for Down), making it easy to see the current market bias at a glance.
  • Trend Continuity: The logic is designed to "hold" a trend signal as long as the direction remains consistent. It only switches labels when the momentum actually reverses.
  • Automated Alerts: The script features an intelligent alert system. It detects the exact moment the trend shifts—for example, if the market was trending down and suddenly switches to an upward movement—and triggers a notification on your platform.
  • Customizable Period: Users can adjust the "Period" setting to make the indicator more sensitive (reacting faster to small price changes) or more conservative (ignoring small fluctuations to focus only on major moves).
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
12 Views
0 Downloads
0 Favorites
Execute Linesw-1(Alert)
#property indicator_separate_window 
#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(); 
    bool direction =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;
      if (direction == -1) Alert("Signal DOWN - ",Symbol()," ",Period()," at ",TimeToStr(TimeCurrent(),TIME_SECONDS));
      direction = 1;
    }
    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 (direction == 1)Alert("Signal UP - ",Symbol()," ",Period()," at ",TimeToStr(TimeCurrent(),TIME_SECONDS));
      direction = -1;
    }              
	
    //Print( " trend=",trend[x]);
    
    }
    
    
   
    
    return(0); 
} 
//+------------------------------------------------------------------+ 

Comments