FX Sniper's MA_002

FX Sniper's MA_002

This tool is designed to provide visual clarity on financial charts by identifying the directional momentum of a Moving Average. Rather than just showing a single fluctuating line, this script analyzes the "flow" of the average to highlight specific trends and transitions for the user.

Core Logic Overview

The script operates by calculating a standard Moving Average based on customizable parameters (such as the time period, the type of average used, and the specific price data it tracks). Once this average is established, the tool performs a secondary analysis to determine whether the average is currently trending upward or downward.

How It Works

The logic follows a three-step process:

  1. Baseline Calculation: The script first determines the position of the Moving Average at every point on the chart. This serves as the foundation for all subsequent visual actions.
  2. Trend Comparison: The tool compares the current value of the Moving Average against its previous value. It is looking for a change in direction:
    • If the average is moving higher than it was in the previous period, it identifies an upward trend.
    • If the average is moving lower than it was in the previous period, it identifies a downward trend.
  3. Visual Differentiation: Instead of drawing a continuous line, the script uses this logic to "paint" different sections of the chart:
    • When the trend moves up, it emphasizes the movement by populating one specific visual buffer while clearing the other.
    • When the trend moves down, it switches which buffer is populated.

User Experience

For the trader, this means that the indicator acts as a dynamic visual map. Instead of having to manually interpret whether a line is sloping up or down at any given moment, the script automatically separates these movements into distinct visual cues (represented by different colors). This allows for a quicker identification of trend shifts and helps in distinguishing between bullish and bearish price momentum on the chart.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
FX Sniper's MA_002
//+------------------------------------------------------------------+
//|                                                        |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2006, FX Sniper "
#property  link      "http://www.metaquotes.net/"

//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 2
#property indicator_color1 Red      
#property indicator_color2 Lime


//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[],ma[];
double uc[],lc[],coeff;
extern string TypeMA="SMA=0, EMA=1, SMMA=2, LWMA=3";
extern int MAType = 1;
extern int MAPeriod = 34;
extern int MAShift = 0;
extern string TypePrice="C=0,O=1,H=2,L=3,M=4,T=5,W=6";
extern int PriceType=0;
extern double Deviation=0;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(5);
   
//---- drawing settings
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ma);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
//---- initialization done
   return(0);
  }

int start()

  { 
  
         
      for(int i = Bars-10; i >= 0; i--)
           {
               ma[i]=iMA(NULL,0,MAPeriod,MAShift,MAType,PriceType,i)+(Deviation*Point);
           }     
   
     
     for(int shift = Bars-10; shift >= 0; shift--)
     {  
       ExtMapBuffer1[shift] = ma[shift]; 
       ExtMapBuffer2[shift] = ma[shift]; 
       //Print (ma[shift]);
        if (ma[shift] > ma[shift+1])
        {
        ExtMapBuffer1[shift] = EMPTY_VALUE;
        ExtMapBuffer2[shift+1] = ma[shift+1];
        
        }
       else if (ma[shift] < ma[shift+1]) 
        {
        ExtMapBuffer2[shift] = EMPTY_VALUE; 
        ExtMapBuffer1[shift+1] = ma[shift+1];
        }

      }
    
      return(0);
  }
//+------------------------------------------------------------------+



Comments