Author: Copyright � 2007, klot
Pearson2
Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicatorStandard Deviation indicator
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Pearson2
//+------------------------------------------------------------------+
//|                                                     #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 string symb0="EURUSD";
extern string symb1="GBPUSD";
//extern int Period1=PERIOD_H4;
extern    int N=20;
extern    int NrBars=500;
//---- indicator buffers
double Pirson[];
int per0;
int per1;

//+------------------------------------------------------------------+
//| 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;
  per0=Period();
  per1=Period();   
   //----
   for( int shift=NrBars-N-1; shift>=0; shift--) {

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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---