Triggerlines Shift Modified_001

Download script
Author: Copyright � 2006, MetaQuotes Software Corp.
Triggerlines Shift Modified_001

This script is designed as a technical analysis tool for the MetaTrader trading platform. Its primary purpose is to visualize specific price trends and momentum shifts by calculating two distinct moving average lines on your chart.

Core Functionality

The logic operates by analyzing historical price data to identify "weighted" trends. Unlike standard moving averages that give equal importance to all past prices, this script employs a custom calculation method to weigh price points differently, likely to highlight more significant market movements.

How the Logic Works

  1. Dual Trend Calculation: The script generates two primary sets of data. One represents the raw weighted trend based on a user-defined period, and the other represents a smoothed version of that trend (a Linearly Smoothed Moving Average).
  2. Dynamic Weighting: The tool calculates a sum of prices where each price point is multiplied by its position relative to the time frame. This means it prioritizes specific sections of the data over others to determine the current "weight" of the trend.
  3. Smoothing Mechanism: It then takes that weighted data and applies a secondary smoothing calculation. This creates a cleaner, less volatile line that helps traders see the broader direction of the market without the "noise" of minor price fluctuations.

Visual Behavior and Alerts

The script is designed to provide clear visual cues for traders:

  • Visual Representation: It plots four distinct data points, but it uses them to create a specific visual experience on the chart using different colors (Red and Blue).
  • Conditional Visibility: A key feature of this logic is its ability to "hide" certain information based on market conditions. Specifically, if the weighted trend falls below the smoothed moving average, the script automatically hides those specific lines.

Summary for the Trader

In practical terms, this tool helps you distinguish between a strengthening trend and a weakening one. By filtering out the data where the weight drops below the smooth average, it helps clarify the current market "bias," making it easier to see when the momentum is moving in your favor versus when it is losing strength.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
Triggerlines Shift Modified_001
//+------------------------------------------------------------------+
//|                                  Triggerlines Shift Modified.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#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=20;
extern int RperiodShift=0;
extern int LSMA_Period=20;
extern int LSMA_PeriodShift=0;
//----
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,1);
   SetIndexShift(0,LSMA_PeriodShift);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   SetIndexShift(1,LSMA_PeriodShift);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
   SetIndexShift(2,RperiodShift);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
   SetIndexShift(3,RperiodShift);
   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]; 
      
      int Buffer1=ExtMapBuffer1[shift];
      int Buffer2=ExtMapBuffer2[shift];
      int Buffer3=ExtMapBuffer3[shift];
      int Buffer4=ExtMapBuffer4[shift];
      
      if (wt[shift]  < lsma_ma[shift])
        {
         ExtMapBuffer4[shift]=EMPTY_VALUE;
         ExtMapBuffer3[shift]=EMPTY_VALUE;
        }
    
        
     }
  }
//+------------------------------------------------------------------+

Comments