SMMA-Crossover_Signal_v1

Download script
Author: Copyright � 2005, Jason Robinson (jnrtrading)
SMMA-Crossover_Signal_v1

This tool is designed to simplify how traders identify specific trend shifts by highlighting the exact moment two moving averages intersect. Rather than requiring you to constantly watch complex lines on your chart, this script acts as an automated "signal" generator that places visual markers (arrows) at key turning points.

How it Works

The logic relies on comparing two different types of smoothed moving averages: a Faster period and a Slower period.

  • The Trend Detection: The script continuously monitors the relationship between these two averages. When the faster line moves above the slower line, it suggests upward momentum; when it drops below, it suggests downward momentum.
  • Pinpointing the Crossover: To ensure the signal is accurate and not just a temporary fluctuation, the script looks for a specific "crossover" event. It confirms that the lines were on one side of each other in the previous bar and have switched sides in the current bar.
  • Visual Indicators: Once a crossover is confirmed, the script automatically places a visual marker on your chart:
    • An upward signal appears below the candle when the faster average crosses above the slower one.
    • A downward signal appears above the candle when the faster average crosses below the slower one.

Key Features for the User

  • Cleaner Charts: One of the primary benefits of this script is that it allows you to remove the actual moving average lines from your view. This declutters your workspace while still providing you with the essential signals derived from those averages.
  • Enhanced Visibility: Because moving average lines can sometimes get "lost" or obscured by price candles (especially when zoomed out), these clear markers ensure you never miss a trend change.
  • Dynamic Positioning: The script calculates the recent price range to determine exactly where to place the arrows, ensuring they sit perfectly above or below the price action without overlapping your candles.
  • Customizable Periods: You can adjust the "Faster" and "Slower" settings (defaulted to 9 and 18) to match your specific trading style, whether you prefer fast-paced scalping signals or slower, more stable trend indicators.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
SMMA-Crossover_Signal_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                         SMA-Crossover_Signal.mq4 |
//|         Copyright © 2005, Jason Robinson (jnrtrading)            |
//|                   http://www.jnrtading.co.uk                     |
//+------------------------------------------------------------------+

/*
  +-------------------------------------------------------------------+
  | Allows you to enter two smoothed 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 emas from the chart. (smas are initially set at 9 and 18)     |
  +-------------------------------------------------------------------+
*/   
#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)"
#property link      "http://www.jnrtrading.co.uk"

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

double CrossUp[];
double CrossDown[];
extern int FasterSMMA = 9;
extern int SlowerSMMA = 18;
//+------------------------------------------------------------------+
//| 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 fasterSMMAnow, slowerSMMAnow, fasterSMMAprevious, slowerSMMAprevious, fasterSMMAafter, slowerSMMAafter;
   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;
       
      fasterSMMAnow = iMA(NULL, 0, FasterSMMA, 0, MODE_SMMA, PRICE_CLOSE, i);
      fasterSMMAprevious = iMA(NULL, 0, FasterSMMA, 0, MODE_SMMA, PRICE_CLOSE, i+1);
      fasterSMMAafter = iMA(NULL, 0, FasterSMMA, 0, MODE_SMMA, PRICE_CLOSE, i-1);

      slowerSMMAnow = iMA(NULL, 0, SlowerSMMA, 0, MODE_SMMA, PRICE_CLOSE, i);
      slowerSMMAprevious = iMA(NULL, 0, SlowerSMMA, 0, MODE_SMMA, PRICE_CLOSE, i+1);
      slowerSMMAafter = iMA(NULL, 0, SlowerSMMA, 0, MODE_SMMA, PRICE_CLOSE, i-1);
      
      if ((fasterSMMAnow > slowerSMMAnow) && (fasterSMMAprevious < slowerSMMAprevious) && (fasterSMMAafter > slowerSMMAafter)) {
         CrossUp[i] = Low[i] - Range*0.5;
      }
      else if ((fasterSMMAnow < slowerSMMAnow) && (fasterSMMAprevious > slowerSMMAprevious) && (fasterSMMAafter < slowerSMMAafter)) {
         CrossDown[i] = High[i] + Range*0.5;
      }
   }
   return(0);
}

Comments