Spread_Of_Symbols

0 Views
0 Downloads
0 Favorites
Spread_Of_Symbols
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#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 string symbol1="AUDUSD";
input string symbol2="NZDUSD";
input double mass_of_symbol1=1;
input double mass_of_symbol2=1;


int i,r1,r2,j;
double S,prs,k1,k2,d1,d2;
//--- indicator buffers
double        ind1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ind1,INDICATOR_DATA);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   ArraySetAsSeries(time,true);ArraySetAsSeries(open,true);ArraySetAsSeries(high,true);ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);ArraySetAsSeries(tick_volume,true);ArraySetAsSeries(volume,true);ArraySetAsSeries(spread,true);

   ArraySetAsSeries(ind1,true);
   MqlRates rates1[]; ArraySetAsSeries(rates1,true);
   MqlRates rates2[]; ArraySetAsSeries(rates2,true);

   if(prev_calculated<rates_total)
     {
      for(i=0;i<rates_total;i++)
        {
         CopyRates(symbol1,0,time[i],1,rates1);
         CopyRates(symbol2,0,time[i],1,rates2);
         ind1[i]=mass_of_symbol1*rates1[0].close-mass_of_symbol2*rates2[0].close;
        }
     }



//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

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