//+------------------------------------------------------------------+
//|                                   Meta COT Absolute Position.mq4 |
//|   Copyright © 2009, C-4 (Vasiliy Sokolov, Russia, St.-Petersburg,|
//|                                      2009), All Rights Reserved. |
//|                                                   vs-box@mail.ru |
//+------------------------------------------------------------------+

// Показывает абсолютные позиции трейдеров.

#property copyright "Copyright © 2009, C-4 (Vasiliy Sokolov, SPb), All Rights Reserved."
#property link      "vs-box@mail.ru"

#property indicator_separate_window
#property  indicator_buffers 7
#property  indicator_color1  Green
#property  indicator_color2  Blue
#property  indicator_color3  SkyBlue
#property  indicator_color4  IndianRed
#property  indicator_color5  Red
#property  indicator_color6  Silver
#property  indicator_color7  SlateGray

int period=52;
int movement_index=6;
extern bool Show_Noncomm_Long=false;
extern bool Show_Noncomm_Short=false;
extern bool Show_Operators_Long=false;
extern bool Show_Operators_Short=false;
extern bool Show_Nonrep_Long=false;
extern bool Show_Nonrep_Short=true;
extern bool Show_OI=true;

double i_open_interest[];
double i_noncomm_long[];
double i_noncomm_short[];
double i_operators_long[];
double i_operators_short[];
double i_nonrep_long[];
double i_nonrep_short[];

#include <cotlib.mq4>

int init()
{
   if(init_data()==false)error=true;
   if(error==false)load_data();
   if(error==false)count_data();
   SetParam();
   return 0;
}

int start()
{
   if(error==true)Print("Не удалось загрузить данные. Дальнейшая работа невозможна");
   DrowData();
   return 0;
}

void SetParam()
{
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexStyle(6,DRAW_LINE);
   IndicatorDigits(0);
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(3,0.0);
   SetIndexEmptyValue(4,0.0);
   SetIndexEmptyValue(5,0.0);
   SetIndexEmptyValue(6,0.0);
   if(load_cot_file==true)IndicatorShortName(StringConcatenate("Meta COT Absolute Pos.: ",str_trim(cot_file)));
   else IndicatorShortName(StringConcatenate("Meta COT Absolute Pos.: ",name));
   if(Show_OI==true){
      SetIndexBuffer(0,i_open_interest);
      SetIndexLabel(0, "Open Interest");
   }
   if(Show_Noncomm_Long==true){
      SetIndexBuffer(1,i_noncomm_long);
      SetIndexLabel(1,"Noncommercial Long");
   }
   if(Show_Noncomm_Short==true){
      SetIndexBuffer(2,i_noncomm_short);
      SetIndexLabel(2,"Noncommercial Short");
   }
   if(Show_Operators_Long==true){
      SetIndexBuffer(3,i_operators_long);
      SetIndexLabel(3,"Operators Long");
   }
   if(Show_Operators_Short==true){
      SetIndexBuffer(4,i_operators_short);
      SetIndexLabel(4,"Operators Short");
   }
   if(Show_Nonrep_Long==true){
      SetIndexBuffer(5,i_nonrep_long);
      SetIndexLabel(5,"Nonreportable Long");
   }
   if(Show_Nonrep_Short==true){
      SetIndexBuffer(6,i_nonrep_short);
      SetIndexLabel(6,"Nonreportable Short");
   }
}

void DrowData()
{
   int end_data=get_lastdata();
   for(int i=0;i<end_data;i++){
      if(Show_OI)i_open_interest[i]=get_data(OI, i);
      if(Show_Noncomm_Long)i_noncomm_long[i]=get_data(NONCOMM_LONG, i);
      if(Show_Noncomm_Short)i_noncomm_short[i]=get_data(NONCOMM_SHORT, i);
      if(Show_Operators_Long)i_operators_long[i]=get_data(OPERATORS_LONG, i);
      if(Show_Operators_Short)i_operators_short[i]=get_data(OPERATORS_SHORT, i);
      if(Show_Nonrep_Long)i_nonrep_long[i]=get_data(NONREP_LONG,i);
      if(Show_Nonrep_Short)i_nonrep_short[i]=get_data(NONREP_SHORT,i);
   }
}