0
Views
0
Downloads
0
Favorites
iCor1
#property copyright "Integer"
#property link "https://www.mql5.com/ru/users/integer"
#property version "1.00"
#property indicator_separate_window
#property indicator_minimum -1
#property indicator_maximum 1
#property indicator_buffers 6
#property indicator_plots 1
//--- plot Label1
#property indicator_label1 "Label1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int period=14;
//--- indicator buffers
double Label1Buffer[];
double bxa[],bya[],bxy[],bx2[],by2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
SetIndexBuffer(1,bxa,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,bya,INDICATOR_CALCULATIONS);
SetIndexBuffer(3,bxy,INDICATOR_CALCULATIONS);
SetIndexBuffer(4,bx2,INDICATOR_CALCULATIONS);
SetIndexBuffer(5,by2,INDICATOR_CALCULATIONS);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
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[])
{
int start;
if(prev_calculated==0){
start=period-1;
bxa[start]=0;
bxa[start]=0;
bxy[start]=0;
bx2[start]=0;
by2[start]=0;
for(int i=start-period+1;i<=start;i++){
bxa[start]+=close[i];
bya[start]+=0.01*i;
bxy[start]+=close[i]*0.01*i;
bx2[start]+=close[i]*close[i];
by2[start]+=0.01*i*0.01*i;
}
bxa[start]/=period;
bya[start]/=period;
start++;
}
else{
start=prev_calculated-1;
}
for(int i=start;i<rates_total;i++){
bxa[i]=bxa[i-1]+(close[i]-close[i-period])/period;
bya[i]=bya[i-1]+0.01;
bxy[i]=bxy[i-1]-close[i-period]*0.01*(i-period)+close[i]*0.01*(i);
bx2[i]=bx2[i-1]-close[i-period]*close[i-period]+close[i]*close[i];
by2[i]=by2[i-1]-0.01*(i-period)*0.01*(i-period)+0.01*i*0.01*i;
double ya2=bya[i]*bya[i];
double xa2=bxa[i]*bxa[i];
double xya=bxa[i]*bya[i];
double sy2=-ya2*period+by2[i];
double sx2=-xa2*period+bx2[i];
double cor=(bxy[i]-xya*period)/MathSqrt(sx2*sy2);
Label1Buffer[i]=cor;
}
return(rates_total);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---