Author: Copyright © 2006, Kalenzo

This script is a custom technical analysis indicator designed for the MetaTrader 5 platform. It combines several advanced mathematical concepts—specifically momentum, moving averages, and relative strength—to provide a visual representation of market trend direction and potential reversal points.

Core Logic Overview

The primary purpose of this indicator is to filter out "market noise" and identify the underlying strength of a price movement. Instead of simply showing raw price changes, it uses a multi-layered smoothing process to determine whether the current momentum is leaning towards a bullish (positive) or bearish (negative) direction.

How the Logic Works

The script processes data through four distinct stages:

  1. Dynamic Price Smoothing: The indicator first identifies the "smoothed" price using a customizable Moving Average method. This ensures that minor, erratic price fluctuations do not cause false signals. It allows users to choose between various calculation types (like Exponential or Simple moving averages).

  2. Momentum Analysis: Once the smoothed price is established, the script calculates the "Momentum" of that movement. It looks at the rate of change in the smoothed price over a specific period. If the price is moving up faster than before, the momentum is considered positive; if it is slowing down or dropping, it is negative.

  3. Positive and Negative Accumulation: The script separates these movements into two distinct buckets:

    • Positive Sums: It tracks only the upward momentum gains.
    • Negative Sums: It tracks only the downward momentum losses. By maintaining these separate totals, the indicator can compare the "weight" of the bulls versus the "weight" of the bears.
  4. Relative Strength Calculation (RSI): The final result is a specialized Relative Strength Index (RSI). The script calculates a ratio between the accumulated positive momentum and the negative momentum. This ratio is then mapped to a scale (typically centered around 50) to produce a visual line on your chart.

Visual Indicators

The script provides three primary visual outputs for the trader:

  • The Main Indicator Line: A dynamic line that oscillates based on the calculated relative strength.
  • Color Coding: The indicator changes color based on where the RSI sits relative to specific thresholds (High, Middle, and Low levels). These colors provide an immediate visual cue regarding whether the market is overbought, oversold, or in a neutral state.
    • Green/Forest tones typically indicate bullish strength.
    • Red/Pink tones typically indicate bearish strength.
    • Gray/Neutral tones indicate a balanced or sideways market.
  • Trigger Line: A secondary smoothed line (the "Trigger") that tracks the RSI itself. This is often used by traders to identify specific moments where the trend might be shifting or confirming.

Summary for the User

In simple terms, this script doesn't just tell you what the price is doing now; it calculates how much "force" is behind the current move. By balancing the history of upward pushes against downward pushes, it creates a cleaner, more reliable signal of market sentiment than standard indicators might provide alone.

8 Views
0 Downloads
0 Favorites
RSIOMA_v1
ÿþ//+---------------------------------------------------------------------+

//|                                                          RSIOMA.mq5 | 

//|                                           Copyright © 2006, Kalenzo | 

//|                bartlomiej.gorski@gmail.com, http://www.fxservice.eu | 

//+---------------------------------------------------------------------+ 

//| ;O @01>BK  8=48:0B>@0  A;54C5B  ?>;>68BL D09; SmoothAlgorithms.mqh |

//| 2 ?0?:C (48@5:B>@8N): :0B0;>3_40==KE_B5@<8=0;0\\MQL5\Include        |

//+---------------------------------------------------------------------+

#property copyright "Copyright © 2006, Kalenzo"

#property link "http://www.fxservice.eu"

//---- =><5@ 25@A88 8=48:0B>@0

#property version   "1.10"

//---- >B@8A>2:0 8=48:0B>@0 2 >B45;L=>< >:=5

#property indicator_separate_window

//---- :>;8G5AB2> 8=48:0B>@=KE 1CD5@>2 3

#property indicator_buffers 3 

//---- 8A?>;L7>20=> 420 3@0D8G5A:8E ?>AB@>5=8O

#property indicator_plots   2

//+-----------------------------------+

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 1 |

//+-----------------------------------+

//---- >B@8A>2:0 8=48:0B>@0 2 2845 G5BK@QEF25B=>9 38AB>3@0<<K

#property indicator_type1 DRAW_COLOR_HISTOGRAM

//---- 2 :0G5AB25 F25B>2 ?OB8F25B=>9 38AB>3@0<<K 8A?>;L7>20=K

#property indicator_color1 clrDeepPink,clrPurple,clrGray,clrForestGreen,clrLawnGreen

//---- ;8=8O 8=48:0B>@0 - A?;>H=0O

#property indicator_style1 STYLE_SOLID

//---- B>;I8=0 ;8=88 8=48:0B>@0 @02=0 2

#property indicator_width1 2

//---- >B>1@065=85 <5B:8 8=48:0B>@0

#property indicator_label1  "RSIOMA"

//+-----------------------------------+

//|  0@0<5B@K >B@8A>2:8 8=48:0B>@0 2 |

//+-----------------------------------+

//---- >B@8A>2:0 8=48:0B>@0 2 2 2845 ;8=88

#property indicator_type2   DRAW_LINE

//---- 2 :0G5AB25 F25B0 <54256L59 ;8=88 8=48:0B>@0 8A?>;L7>20= A8=89 F25B

#property indicator_color2  clrDarkViolet

//---- ;8=8O 8=48:0B>@0 2 - =5?@5@K2=0O :@820O

#property indicator_style2  STYLE_SOLID

//---- B>;I8=0 ;8=88 8=48:0B>@0 2 @02=0 1

#property indicator_width2  1

//---- >B>1@065=85 <54256L59 <5B:8 8=48:0B>@0

#property indicator_label2  "Trigger"



//+-----------------------------------+

//|  ?8A0=85 :;0AA0 CXMA             |

//+-----------------------------------+

#include <SmoothAlgorithms.mqh> 

//+-----------------------------------+



//---- >1JO2;5=85 ?5@5<5==KE :;0AA0 CXMA 87 D09;0 SmoothAlgorithms.mqh

CXMA XMA1,XMA2,XMA3,XMA4;

//---- >1JO2;5=85 ?5@5<5==KE :;0AA0 CMomentum 87 D09;0 SmoothAlgorithms.mqh

CMomentum Mom;

//+-----------------------------------+

//|  >1JO2;5=85 ?5@5G8A;5=89          |

//+-----------------------------------+

enum Applied_price_ //"8? :>=AB0=BK

  {

   PRICE_CLOSE_ = 1,     //Close

   PRICE_OPEN_,          //Open

   PRICE_HIGH_,          //High

   PRICE_LOW_,           //Low

   PRICE_MEDIAN_,        //Median Price (HL/2)

   PRICE_TYPICAL_,       //Typical Price (HLC/3)

   PRICE_WEIGHTED_,      //Weighted Close (HLCC/4)

   PRICE_SIMPL_,         //Simpl Price (OC/2)

   PRICE_QUARTER_,       //Quarted Price (HLOC/4) 

   PRICE_TRENDFOLLOW0_,  //TrendFollow_1 Price 

   PRICE_TRENDFOLLOW1_,  //TrendFollow_2 Price

   PRICE_DEMARK_         //Demark Price

  };

//+-----------------------------------+

//|  >1JO2;5=85 ?5@5G8A;5=89          |

//+-----------------------------------+

/*enum Smooth_Method - ?5@5G8A;5=85 >1JO2;5=> 2 D09;5 SmoothAlgorithms.mqh

  {

   MODE_SMA_,  //SMA

   MODE_EMA_,  //EMA

   MODE_SMMA_, //SMMA

   MODE_LWMA_, //LWMA

   MODE_JJMA,  //JJMA

   MODE_JurX,  //JurX

   MODE_ParMA, //ParMA

   MODE_T3,    //T3

   MODE_VIDYA, //VIDYA

   MODE_AMA,   //AMA

  }; */

//+-----------------------------------+

//|  %+  " + "      |

//+-----------------------------------+

input Smooth_Method RSIOMA_Method=MODE_EMA_;  // 5B>4 CA@54=5=8O RSIOMA

input uint RSIOMA=14;                         // ;C18=0 CA@54=5=8O RSIOMA

input int RSIOMAPhase=15;                     // 0@0<5B@ CA@54=5=8O RSIOMA

input Smooth_Method MARSIOMA_Method=MODE_EMA_;// 5B>4 CA@54=5=8O MARSIOMA

input uint MARSIOMA=21;                       // ;C18=0 CA@54=5=8O RSIOMA

input int MARSIOMAPhase=15;                   // 0@0<5B@ CA@54=5=8O RSIOMA

input uint MomPeriod=1;                       // 5@8>4 ><5=BC<0

input Applied_price_ IPC=PRICE_CLOSE_;        // &5=>20O :>=AB0=B0

input int HighLevel=+20;                      // 5@E=89 C@>25=L A@010BK20=8O

input int MiddleLevel=0;                      // !5@548=0 480?07>=0

input int LowLevel=-20;                       // 86=89 C@>25=L A@010BK20=8O

input int Shift=0;                            // !4283 8=48:0B>@0 ?> 3>@87>=B0;8 2 10@0E

//+-----------------------------------+



//---- >1JO2;5=85 48=0<8G5A:8E <0AA82>2, :>B>@K5 1C4CB 2 

// 40;L=59H5< 8A?>;L7>20=K 2 :0G5AB25 8=48:0B>@=KE 1CD5@>2

double IndBuffer[],ColorIndBuffer[],TriggerBuffer[];



//---- 1JO2;5=85 F5;KE ?5@5<5==KE =0G0;0 >BAGQB0 40==KE

int min_rates_total,min_rates_1,min_rates_2,min_rates_3;

//+------------------------------------------------------------------+   

//| RSIOMA indicator initialization function                         | 

//+------------------------------------------------------------------+ 

void OnInit()

  {

//---- =8F80;870F8O ?5@5<5==KE =0G0;0 >BAGQB0 40==KE

   min_rates_1=GetStartBars(RSIOMA_Method,RSIOMA,RSIOMAPhase);

   min_rates_2=int(min_rates_1+MomPeriod);

   min_rates_3=int(min_rates_2+RSIOMA+1);

   min_rates_total=min_rates_3+GetStartBars(MARSIOMA_Method,MARSIOMA,RSIOMAPhase);



//---- CAB0=>2:0 0;5@B>2 =0 =54>?CAB8<K5 7=0G5=8O 2=5H=8E ?5@5<5==KE

   XMA1.XMALengthCheck("RSIOMA",RSIOMA);

   XMA1.XMAPhaseCheck("RSIOMAPhase",RSIOMAPhase,RSIOMA_Method);

//---- CAB0=>2:0 0;5@B>2 =0 =54>?CAB8<K5 7=0G5=8O 2=5H=8E ?5@5<5==KE

   XMA1.XMALengthCheck("MARSIOMA",MARSIOMA);

   XMA1.XMAPhaseCheck("RSIOMAPhase",RSIOMAPhase,MARSIOMA_Method);



//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 IndBuffer 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(0,IndBuffer,INDICATOR_DATA);

//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 2 F25B>2>9, 8=45:A=K9 1CD5@   

   SetIndexBuffer(1,ColorIndBuffer,INDICATOR_COLOR_INDEX);

//---- ?@52@0I5=85 48=0<8G5A:>3> <0AA820 TriggerBuffer 2 8=48:0B>@=K9 1CD5@

   SetIndexBuffer(2,TriggerBuffer,INDICATOR_DATA);



//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAGQB0 >B@8A>2:8 8=48:0B>@0

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 2 ?> 3>@87>=B0;8 =0 Shift

   PlotIndexSetInteger(0,PLOT_SHIFT,Shift);



//---- >ACI5AB2;5=85 A42830 =0G0;0 >BAG5B0 >B@8A>2:8 8=48:0B>@0 2 =0 min_rates_total

   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);

//---- CAB0=>2:0 7=0G5=89 8=48:0B>@0, :>B>@K5 =5 1C4CB 2848<K =0 3@0D8:5

   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE);

//---- >ACI5AB2;5=85 A42830 8=48:0B>@0 2 ?> 3>@87>=B0;8 =0 Shift

   PlotIndexSetInteger(1,PLOT_SHIFT,Shift);



//--- A>740=85 8<5=8 4;O >B>1@065=8O 2 >B45;L=>< ?>4>:=5 8 2> 2A?;K20NI59 ?>4A:07:5

   IndicatorSetString(INDICATOR_SHORTNAME,"RSIOMA");



//--- >?@545;5=85 B>G=>AB8 >B>1@065=8O 7=0G5=89 8=48:0B>@0

   IndicatorSetInteger(INDICATOR_DIGITS,0);



//---- :>;8G5AB2>  3>@87>=B0;L=KE C@>2=59 8=48:0B>@0 3   

   IndicatorSetInteger(INDICATOR_LEVELS,3);

//---- 7=0G5=8O 3>@87>=B0;L=KE C@>2=59 8=48:0B>@0   

   IndicatorSetDouble(INDICATOR_LEVELVALUE,0,HighLevel);

   IndicatorSetDouble(INDICATOR_LEVELVALUE,1,MiddleLevel);

   IndicatorSetDouble(INDICATOR_LEVELVALUE,2,LowLevel);

