MA_PriceCcrossClose

Download script
Author:
MA_PriceCcrossClose

This tool is designed to provide a visual representation of price trends by comparing current market movements against a smoothed average. It serves as a dynamic guide on your trading chart, helping to distinguish between "bullish" and "bearish" market conditions based on where the price sits in relation to a moving baseline.

Core Functionality

The script calculates a Moving Average—a mathematical line that smooths out short-term price fluctuations to reveal the underlying direction of the market. By using this average, the tool helps filter out "market noise," making it easier to see the broader trend.

How the Logic Works

The indicator monitors the relationship between two specific data points: the current closing price of an asset and its calculated Moving Average. It then categorizes the market into three distinct visual states:

  • The Baseline: The primary calculation creates a continuous line that represents the average price over a specific period. This acts as the "equilibrium" point for the market.
  • Bearish Detection (Price Below Average): When the market's closing price falls below the Moving Average, the script identifies this as a potential downward trend. In these instances, it marks the baseline to highlight that the price is currently underperforming relative to its recent history.
  • Bullish Detection (Price Above Average): Conversely, when the closing price stays above the Moving Average, the script recognizes this as an upward trend. It highlights the baseline to signify that the price is maintaining strength.

Visual Experience

Instead of just showing a single line, the script uses different colors to signal these shifts. By monitoring whether the price is "above" or "below" the moving average, it provides a clear visual cue to traders. This allows you to quickly identify at a glance whether the market sentiment is leaning toward growth (strength) or decline (weakness), helping you stay aligned with the prevailing momentum of the chart.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
8 Views
0 Downloads
0 Favorites
MA_PriceCcrossClose
//+------------------------------------------------------------------+
//|                                                            MA_xP |
//+------------------------------------------------------------------+
//2008fxtsd  ki  
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 3

#property indicator_color1 Yellow
#property indicator_color2 Maroon
#property indicator_color3 SlateBlue



extern int ma_period  =9;
extern int ma_method =1;
extern int ma_price  =0;

double Buffer1[];
double Buffer2[];
double Buffer3[];



//+---

int init()
  {

  SetIndexBuffer(0,Buffer1);  SetIndexStyle(0,DRAW_LINE);
  SetIndexBuffer(1,Buffer2);  SetIndexStyle(1,DRAW_LINE);
  SetIndexBuffer(2,Buffer3);  SetIndexStyle(2,DRAW_LINE);


   return(0);
  }

//+----


int start()
{
   int i,limit;
   int counted_bars=IndicatorCounted();

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;

   limit = Bars-counted_bars;

   for(i=limit; i>=0; i--)
   {

   double MA=iMA(NULL,0,ma_period,0,ma_method,ma_price,i) ;


   Buffer1[i] = MA;   
   Buffer2[i] = EMPTY_VALUE; 
   Buffer3[i] = EMPTY_VALUE;
      
      
   if (Close[i]<MA) Buffer2[i]= MA;   
   if (Close[i]>MA) Buffer3[i]= MA;

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

Comments