FX Sniper's MA Cross

Download script
FX Sniper's MA Cross

This custom technical indicator is designed to provide traders with a visual representation of momentum and trend direction by comparing two different moving averages. Instead of cluttering the main price chart, it operates in a separate window, providing a clear "signal" based on the relationship between short-term and long-term price actions.

Core Logic and Functionality

The indicator functions by calculating two distinct types of Moving Averages (MAs) simultaneously:

  1. Short-Term Average: This tracks the recent price fluctuations more closely, reacting quickly to immediate market changes.
  2. Long-Term Average: This smooths out the price data over a longer period, representing the broader market trend.

Users can customize these averages by selecting different timeframes (periods) and calculation types (such as Simple, Exponential, or Linear Weighted) to suit their specific trading strategy.

How It Generates Signals

The indicator compares the values of these two moving averages at every point on the chart to determine the market's current "bias." It then translates this information into a color-coded histogram:

  • Bullish Momentum (Blue): When the short-term average rises above the long-term average, the indicator displays a blue histogram. This suggests that recent price action is stronger than the historical average, often indicating an upward trend or bullish momentum.
  • Bearish Momentum (Red): When the short-term average falls below the long-term average, the indicator displays a red histogram. This suggests that recent price action is weaker than the historical average, often indicating a downward trend or bearish momentum.

Visual Representation

By using a histogram format in a dedicated window, the tool allows traders to see at a glance whether the current market sentiment is positive or negative. The visual switch between blue and red provides a binary signal of "strength," helping traders identify when to align with the prevailing trend or recognize potential shifts in market direction.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
5 Views
0 Downloads
0 Favorites
FX Sniper's MA Cross
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//Coded By FX Sniper


#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+


extern int MA1 = 5;
extern int MA1_Type = 1;
extern int MA2 = 20;
extern int MA2_Type = 1;

double buf1[];
double buf2[];
double buf3[];
double buf4[];


int init()
  {
//---- indicators
// ObjectDelete("EU");
// ObjectDelete("USSession");
//----
   IndicatorBuffers(8);
   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,5,Blue);
   SetIndexBuffer(0,buf1);
  
   SetIndexStyle(1,DRAW_HISTOGRAM,EMPTY,5,Red);
   SetIndexBuffer(1,buf2);
  
  SetIndexBuffer(2,buf3);
  SetIndexBuffer(3,buf4);
  
   IndicatorShortName(" ");
//----
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
      for (int x=Bars;x>=0;x--) 
   {  
   
   switch(MA1_Type)
    {
      case 1:
       buf3[x]=iMA(NULL,0,MA1,0,MODE_SMA,PRICE_CLOSE,x);
       break;
      case 2:
       buf3[x]=iMA(NULL,0,MA1,0,MODE_EMA,PRICE_CLOSE,x);
       break;
      case 3:
       buf3[x]=iMA(NULL,0,MA1,0,MODE_LWMA,PRICE_CLOSE,x);
       break;
        
   }
   
   switch(MA2_Type)
    {
      case 1:
       buf4[x]=iMA(NULL,0,MA2,0,MODE_SMA,PRICE_CLOSE,x);
       break;
      case 2:
       buf4[x]=iMA(NULL,0,MA2,0,MODE_EMA,PRICE_CLOSE,x);
       break;
      case 3:
       buf4[x]=iMA(NULL,0,MA2,0,MODE_LWMA,PRICE_CLOSE,x);
       break; 
   }
   
   
      if (buf3[x]>buf4[x])
         {         
            buf1[x]=24;
            buf2[x]=0;
         }
         else
         {  buf2[x]=24;
            buf1[x]=0; 
         }
       
   }
   
      return(0);
  }
//+------------------------------------------------------------------+

Comments