//---- 2 :0G5AB25 F25B>2 ;8=89 3>@87>=B0;L=KE C@>2=59 8A?>;L7>20=K A5@K9 8 @>7>2K9 F25B0  

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrPurple);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,1,clrGray);

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,2,clrPurple);

//---- 2 ;8=88 3>@87>=B0;L=>3> C@>2=O 8A?>;L7>20= :>@>B:89 HB@8E-?C=:B8@  

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,0,STYLE_DASHDOTDOT);

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,1,STYLE_DASHDOTDOT);

   IndicatorSetInteger(INDICATOR_LEVELSTYLE,2,STYLE_DASHDOTDOT);

//---- 7025@H5=85 8=8F80;870F88

  }

//+------------------------------------------------------------------+ 

//| RSIOMA iteration function                                        | 

//+------------------------------------------------------------------+ 

int OnCalculate(

                const int rates_total,    // :>;8G5AB2> 8AB>@88 2 10@0E =0 B5:CI5< B8:5

                const int prev_calculated,// :>;8G5AB2> 8AB>@88 2 10@0E =0 ?@54K4CI5< B8:5

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[]

                )

  {

//---- ?@>25@:0 :>;8G5AB20 10@>2 =0 4>AB0B>G=>ABL 4;O @0AGQB0

   if(rates_total<min_rates_total) return(0);



//---- 1JO2;5=85 ?5@5<5==KE A ?;020NI59 B>G:>9  

   double price,x1xma,rel,RSI,positive,negative,sump,sumn,res;

   static double prev_positive,prev_negative;

//---- 1JO2;5=85 F5;KE ?5@5<5==KE 8 ?>;CG5=85 C65 ?>AG8B0==KE 10@>2

   int first,bar,clr;



//---- @0AGQB AB0@B>2>3> =><5@0 first 4;O F8:;0 ?5@5AGQB0 10@>2

   if(prev_calculated>rates_total || prev_calculated<=0) // ?@>25@:0 =0 ?5@2K9 AB0@B @0AGQB0 8=48:0B>@0

     {

      first=0; // AB0@B>2K9 =><5@ 4;O @0AGQB0 2A5E 10@>2

     }

   else first=prev_calculated-1; // AB0@B>2K9 =><5@ 4;O @0AGQB0 =>2KE 10@>2



//---- A=>2=>9 F8:; @0AGQB0 8=48:0B>@0

   for(bar=first; bar<rates_total && !IsStopped(); bar++)

     {

      price=PriceSeries(IPC,bar,open,low,high,close);

      x1xma=XMA1.XMASeries(0,prev_calculated,rates_total,RSIOMA_Method,RSIOMAPhase,RSIOMA,price,bar,false);

      rel=Mom.MomentumSeries(min_rates_1,prev_calculated,rates_total,MomPeriod,x1xma,bar,false);



      sump=RSIOMA*XMA2.XMASeries(min_rates_2,prev_calculated,rates_total,MODE_SMA_,0,RSIOMA,+MathMax(rel,0),bar,false);

      sumn=RSIOMA*XMA3.XMASeries(min_rates_2,prev_calculated,rates_total,MODE_SMA_,0,RSIOMA,-MathMin(rel,0),bar,false);



      if(bar==min_rates_3)

        {

         prev_positive=0.0;

         prev_negative=0.0;

        }



      positive=(prev_positive*(RSIOMA-1)+sump)/RSIOMA;

      negative=(prev_negative*(RSIOMA-1)+sumn)/RSIOMA;

      

      if(negative) res=1.0+positive/negative;

      else res=2.0;



      if(res) RSI=50-100/res;

      else RSI=0.0;

      IndBuffer[bar]=RSI;



      TriggerBuffer[bar]=XMA4.XMASeries(min_rates_3,prev_calculated,rates_total,MARSIOMA_Method,MARSIOMAPhase,MARSIOMA,RSI,bar,false);



      if(bar<rates_total-1)

        {

         prev_positive=positive;

         prev_negative=negative;

        }



      clr=2;

      if(RSI>MiddleLevel) {if(RSI>HighLevel) clr=4; else clr=3;}

      if(RSI<MiddleLevel) {if(RSI<LowLevel)  clr=0; else clr=1;}

      ColorIndBuffer[bar]=clr;

     }

//----     

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments