//+------------------------------------------------------------------+
//|                                               TestCopyArray3.mq5 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright "MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot TSIsCD
#property indicator_label1  "Relation"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Orange
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

input int InpDepth = 1500;
input bool InpAlign = true;
input ENUM_TIMEFRAMES InpTimePeriod = PERIOD_CURRENT;
input string InpExpression = "2 ^ (1 + EURUSD.m) + EURUSD.m / 3.5 * GBPUSD.m";

double         IndiBuffer[];


int Handle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
 
   SetIndexBuffer(0,IndiBuffer,INDICATOR_DATA);
 
   //Handle=iCustom(_Symbol,PERIOD_CURRENT,"TSIs",r,s,sp,sm);
   
    Handle=iCustom(NULL,0,"Relation",InpDepth,InpAlign,InpTimePeriod,InpExpression);
  
   if(Handle==INVALID_HANDLE)
     {
      Print("Invalid handle ",GetLastError());
      return(INIT_FAILED);
     }

   return(INIT_SUCCEEDED);
   
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,0);
   IndicatorSetInteger(INDICATOR_DIGITS,2);      
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,    // size of the price[] array
                const int prev_calculated,// number of bars processed at the previous call
                const int begin,          // where the significant data start from
                const double &price[]     // array for calculation
                )
  {

   static bool error=true;
   int start;
   if(prev_calculated==0)
     {
      error=true;
     }
   if(error)
     {
      start=begin+1;
      error=false;
     }
   else
     {
      start=prev_calculated-1;
     }

   if(CopyBuffer(Handle,0,0,InpDepth,IndiBuffer)==-1)
     {
      error=true;
      return(0);
     }
   
   return(rates_total);
  }
//+------------------------------------------------------------------+
