VininI_LRMA_color

Download script
Author: Victor Nicolaev aka Vinin

This script is a custom technical analysis tool designed for the MetaTrader platform. It serves as a visual aid to help traders identify market trends by calculating specific moving averages and displaying them on the price chart.

Core Logic and Methodology

The tool operates by processing historical price data to calculate three different types of "weighted" averages simultaneously. Here is a breakdown of how it functions:

1. Data Calculation The script looks at a specific window of time (defined by the user-set period) and calculates two distinct types of moving averages:

  • Simple Moving Average (SMA): A standard average where every data point in the period carries equal weight.
  • Linear Weighted Moving Average (LWMA): An average that gives more importance to the most recent price data points, making it more responsive to current market action.

2. The Smoothing Formula The indicator doesn't just show these averages individually. Instead, it uses a mathematical formula to combine them. By blending the SMA and the LWMA (specifically using a weighted calculation of $3 \times \text{LWMA} - 2 \times \text{SMA}$), the tool creates a "smoothed" data line. This hybrid approach is intended to capture the stability of a simple average while maintaining the sensitivity of a weighted one.

3. Visual Signaling (Trend Identification) The most unique feature of this script is how it handles its visual output. It uses three different colors—Yellow, Green, and Red—to represent the direction of the market trend:

  • Upward Momentum: When the calculated value is higher than the previous period's value, the tool emphasizes the upward movement.
  • Downward Momentum: When the calculated value is lower than the previous period's value, it emphasizes the downward movement.
  • Neutral/Flat Movement: If there is no change in the value compared to the previous period, the visual indicators remain neutral.

Summary for the User

In essence, this tool acts as a "trend filter." Rather than showing you cluttered raw data, it processes the price history into a single, smoothed line that highlights whether the current market momentum is moving up or down. By visually changing which color is active based on whether the value is rising or falling, it helps traders quickly identify the prevailing direction of the market at a glance.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
VininI_LRMA_color
//+------------------------------------------------------------------+
//|                                             Vinin HighLow v1.mq4 |
//|                                        Victor Nicolaev aka Vinin |
//|                                                    vinin@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Victor Nicolaev aka Vinin"
#property link      "mailto: vinin@mail.ru"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red

extern int period=34;
extern int price=0;
extern int Shift=0;

//---- buffers
double BufferGreen[];
double BufferYellow[];
double BufferRed[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int i;
   for(i=0;i<3;i++)
     {
      SetIndexStyle(i,DRAW_LINE);
      SetIndexDrawBegin(i,period);
      SetIndexShift(i,Shift);
     }
   SetIndexBuffer(0,BufferYellow);
   SetIndexBuffer(1,BufferGreen);
   SetIndexBuffer(2,BufferRed);

   return(0);
  }//int init() 
//+------------------------------------------------------------------+
int start()
  {
   double tmp1,tmp2,tmp3;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=1+1;
   for(int i=limit;i>=0;i--)
     {
      tmp1=iMA(Symbol(),0,period,0,MODE_SMA,price,i);
      tmp2=iMA(Symbol(),0,period,0,MODE_LWMA,price,i);
      tmp3=3.0*tmp2-2.0*tmp1;
      BufferGreen[i] =tmp3;
      BufferYellow[i]=tmp3;
      BufferRed[i]   =tmp3;
      if(BufferYellow[i]>BufferYellow[i+1])
        {
         BufferRed[i]=EMPTY_VALUE;
           } else if(BufferYellow[i]<BufferYellow[i+1]){
         BufferGreen[i]=EMPTY_VALUE;
           } else {
         BufferRed[i]=EMPTY_VALUE;
         BufferGreen[i]=EMPTY_VALUE;
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments