//+------------------------------------------------------------------+ //| iSpread.mq5 | //| A.V. Oreshkin | //| vk.com/mtforex | //+------------------------------------------------------------------+ #property copyright "A.V. Oreshkin" #property link "vk.com/mtforex" #property version "1.00" #property indicator_separate_window #property indicator_buffers 15 #property indicator_plots 7 #property indicator_label1 "SNT"; #property indicator_label2 "L1 UP"; #property indicator_label3 "L2 UP"; #property indicator_label4 "L3 UP"; #property indicator_label5 "L1 DN"; #property indicator_label6 "L2 DN"; #property indicator_label7 "L3 DN"; #property indicator_color1 clrAqua #property indicator_color2 clrRed #property indicator_color3 clrYellow #property indicator_color4 clrGreen #property indicator_color5 clrRed #property indicator_color6 clrYellow #property indicator_color7 clrGreen #property indicator_style1 STYLE_SOLID #property indicator_style2 STYLE_SOLID #property indicator_style3 STYLE_SOLID #property indicator_style4 STYLE_SOLID #property indicator_style5 STYLE_SOLID #property indicator_style6 STYLE_SOLID #property indicator_style7 STYLE_SOLID #property indicator_type1 DRAW_LINE #property indicator_type2 DRAW_LINE #property indicator_type3 DRAW_LINE #property indicator_type4 DRAW_LINE #property indicator_type5 DRAW_LINE #property indicator_type6 DRAW_LINE #property indicator_type7 DRAW_LINE #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 #property indicator_width4 1 #property indicator_width5 1 #property indicator_width6 1 #property indicator_width7 1 #property indicator_level1 0 #property indicator_level2 1 #property indicator_level3 -1 //+------------------------------------------------------------------+ //| enum MOVE | //+------------------------------------------------------------------+ enum MOVE { Subtract=1, //Difference Add=2, //Sum Multiply=3, //Product Divizion=4 //Ratio }; //+------------------------------------------------------------------+ //| enum DET | //+------------------------------------------------------------------+ enum DET { Returns=1, //The first difference DeTrend=2 //Detrend using a simple MA }; //+------------------------------------------------------------------+ //| enum LVL | //+------------------------------------------------------------------+ enum LVL { Norm=1, //Normalization to 0..1 with an offset MaxMin=2, //Levels of extrema //CKO=3 //Calculation of mean square deviation is not used. 1 - levels are narrowed and 2 - long calculation }; input datetime BeginTime = D'2013.01.01'; //Date to start input string Symbol1 = "GBPUSD"; //Symbol 1 input string Symbol2 = "EURUSD"; //Symbol 2 input MOVE Action = Divizion; //Action input bool Invert1 = false; //Reverse of symbol 1 input bool Invert2 = false; //Reverse of symbol 2 input double Pow1 = 1; //Power of symbol 1 input double Pow2 = 1; //Power of symbol 2 input double Multi1 = 1; //Multiplier of symbol 1 input double Multi2 = 1; //Multiplier of symbol 2 input bool Ln = false; //The logarithm input uint Average = 3; //Smoothing.Period input DET Algo = DeTrend; //Selecting an algorithm input uint Window = 288; //Period for the algorithm input bool Screen_Levels = true; //Show levels input LVL Method = Norm; //Levels calculation method input double Levels = 1; //Ratio of levels bool Error_Init=true; datetime BeginDate=0; double BF[], //The final array for the output PR1[],PR2[], //Arrays of initial data after mathematical processing PRA1[],PRA2[], //Arrays PR1 and PR2 smoothed by a MA CALC[], //Output here either after a detrend or after the first difference DTR[], //An array after detrend LG1[],LG2[], //An array for first differences max,min, //Extreme for normalization L1up[],L2up[],L3up[],L1dn[],L2dn[],L3dn[];//arrays for the levels //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { Error_Init=true; LOAD_DATA(); max=-10000;min=10000; IndicatorSetString(INDICATOR_SHORTNAME,NAME()); SetIndexBuffer(0,BF,INDICATOR_DATA); SetIndexBuffer(1,L1up,INDICATOR_DATA); SetIndexBuffer(2,L2up,INDICATOR_DATA); SetIndexBuffer(3,L3up,INDICATOR_DATA); SetIndexBuffer(4,L1dn,INDICATOR_DATA); SetIndexBuffer(5,L2dn,INDICATOR_DATA); SetIndexBuffer(6,L3dn,INDICATOR_DATA); SetIndexBuffer(7,PR1,INDICATOR_CALCULATIONS); SetIndexBuffer(8,PR2,INDICATOR_CALCULATIONS); SetIndexBuffer(9,PRA1,INDICATOR_CALCULATIONS); SetIndexBuffer(10,PRA2,INDICATOR_CALCULATIONS); SetIndexBuffer(11,CALC,INDICATOR_CALCULATIONS); SetIndexBuffer(12,DTR,INDICATOR_CALCULATIONS); SetIndexBuffer(13,LG1,INDICATOR_CALCULATIONS); SetIndexBuffer(14,LG2,INDICATOR_CALCULATIONS); //--- ArraySetAsSeries(BF,false); ArraySetAsSeries(PR1,false); ArraySetAsSeries(PR2,false); ArraySetAsSeries(PRA1,false); ArraySetAsSeries(PRA2,false); ArraySetAsSeries(CALC,false); ArraySetAsSeries(DTR,false); ArraySetAsSeries(LG1,false); ArraySetAsSeries(LG2,false); ArraySetAsSeries(L1up,false); ArraySetAsSeries(L2up,false); ArraySetAsSeries(L3up,false); ArraySetAsSeries(L1dn,false); ArraySetAsSeries(L2dn,false); ArraySetAsSeries(L3dn,false); //--- ZeroMemory(L1up); ZeroMemory(L2up); ZeroMemory(L3up); ZeroMemory(L1dn); ZeroMemory(L2dn); ZeroMemory(L3dn); //--- 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[]) { if(Error_Init) LOAD_DATA(); if(Error_Init) return(INIT_FAILED); //Initialization error double pr1[1],pr2[1]; int x1,x2; int limit=prev_calculated; if(limit>1) limit=limit-2; //--- step 1 - data preparation for(int pos=1+limit;pos1) for(int pos=1+limit;pos1) { for(int pos=1+limit;pos0) { for(int pos=1+limit;posmax) max=BF[pos]; if(BF[pos]