Author: Copyright � 2007, klot
#-Pirson

This technical indicator is designed to measure the relationship between the current price of an asset and its moving average over a specific period. In simpler terms, it evaluates how closely the market price is "following" or aligning with its historical trend, providing a visual representation of price momentum and correlation.

How the Logic Works

The script operates by analyzing the history of the market to determine the strength of the connection between two key data points: the actual closing prices and a smoothed moving average. Here is a breakdown of the process:

  • Trend Smoothing: The tool first establishes a "baseline" by calculating a Simple Moving Average (SMA). This represents the general direction of the price over a user-defined number of bars (the default being 20).
  • Correlation Analysis: The script then looks at how much the actual closing prices deviate from this moving average. It calculates a mathematical correlation—specifically, it measures how consistently the price moves in relation to its own trend line.
  • Volatility Adjustment: To ensure the data is accurate and not distorted by sudden, extreme market swings, the tool incorporates "Standard Deviation." This acts as a stabilizer, adjusting the calculation so that the resulting value reflects a true correlation rather than just temporary noise.
  • The Final Output: The final result is expressed as a numerical value displayed in a separate window on your chart.

Practical Interpretation

By observing this indicator, traders can see how "in sync" the current price action is with the underlying trend. When the values are consistent, it suggests that the current price movement is well-aligned with the established trend. Conversely, significant shifts in the indicator's value can highlight moments where the price is beginning to decouple from its average path, potentially signaling a change in market dynamics.

Indicators Used
Moving average indicatorStandard Deviation indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
#-Pirson
//+------------------------------------------------------------------+
//|                                                     #DT-Pirsonq4 |
//|                                           Copyright © 2007, klot |
//|                                                     klot@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, klot"
#property link      "klot@mail.ru"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Aqua
#property indicator_level1 0.0
extern    int N=20;
//---- indicator buffers
double Pirson[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_SECTION);
//---- indicator buffers mapping
   SetIndexBuffer(0,Pirson);
   SetIndexEmptyValue(0,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   double X,Y,Sx,Sy;
   double sum=0.0;
   //----
   for( int shift=Bars-N-1; shift>=0; shift--) {

      X=iMA(NULL,0,N,0,MODE_SMA,PRICE_CLOSE,shift);
      Y=iMA(NULL,0,N,0,MODE_SMA,PRICE_CLOSE,shift+1);
      //----
      sum=0;
      for( int i=N-1; i>=0; i--) {
         sum+=(Close[shift+i]-X)*(Close[shift+i+1]-Y);
      }
      //---
      Sx=iStdDev(NULL,0,N,0,MODE_SMA,PRICE_CLOSE,shift);
      Sy=iStdDev(NULL,0,N,0,MODE_SMA,PRICE_CLOSE,shift+1);
      //---
      Pirson[shift]=sum/((N-1)*Sx*Sy);
    }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments