Triggerlines2_v1

Download script
Triggerlines2_v1

This script is designed as a technical analysis tool for the MetaTrader trading platform. It generates visual signals on a price chart by calculating and plotting two distinct types of moving averages to help traders identify momentum and potential trend shifts.

Core Functional Logic

The tool operates by analyzing historical price data over a specific timeframe (defined by the "Rperiod" setting) to calculate a customized weighted average. Here is the step-by-step breakdown of how it processes information:

1. Weighted Data Calculation Instead of treating every previous price point as equally important, the script assigns a different level of significance (weight) to each price point. It calculates a "Weighted Sum" where more recent prices carry a specific mathematical influence compared to older ones. This helps the indicator react more dynamically to current market movements while still considering historical context.

2. Linear Smoothed Average (LSMA) The script then takes that weighted data and applies a secondary smoothing process. It creates a "Linear Smoothed Moving Average." This acts as a filter, removing the "noise" or minor fluctuations of the market to reveal the underlying trend more clearly.

3. Visual Comparison and Filtering The primary purpose of the script is to compare these two values:

  • The Weighted Line: Represents the immediate weighted momentum of the price.
  • The Smoothed Line: Represents the broader trend direction.

4. Dynamic Color Coding & Signal Logic The tool uses a specific logic to filter what information is displayed on your screen:

  • When the weighted momentum is higher than the smoothed average, the script highlights both lines (typically in blue), suggesting a specific market sentiment.
  • When the weighted momentum falls below the smoothed average, the script automatically hides those specific data points (setting them to an "Empty Value").

Summary for Traders

Essentially, this tool acts as a visual filter. It focuses your attention on specific market conditions by only displaying full trend lines when the price momentum meets certain criteria relative to its moving average. This allows traders to visually identify high-interest zones where momentum and smoothed trends align, while filtering out periods that do not meet the script's mathematical requirements.

Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Triggerlines2_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                 Triggerlines.mq4 |
//|                             Copyright © 2005 dwt5 and adoleh2000 |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005 dwt5 and adoleh2000 "
#property  link      "http://www.metaquotes.net/"

//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 4            
#property indicator_color1 Red      
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Blue

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

int width;

extern int Rperiod = 15;
extern int LSMA_Period = 5;
int Draw4HowLong;
int shift;
int i;
int j;
int loopbegin;
int length;
int lsma_length;

double lengthvar;
double tmp ;
double tmp2 ;
double wt[];
double sum[];
double lsma_sum[];
double lsma_ma[];
double middle[];
int c;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 7 additional buffers are used for counting.
   IndicatorBuffers(7);   
   
//---- drawing settings
   
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
   
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,2);
   
   
   
   SetIndexBuffer(4,sum);        
   SetIndexBuffer(5,wt);         
   SetIndexBuffer(6,lsma_ma);
   
//---- initialization done
   return(0);
  }

int start()

  {   Draw4HowLong = Bars-Rperiod - 5;                            //Rperiod = 20
      length = Rperiod;                                           //length now = 20  
      lsma_length = LSMA_Period;
      loopbegin = Draw4HowLong - length - 1;   
      

      for(shift = loopbegin; shift >= 0; shift--)  //  MAIN For Loop
      { 
         sum[1] = 0;                                              
         for(i = length; i >= 1  ; i--)             //LSMA loop
         {
         lengthvar = length + 1;                               //lengthvar = 21  
         lengthvar /= 3;                                       //lengthvar = 7
         tmp = 0;
         tmp = ( i - lengthvar)*Close[length-i+shift];         //tmp = 20 - 7 * close[20-i+shift]
         sum[1]+=tmp;
         }
         wt[shift] = sum[1]*6/(length*(length+1));  
         j = shift;
         lsma_ma[shift] = wt[j+1] + (wt[j]-wt[j+1])* 2/(lsma_length+1);
  
                          
//========== COLOR CODING ===========================================                       
        
        
            ExtMapBuffer1[shift] = wt[shift]; 
            ExtMapBuffer2[shift] = lsma_ma[shift]; 
            ExtMapBuffer3[shift] = wt[shift]; 
            ExtMapBuffer4[shift] = lsma_ma[shift]; 
            
            
            
            if (wt[shift]  < lsma_ma[shift])
            {
                ExtMapBuffer4[shift] = EMPTY_VALUE;
                ExtMapBuffer3[shift] = EMPTY_VALUE;
           }          
        
        }
  }
//+------------------------------------------------------------------+



Comments