Multicurrency Statistical characteristics

Author: Copyright © 2019, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Multicurrency Statistical characteristics
ÿþ//+------------------------------------------------------------------+

//|                    Multicurrency Statistical characteristics.mq5 |

//|                              Copyright © 2019, Vladimir Karputov |

//|                                           http://wmua.ru/slesar/ |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2019, Vladimir Karputov"

#property link      "http://wmua.ru/slesar/"

#property version   "1.001"

#property indicator_chart_window

#property indicator_buffers 0

#property indicator_plots 0

//---

#include <Trade\SymbolInfo.mqh>  

CSymbolInfo    m_symbol;                     // symbol info object

//--- method of stat 

enum methodOfStat

  {

   mean=0,        // A@54=55 7=0G5=85, mean 

   variance=1,    // 48A?5@A8O, variance 

   skewness=2,    // :>MDD8F85=B 0A8<<5B@88, skewness 

   kurtosis=3,    // :>MDD8F85=B M:AF5AA0, kurtosis 

  };

//--- input parameters

input int            Inpcount=7;             // :>;8G5AB2> M;5<5=B>2, the number of elements 

input methodOfStat   Inpmethod=variance;     // <5B>4, method

input bool           InpCurrentSybmol=true;  // Current Symbol, "true" -> "Symbols" OFF

input string         InpSymbols="EURUSD,USDCAD,GBPUSD,USDJPY,EURAUD,AUDUSD,NZDUSD,AUDCAD";// Symbols

//---

int   array_handle_iCustom[];       // array for storing the handles of the iCustom indicators

string array_symbols[];             // array for storing symbols name

string array_name_trend_labels[];   // array for storing labels trend name

string array_name_labels[];         // array for storing labels name

string prefix="MSc ";

int    size=0;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//---

   string to_split="";

   if(!InpCurrentSybmol)

      to_split=InpSymbols;   // a string to split into substrings 

   else

      to_split=Symbol();   // a string to split into substrings 



   StringTrimLeft(to_split);

   StringTrimRight(to_split);



   string sep=",";               // a separator as a character 

   ushort u_sep;                 // the code of the separator character 

   string result[];              // an array to get strings 

//--- get the separator code 

   u_sep=StringGetCharacter(sep,0);

//--- split the string to substrings 

   int k=StringSplit(to_split,u_sep,result);



   for(int i=0;i<k;i++)

     {

      if(m_symbol.Name(result[i])) // sets symbol name

        {

         size=ArraySize(array_symbols);

         ArrayResize(array_symbols,size+1);

         array_symbols[size]=m_symbol.Name();

        }

     }

   ArrayPrint(array_symbols);

   size=ArraySize(array_symbols);

   ArrayResize(array_handle_iCustom,size);

   ArrayResize(array_name_trend_labels,size);

   ArrayResize(array_name_labels,size);



   for(int i=0;i<size;i++)

     {

      //--- create handle of the indicator iCustom

      int handle_iCustom=iCustom(array_symbols[i],Period(),"Statistical characteristics",Inpcount,Inpmethod);

      //--- if the handle is not created 

      if(handle_iCustom==INVALID_HANDLE)

        {

         //--- tell about the failure and output the error code 

         PrintFormat("Failed to create handle of the iCustom indicator for the symbol %s/%s, error code %d",

                     array_symbols[i],

                     EnumToString(Period()),

                     GetLastError());

         //--- the indicator is stopped early 

         return(INIT_FAILED);

        }



      array_handle_iCustom[i]=handle_iCustom;

     }



   int width=70,y=60;

   for(int i=0;i<size;i++)

     {

      LabelCreate(0,prefix+array_symbols[i]+" trend",0,30+width*i,y,CORNER_LEFT_LOWER,"******");

      LabelCreate(0,prefix+array_symbols[i],0,30+width*i,y-10,CORNER_LEFT_LOWER,array_symbols[i]);

     }

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---

   ObjectsDeleteAll(0,prefix,0,OBJ_LABEL);

  }

//+------------------------------------------------------------------+

//| 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[])

  {

//---

   for(int i=0;i<size;i++)

     {

      double custom[];

      ArraySetAsSeries(custom,true);

      if(!iGetArray(array_handle_iCustom[i],0,0,2,custom))

         return(rates_total);

      if(custom[0]>custom[1])

         LabelTextChange(0,prefix+array_symbols[i]+" trend","  +  ");

      else

         LabelTextChange(0,prefix+array_symbols[i]+" trend","  -  ");

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+ 

//| Create a text label                                              | 

//+------------------------------------------------------------------+ 

bool LabelCreate(const long              chart_ID=0,               // chart's ID 

                 const string            name="Label",             // label name 

                 const int               sub_window=0,             // subwindow index 

                 const int               x=0,                      // X coordinate 

                 const int               y=0,                      // Y coordinate 

                 const ENUM_BASE_CORNER  corner=CORNER_LEFT_LOWER, // chart corner for anchoring 

                 const string            text="Label",             // text 

                 const string            font="Lucida Console",// font 

                 const int               font_size=10,             // font size 

                 const color             clr=clrMagenta,           // color 

                 const double            angle=0.0,                // text slope 

                 const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type 

                 const bool              back=false,               // in the background 

                 const bool              selection=false,          // highlight to move 

                 const bool              hidden=true,              // hidden in the object list 

                 const long              z_order=0)                // priority for mouse click 

  {

//--- reset the error value 

   ResetLastError();

//--- create a text label 

   if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))

     {

      Print(__FUNCTION__,

            ": failed to create text label! Error code = ",GetLastError());

      return(false);

     }

//--- set label coordinates 

   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);

   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);

//--- set the chart's corner, relative to which point coordinates are defined 

   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);

//--- set the text 

   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);

//--- set text font 

   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);

//--- set font size 

   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);

//--- set the slope angle of the text 

   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);

//--- set anchor type 

   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);

//--- set color 

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);

//--- display in the foreground (false) or background (true) 

   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);

//--- enable (true) or disable (false) the mode of moving the label by mouse 

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);

//--- hide (true) or display (false) graphical object name in the object list 

   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);

//--- set the priority for receiving the event of a mouse click in the chart 

   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);

//--- successful execution 

   return(true);

  }

//+------------------------------------------------------------------+ 

//| Change the label text                                            | 

//+------------------------------------------------------------------+ 

bool LabelTextChange(const long   chart_ID=0,   // chart's ID 

                     const string name="Label", // object name 

                     const string text="Text")  // text 

  {

//--- reset the error value 

   ResetLastError();

//--- change object text 

   if(!ObjectSetString(chart_ID,name,OBJPROP_TEXT,text))

     {

      Print(__FUNCTION__,

            ": failed to change the text! Error code = ",GetLastError());

      return(false);

     }

//--- successful execution 

   return(true);

  }

//+------------------------------------------------------------------+

//| Get value of buffers                                             |

//+------------------------------------------------------------------+

double iGetArray(const int handle,const int buffer,const int start_pos,const int count,double &arr_buffer[])

  {

   bool result=true;

   if(!ArrayIsDynamic(arr_buffer))

     {

      Print("This a no dynamic array!");

      return(false);

     }

   ArrayFree(arr_buffer);

//--- reset error code 

   ResetLastError();

//--- fill a part of the iBands array with values from the indicator buffer

   int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer);

   if(copied!=count)

     {

      //--- if the copying fails, tell the error code 

      PrintFormat("Failed to copy data from the indicator, error code %d",GetLastError());

      //--- quit with zero result - it means that the indicator is considered as not calculated 

      return(false);

     }

   return(result);

  }

//+------------------------------------------------------------------+

Comments