Author: Copyright � 2005, MetaQuotes Software Corp.
SMI_Color

The SMI Color indicator is a visual trading tool designed to help market analysts identify momentum and trend direction through color-coded signals. By processing historical price data, it translates complex mathematical movements into an intuitive display that highlights whether the market is moving upward, downward, or remaining neutral.

Core Functionality

The logic behind this script relies on comparing two different types of smoothed averages (referred to as "Smooth" and "High Quality"). The indicator calculates these values using specific timeframes and smoothing methods—such as Simple Moving Averages (SMA) or Exponential Moving Averages (EMA)—which you can customize in the settings.

By dividing one average by the other, the tool produces a percentage-based value. This value represents the relative strength of the current price momentum compared to its historical baseline.

Visual Logic and Color Coding

The primary purpose of this script is to change the visual representation of the indicator based on whether the momentum value is increasing or decreasing. The logic categorizes the market movement into three distinct states:

  • Upward Momentum (Green): When the current momentum value is lower than the previous value, the script recognizes a shift in trend and highlights it with green markers.
  • Downward Momentum (Red): When the current momentum value is higher than the previous value, the script identifies a shift in the opposite direction and highlights it with red markers.
  • Neutral/Flat Momentum (Yellow): If the momentum value remains unchanged between two points, the indicator reflects a "flat" state using yellow markers.

Key Features for the User

  • Dynamic Smoothing: Users can choose different calculation methods (SMA, EMA, SMMA, or LWMA) to determine how quickly or slowly the indicator reacts to new price data.
  • Customizable Periods: The script allows for the adjustment of various periods (Q, R, S, and Signal), enabling traders to fine-tune the sensitivity of the tool to match different trading styles—from fast-paced scalping to longer-term trend following.
  • Visual Clarity: Instead of a standard line chart that may be difficult to read at a glance, this script uses distinct markers (arrows) and colors to provide an immediate "at-a-glance" summary of market sentiment.
6 Views
0 Downloads
0 Favorites
SMI_Color
//+------------------------------------------------------------------+
//|                                                    SMI Color.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_level1 0
#property indicator_level2 60
#property indicator_level3 -60


//---- input parameters
extern int       Period_Q =10;
extern int       Period_R =3;
extern int       Period_S =5;
extern int       Signal   =3;
extern int       method   =1;          // O MODE_SMA 1 MODE_EMA 2 MODE_SMMA 3 MODE_LWMA 


//---- buffers
double SMI_BufferFLAT[];
double SMI_BufferUP[];
double SMI_BufferDOWN[];
double SMI_Buffer[];

double EMA2_SM;
double EMA2_HQ;

// double EMA_HQ[];
// double EMA_SM[];

// double SM_Buffer[];
// double HQ_Buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(4);
   IndicatorDigits(Digits + 1);
   
//---- drawing settings
   SetIndexBuffer(0,SMI_BufferFLAT);       // FLAT SMI
   SetIndexBuffer(1,SMI_BufferUP);       // UP SMI
   SetIndexBuffer(2,SMI_BufferDOWN);       // DOWN SMI

// line => dot changes

/*
	SetIndexStyle(0,DRAW_LINE,STYLE_SOLID); 
	SetIndexStyle(1,DRAW_LINE,STYLE_SOLID); 
	SetIndexStyle(2,DRAW_LINE,STYLE_SOLID); 
*/

	SetIndexStyle(0,DRAW_ARROW);
	SetIndexStyle(1,DRAW_ARROW);
	SetIndexStyle(2,DRAW_ARROW);

	SetIndexArrow(0,159);
	SetIndexArrow(1,159);
	SetIndexArrow(2,159);
//----   

//----
   SetIndexBuffer(3,SMI_Buffer);
   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("SMI("+Period_Q+","+Period_R+","+Period_S+","+Signal+")");

   SetIndexLabel(0,"SMI_FLAT");
   SetIndexLabel(1,"SMI_UP");
   SetIndexLabel(2,"SMI_DOWN");

//----  initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit;
   int i;
//   double Median_Q[];
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
//   limit=Bars-Period_Q-counted_bars;
   limit=Bars-Period_Q;


   for (i=limit-Period_R-Period_S;i>=0;i--)
      {
      EMA2_SM = iCustom(NULL,0,"SMI_Helper",Period_Q, Period_R, Period_S, Signal,method,0,i);
      EMA2_HQ = iCustom(NULL,0,"SMI_Helper",Period_Q, Period_R, Period_S, Signal,method,1,i);
      SMI_Buffer[i]=100*(EMA2_SM/0.5/EMA2_HQ);

// Color Handling

      if(SMI_Buffer[i+1] >  SMI_Buffer[i])
      {
       SMI_BufferUP[i] = EMPTY_VALUE ;
       SMI_BufferFLAT[i] = EMPTY_VALUE ;
       SMI_BufferDOWN[i] = SMI_Buffer[i] ;
      }
      else if(SMI_Buffer[i+1] <  SMI_Buffer[i])
      {
       SMI_BufferDOWN[i] = EMPTY_VALUE ;
       SMI_BufferFLAT[i] = EMPTY_VALUE ;
       SMI_BufferUP[i] = SMI_Buffer[i] ;
      }
      else
      {
       SMI_BufferUP[i] = EMPTY_VALUE ;
       SMI_BufferDOWN[i] = EMPTY_VALUE ;
       SMI_BufferFLAT[i] = SMI_Buffer[i] ;
      }
      }

//---- TODO: add your code here

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

Comments