Author: Alexandr Sokolov
Price Data Components
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
CBS
ÿþ#property copyright "Alexandr Sokolov"

#property link      "https://www.facebook.com/sokolov6897"

#property version   "1.00"

#property description "The correlation between symbols"

#property strict

#property indicator_separate_window

#property indicator_buffers 2

//--- E>4=K5 ?0@0<5B@K ---------------------------------------------

input string symbol_1 = "GBPUSD"; //Symbol !1

input string symbol_2 = "EURUSD"; //Symbol !2

//--- 1JO2;O5< 1CD5@K ----------------------------------------------

double Symbol_1[], Symbol_2[]; //;O E@0=5=8O 7=0G5=89 @07=8FK <564C F5=0<8 Open 8 Close A8<2>;>2 !1 8 !2

//--- 1JO2;O5< AB0B8G5A:85 ?5@5<5==K5 ------------------------------

static int coef_s1, coef_s2; //>MDD8F85=B C<=>65=8O :>B8@>2>:

//-------------------------------------------------------------------------------------------------

int OnInit()

  {

  //--- #AB0=>28< :>;8G5AB2> 45AOB8G=KE 7=0:>2 ?>A;5 70?OB>9 --------

   IndicatorDigits(0);

  //--- Symbol_1 ----------------------------------------------------

   SetIndexBuffer(0,Symbol_1);                       //8=8O !0 1C45B >B>1@060BL 7=0G5=8O 87 1CD5@0 Symbol_1

   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,clrBlue); //04048< B8?, AB8;L, H8@8=C 8 F25B 4;O ;8=88 !0

   SetIndexLabel(0,symbol_1);                        //@>?8H5< >?8A0=85 4;O ;8=88 !0, :>B>@>5 1C45B ?>O2;OBAO ?@8 =02545=88 :C@A>@0 <KH:8 =0 =5Q

  //--- Symbol_2 ----------------------------------------------------

   SetIndexBuffer(1,Symbol_2);                      //;O ;8=88 !1 2AQ 7040QBAO 0=0;>38G=K< >1@07>< :0: 4;O ;8=88 !0

   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2,clrRed);

   SetIndexLabel(1,symbol_2);

  //--- 064><C A8<2>;C ?@8A2>8< :>MDD8F85=B C<=>65=8O :>B8@>2>: ----

   coef_s1 = Coefficient((int)SymbolInfoInteger(symbol_1,SYMBOL_DIGITS)); //;O A8<2>;0 !1

   coef_s2 = Coefficient((int)SymbolInfoInteger(symbol_2,SYMBOL_DIGITS)); //;O A8<2>;0 !2

  //--- @>25@8< :>@@5:B=>ABL/ACI5AB2>20=85 2254Q==KE A8<2>;>2 ------

   bool s1 = false, s2 = false;

   int total_symbols = SymbolsTotal(false);

   for(int i = 0; i <= total_symbols; i++)

     {

      if(SymbolName(i,false) == symbol_1) {s1 = true;};

      if(SymbolName(i,false) == symbol_2) {s2 = true;};

     };

  //--- A;8 2A5 A8<2>;K :>@@5:B=> 22545=K, B> 8=8F80;870F8O ?@>94QB CA?5H=>

   ENUM_INIT_RETCODE initialization;

   if(s1 == true && s2 == true)

     {

      initialization = INIT_SUCCEEDED;

     }

   else

     {

      initialization = INIT_FAILED;

     //--- #254><8< 2 GQ< 65 >H81:0 -------------

      if(s1 == false) {Alert(symbol_1," not found (Symbol !1)");};

      if(s2 == false) {Alert(symbol_2," not found (Symbol !2)");};

     };

  //-----------------------------------------------------------------

   return(initialization);

  }

//-------------------------------------------------------------------------------------------------

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 bar_s1 = Bars(symbol_1,PERIOD_CURRENT); //>;CG05< :>;8G5AB2> 10@>2 ?5@2>3> A8<2>;0

   int bar_s2 = Bars(symbol_2,PERIOD_CURRENT); //>;CG05< :>;8G5AB2> 10@>2 2B>@>3> A8<2>;0

   int limit = MathMin(bar_s1,bar_s2) - prev_calculated; if(limit == 0) {limit = 1;}; //#AB0=02;8205< ;8<8B 4;O F8:;0

   for(int i = 0; i < limit; i++) //040Q< CA;>28O F8:;0

     {//--- >;CG05< F5=K >B:@KB8O 8 70:@KB8O G5@57 <C28=38 8 C<=>605< @07=8FC =0 :>MDD8F85=B

      Symbol_1[i] = (iMA(symbol_1,PERIOD_CURRENT,1,0,MODE_SMA,PRICE_CLOSE,i) - iMA(symbol_1,PERIOD_CURRENT,1,0,MODE_SMA,PRICE_OPEN,i)) * coef_s1;

      Symbol_2[i] = (iMA(symbol_2,PERIOD_CURRENT,1,0,MODE_SMA,PRICE_CLOSE,i) - iMA(symbol_2,PERIOD_CURRENT,1,0,MODE_SMA,PRICE_OPEN,i)) * coef_s2;

     };

  //-----------------------------------------------------------------

   return(MathMin(bar_s1,bar_s2));

  }

//--- $C=:F8O 4;O ?@8A2>5=8O :>MDD8F85=B0 C<=>65=8O :>B8@>2>: -------------------------------------

int Coefficient(int digits)

  {

   int coefficient = 1;

   for(int i = 1; i <= digits; i++)

     {

      coefficient = coefficient * 10;

     };

  //-----------------------------------------------------------------

   return(coefficient);

  }

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 ---