Author: Copyright � 2006, Eli hayun
MA rsi

This custom technical indicator is designed to provide a visual representation of market momentum by combining two popular trading tools: the Moving Average (MA) and the Relative Strength Index (RSI). Instead of showing these indicators as separate lines, this script intelligently splits the Moving Average into two distinct colors based on specific market conditions.

How the Logic Works

The indicator operates by continuously scanning your price data and performing a three-step calculation:

  1. Trend Identification (Moving Average): The script first calculates a Moving Average, which serves as a "smooth" representation of the current price. This helps filter out minor market noise to show the broader direction of the trend.

  2. Momentum Measurement (RSI): Simultaneously, the script calculates the Relative Strength Index (RSI). This is a momentum oscillator that measures whether an asset is being overbought or oversold, or simply which direction the current "strength" of the price is moving.

  3. Dynamic Filtering: This is where the unique logic happens. The script looks at the RSI value and compares it against a specific threshold (the "Level").

    • Condition A: If the momentum (RSI) is equal to or greater than your chosen level, the Moving Average is displayed in Blue.
    • Condition B: If the momentum (RSI) falls below that level, the Moving Average is displayed in Red.

Practical Application for the User

For a trader viewing this on a chart, the indicator acts as a visual confirmation tool. Rather than seeing a single moving average line, you see a color-changing trend line.

When the line turns Blue, it signals that the current price momentum is strong enough to meet your specified criteria. When it switches to Red, it signals that the momentum has weakened or dipped below your defined threshold. This allows you to quickly identify shifts in market sentiment and trend strength at a single glance without having to monitor two separate sub-windows on your screen.

Indicators Used
Moving average indicatorRelative strength index
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
MA rsi
//+------------------------------------------------------------------+
//|                                                       MA rsi.mq4 |
//|                                      Copyright © 2006, Eli hayun |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Eli hayun"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int       maPeriod=50;
extern int       maMethod=MODE_EMA;
extern int       maPrice=PRICE_CLOSE;
extern int       rsiPeriod=40;
extern int       rsiLevel=50;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   int limit;
   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;
//---- main loop
   for(int i=0; i<limit; i++)
     {
         double ma = iMA(NULL,0,maPeriod, 0, maMethod, maPrice, i);
         double rsi= iRSI(NULL, 0, rsiPeriod, maPrice, i);
         if (rsi >= rsiLevel)
            ExtMapBuffer1[i] = ma;
         else
            ExtMapBuffer2[i] = ma;
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments