Navigation:Home > Content >

MetaCOT2_CIT_Netto_Position.mq4

Time: 2014-11-04 | Download file:MetaCOT2_CIT_Netto_Position.mq4

//+------------------------------------------------------------------+
//|                                 MetaCOT 2 - Netto Positions.mq4  |
//|                                  Copyright 2017, Vasiliy Sokolov |
//|                                https://www.mql5.com/en/users/c-4 |
//+------------------------------------------------------------------+
#property copyright "MetaCOT® 2009-2017, Vasiliy Sokolov, St.-Petersburg, Russia"
#property link      "https://www.mql5.com/en/articles/1573"
#include 
#property version   VERSION
#property description "MetaCOT 2 is designed for analize CFTC reports, data mining and for fundamental analysis."
#property description "See article 'MetaCOT Project - New horizons for CFTC report analysis in MetaTrader 4'"
#property description "\nFor work this indicator need download and install 'MetaCOT -  Install CFTC reports' tool."
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_LINE
#property indicator_color1   clrRed
#property icon "\\Images\\MetaCOT\\MetaCOT CIT Netto Positions.ico"
#property strict

#include 
#include 

const ENUM_CFTC_REPORT   ReportType = CFTC_CIT;
CftcReportInfo           ReportInfo;
input ENUM_CIT_NETTO_GROUP     Group = CIT_NETTO_ALL;            // Group of Traders
input string             ProffSettings = "";                    // #      PROFESSIONAL SETTINGS:    #
input ENUM_COT_RELEASE_DAY ReleaseDay = COT_RELEASE_FRIDAY;     // Release Day
input ENUM_COT_DATA_TYPE DateType = COT_DATA_FUTURES;           // Data Type
input ENUM_COT_SUBGROUP  SubGroup = COT_SUBGROUP_ALL;           // Subgroup of Traders
input bool               AutoDetectReport = true;               // Auto Detect Report Name
input string             LoadReportName =                                
                         "# WHEAT - CHICAGO BOARD OF TRADE";      // Report Name (If Auto Detect=false)
input bool               Mirror = false;                        // Mirror Mode

double                   cot_values[];
int                      Sign = 1;
double                   cvalues[];
datetime                 ctimes[];
int                      cindex = 0;
int                      prev_total = 0;
bool                     wrong_combinated = false;
CotBaseSettings          CftcSet;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{  
   // -- initialize -- //
   if(!AutoDetectReport || !GetCftcReportInfo(Symbol(), ReportType, ReportInfo))
   {
      ReportInfo.reverse = Mirror;
      ReportInfo.report_name = LoadReportName;
      ReportInfo.short_name = LoadReportName;
   }
   if(DateType == COT_DATA_NUMBERS_TRADES &&
     Group == CIT_NETTO_NONREP)
   {
      wrong_combinated = true;
      return (INIT_SUCCEEDED);
   }
   else
      wrong_combinated = false;
   Sign = Mirror ? -1 : 1;
   SetIndexBuffer(0, cot_values, INDICATOR_DATA);
   IndicatorSetInteger(INDICATOR_DIGITS, 0);
   string mmode = Mirror ? " (Mirror mode)" : "";
   IndicatorSetString(INDICATOR_SHORTNAME, MC_LABEL + " CIT Netto Pos. " + ReportInfo.short_name + " " + EnumCitNettoGroupToString(Group) + mmode);
   
   // -- Config base parameters -- //
   CftcSet.report_name = ReportInfo.report_name;
   CftcSet.date_type = DateType;
   CftcSet.subgroup = SubGroup;
   CftcSet.release_day = ReleaseDay;
   return(INIT_SUCCEEDED);
}

int OnCalculate (const int rates_total,      // размер входных таймсерий 
                 const int prev_calculated,  // обработано баров на предыдущем вызове 
                 const datetime& time[],     // Time 
                 const double& open[],       // Open 
                 const double& high[],       // High 
                 const double& low[],        // Low 
                 const double& close[],      // Close 
                 const long& tick_volume[],  // Tick Volume 
                 const long& volume[],       // Real Volume 
                 const int& spread[]         // Spread 
   )
{
   if(rates_total - prev_calculated > 1)
      GetCitNettoValues(CftcSet, Group, ctimes, cvalues);
   if(wrong_combinated)
      return rates_total;
   int total = ArraySize(cvalues);
   if(total == 0)
      return rates_total;
   if(prev_calculated == 0)
      cindex = 0;
   ArraySetAsSeries(cot_values, false);
   ArraySetAsSeries(time, false);
   int limit = prev_calculated;
   //Полный пересчет в случае закачки новых данных
   if(total != prev_total)
   {
      limit = 0;
      cindex = 0;
      prev_total = total;
   }
   for(int i = limit; i < rates_total; i++)
   {
      datetime tt = ctimes[cindex];
      if(ctimes[cindex] > time[i])
      {
         cot_values[i] = EMPTY_VALUE;
         continue;
      }
      while(cindex+1 < total && time[i] >= ctimes[cindex+1])  
        cindex++;
      if(!Mirror)
         cot_values[i] = cvalues[cindex];
      else
         cot_values[i] = cvalues[cindex] * (-1);
   }
   return rates_total-1;
}

Recommend