Ergodic_Oscillator

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
Ergodic_Oscillator

The Ergodic Oscillator is a technical analysis tool designed to help traders identify momentum and potential turning points in the market by smoothing out price noise. Rather than looking at raw price action directly, this script processes data through multiple layers of calculation to provide a clearer picture of the underlying market trend.

How the Logic Works

The script functions by pulling data from an external source and refining it through three distinct stages:

1. The Foundation (Base Data) The tool begins by calculating a primary movement value based on the "TSI-Osc" (True Strength Index Oscillator) logic. This provides the raw momentum of the market, capturing how strongly the price is moving in a specific direction over a set period.

2. The Ergodic Component (Primary Smoothing) Once the base momentum is established, the script applies an Exponential Moving Average (EMA) to that data. This step is crucial because it filters out "market noise"—the small, erratic price fluctuations that can often trigger false signals. By using an exponential average, the tool gives more weight to recent price action while still maintaining a smooth, readable curve.

3. The Signal Component (Secondary Smoothing) To provide the most refined view possible, the script performs one final smoothing operation. It takes the result of the previous step and applies a second Exponential Moving Average. This produces a secondary "Signal" line.

How to Interpret the Results

The indicator visualizes these calculations in a separate window on your chart, displaying two distinct lines:

  • The Ergodic Line: This is your primary trend indicator. It shows the smoothed momentum of the market.
  • The Signal Line: This acts as a secondary reference point.

By observing the relationship between these two lines, traders can look for "crossovers." When the Ergodic line crosses the Signal line, it often suggests a shift in momentum. The inclusion of predefined horizontal levels (such as 20 and -20) helps users identify periods where the market might be overextended or showing significant strength/weakness.

In essence, this script is designed to take complex, volatile price data and "distill" it into two smooth lines that make it easier to visualize the current trend and potential shifts in market energy.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
Ergodic_Oscillator
  //+----------------------------------------------------------------+
//|                                           Ergodic Oscillator.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 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_level1 0
#property indicator_level2 20
#property indicator_level3 -20
//---- input parameters
extern int First_R = 8;
extern int Second_S = 5;
extern int SignalPeriod = 5;
extern int Mode_Smooth = 1;
//---- buffers
double ErgodicBuffer[];
double Signal_Buffer[];
double TSI_Siganl_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(3);
//----
   SetIndexBuffer(2, TSI_Siganl_Buffer);
//----
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, ErgodicBuffer);
   SetIndexLabel(0, "Ergodic");
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, Signal_Buffer);
   SetIndexLabel(1, "Signal");
   IndicatorShortName("ErgodicOsc"+"("+First_R+","+Second_S+","+SignalPeriod+")");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars = IndicatorCounted();
   int limit, i;
   limit = Bars - counted_bars - 1;
   for(i = limit; i >= 0; i--)
     {
       TSI_Siganl_Buffer[i] = iCustom(NULL, 0, "TSI-Osc", First_R, Second_S, 
                                      SignalPeriod, Mode_Smooth, 1, i);
     }
//----
   for(i = limit; i >= 0; i--)
     {
       ErgodicBuffer[i] = iMAOnArray(TSI_Siganl_Buffer, 0, 5, 0, MODE_EMA, i);
     }
//----
   for(i = limit; i >= 0; i--)
     {
       Signal_Buffer[i] = iMAOnArray(ErgodicBuffer, 0, 5, 0, MODE_EMA, i);
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments