TriggerLineExp-mod

Download script
TriggerLineExp-mod

This script functions as a technical analysis tool designed to identify specific trends and potential turning points in market price action. It operates by calculating two distinct moving averages and comparing them to create visual "trigger" lines on your trading chart.

Core Logic & Mechanics

The tool works by processing historical price data (specifically the closing prices) through a multi-step mathematical sequence:

1. Trend Calculation Instead of using a standard simple average, the script calculates a weighted value based on a user-defined period (referred to as the Rperiod). This calculation assigns different importance to price points over time, allowing the tool to react more dynamically to recent price changes while still considering historical data.

2. Smoothing the Data Once the weighted trend is established, the script applies a "Linear Smoothed Moving Average" (LSMA). This acts as a secondary layer of processing that cleans out minor market "noise," creating a smoother line that represents the underlying momentum of the asset.

3. The Comparison (The "Trigger") The heart of the script lies in the comparison between these two lines: the weighted trend and the smoothed average. The tool constantly monitors whether the weighted trend is moving above or below its smoothed counterpart.

Visual Representation

To make this information easy to read on a chart, the script uses color-coded visual buffers to signal market sentiment:

  • Downside Momentum (Red): When the weighted trend falls below the smoothed average, the tool activates red lines. This typically signifies bearish pressure or a downward price movement.
  • Upside Momentum (Blue): When the weighted trend rises above the smoothed average, the tool switches to blue lines. This typically signifies bullish pressure or an upward price movement.

Summary for the Trader

Essentially, this script acts as a visual momentum filter. By looking at where the colors shift from Blue to Red (or vice versa), traders can identify moments where the short-term weighted price action is breaking away from its smoothed average, potentially highlighting shifts in market direction.

Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
TriggerLineExp-mod
//+------------------------------------------------------------------+
//|                                                     Trigger Line |
//|                             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()

  {   if(Rperiod<50) {int lp=100;} else {lp=Rperiod*2;}
      Draw4HowLong = lp - 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 ===========================================                       
        
        
            if (wt[shift]  < lsma_ma[shift])
            {
            ExtMapBuffer1[shift] = wt[shift]; 
            ExtMapBuffer2[shift] = lsma_ma[shift]; 
            ExtMapBuffer3[shift] = 0; 
            ExtMapBuffer4[shift] = 0; 
            }
            if (wt[shift]  > lsma_ma[shift])
            {
            ExtMapBuffer1[shift] = 0; 
            ExtMapBuffer2[shift] = 0; 
            ExtMapBuffer3[shift] = wt[shift];
            ExtMapBuffer4[shift] = lsma_ma[shift]; 
            }       
        
        }
  }
//+------------------------------------------------------------------+

Comments