2

This tool is designed to help traders identify specific "crossover" moments between two different Moving Averages (MA) on a price chart. While standard moving averages are often useful, they can sometimes become difficult to read accurately when you zoom out or when the chart becomes cluttered with many candles. This script solves that problem by pinpointing exactly where these lines intersect and marking those spots with clear visual indicators.

How it Works

The logic operates by comparing two separate moving averages: a "Faster" period and a "Slower" period. By default, these are set to 10 and 20 units, but the tool allows for full customization of the following parameters:

  • Moving Average Type: You can choose between various calculation methods (such as Simple, Exponential, Smoothed, or Linear Weighted).
  • Price Source: You can define which price data the averages should calculate based on (such as Close, Open, High, Low, or various weighted averages).

Identifying the Signals

The script constantly scans the chart to detect two specific types of movements:

  1. Bullish Cross (Up): When the Faster moving average moves from below the Slower moving average to above it, the tool places a visual marker slightly below the candle's low price.
  2. Bearish Cross (Down): When the Faster moving average moves from above the Slower moving average to below it, the tool places a visual marker slightly above the candle's high price.

Dynamic Positioning

To ensure that the markers do not overlap with the actual price candles, the script performs a small calculation to determine the "Range" of the price action (the difference between the highs and lows over a recent period). It then uses this information to place the indicators at a consistent, comfortable distance away from the bars.

Key Benefits for Traders

  • Clarity: It highlights the exact moment of a trend shift, which is especially helpful on smaller timeframes where visual overlap makes it hard to see the precise crossover point.
  • Clean Charts: Because the tool places arrows rather than continuous lines, it allows you to remove the moving averages from your chart entirely if you prefer a cleaner look, while still keeping the important historical crossover points visible.
  • Versatility: By allowing you to change the periods and types of averages, the tool can be adapted to various trading styles, from fast-paced scalping to longer-term trend following.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
2
/*
  +------------------------------------------------------------------+
  | Allows you to enter two SMA periods and it will then show you at |
  | Which point they crossed over. It is more usful on the shorter   |
  | periods that get obscured by the bars / candlesticks and when    |
  | the zoom level is out. Also allows you then to remove the SMAs   |
  | from the chart. (SMAs are initially set at 10 and 20)              |
  +------------------------------------------------------------------+
*/   

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

double CrossUp[];
double CrossDown[];
extern int FasterSMA = 10;
extern int FasterPeriodMode =  0; //0=sma, 1=ema, 2=smma, 3=lwma
extern int FasterPriceMaMode =  0; //0=price close, 1=price open, 2=price high, 3=price low, 4=price median, 5=price typical, 6=price weighted
extern int SlowerSMA = 20;
extern int SlowerPeriodMode =  0; //0=sma, 1=ema, 2=smma, 3=lwma
extern int SlowerPriceMaMode =  0; //0=price close, 1=price open, 2=price high, 3=price low, 4=price median, 5=price typical, 6=price weighted
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int limit, i, counter;
   double fasterSMAnow, slowerSMAnow, fasterSMAprevious, slowerSMAprevious, fasterSMAafter, slowerSMAafter;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++) {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
       
      fasterSMAnow = iMA(NULL, 0, FasterSMA, 0, FasterPeriodMode, FasterPriceMaMode, i);
      fasterSMAprevious = iMA(NULL, 0, FasterSMA, 0, FasterPeriodMode, FasterPriceMaMode, i+1);
      

      slowerSMAnow = iMA(NULL, 0, SlowerSMA, 0, SlowerPeriodMode, SlowerPriceMaMode, i);
      slowerSMAprevious = iMA(NULL, 0, SlowerSMA, 0, SlowerPeriodMode, SlowerPriceMaMode, i+1);
      
      
      if ((fasterSMAnow > slowerSMAnow) && (fasterSMAprevious < slowerSMAprevious)) {
         CrossUp[i] = Low[i] - Range*0.5;
      }
      else if ((fasterSMAnow < slowerSMAnow) && (fasterSMAprevious > slowerSMAprevious)) {
         CrossDown[i] = High[i] + Range*0.5;
      }
   }
   return(0);
}

Comments