Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

YURAZ_MCCH Calculation Indicator - indicator for MetaTrader 5

Views:
8233
Rating:
(32)
Published:
2015.01.22 12:54
Updated:
2016.11.22 07:32
YURAZ_MCCH.mq5 (7.18 KB) view
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

The indicator calculates % of growth or drop towards CLOSE. It is written via use of object-oriented programming and can be easily integrated into any Expert Advisor or other indicator.

  • The indicator calculates CH%, percentage of change of CLOSE of a previous day.
  • Creates objects on a chart. The indicator is written in object-oriented programming style.
  • It is easily integrated into any expert advisor or other indicator. It suffices to describe a class and effectuate its activation

You can estimate code size integrated into another indicator or Expert Advisor.

There are 2 lines:

CChmcYZ chmc;

chmc.RCHsay("EURUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16); // let's calculate the current day CH%

Object-oriented programming offer massive opportunities, necessary classes are written, and then you construct ...


//+------------------------------------------------------------------+
//|                                                   yuraz_mcch.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// class calculation CH% 
//
struct SymbolStruct
  {
   bool              work;
   string            sSymbol;
   int               y;
   int               x;
   double            CH;
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class CChmcYZ
  {
public:
   SymbolStruct      sSymb;
   color             lColorSym;
   color             lColorChPlus;
   color             lColorChMinus;
   color             lColorCH;
   
   int               indicatorWindow; // work in the main window
   void CChmcYZ()    { 
   indicatorWindow=0;
   lColorSym=DarkBlue; //  DarkTurquoise
   lColorCH=DarkGreen; // White; 
   lColorChPlus  = Green; // LimeGreen;
   lColorChMinus = FireBrick ; // Red;
    } // constructor
   void              RCH(string sSym,datetime db,datetime de);   // Full calculation of one pair only without display
   void              RCHsay(string sSym,datetime db,datetime de,int X,int Y); // Full calculation of one pair and its display
private:
   color lColor;
   double            dClose[7000];                    // array for copying maximal prices
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CChmcYZ::RCH(string sSymbol,datetime DATEBEG,datetime DATEEND)
  {
   sSymb.CH = 0;
   int CountBar;
   DATEBEG = StringToTime( TimeToString(DATEBEG,TIME_DATE));
   DATEEND = StringToTime( TimeToString(DATEEND,TIME_DATE));
   CountBar= CopyClose(sSymbol,PERIOD_D1,DATEEND,2,dClose);
   if(CountBar>=0)
     {
      if(NormalizeDouble(dClose[1],5)!=0.0 && NormalizeDouble(dClose[0],5)!=0.0)
        {
         sSymb.CH=(dClose[1]*100)/dClose[0]-100;
        }
     }
  }
//+------------------------------------------------------------------+
//| Calculation with output
//+------------------------------------------------------------------+
void CChmcYZ::RCHsay(string sSym,datetime db,datetime de,int XD,int YD) // Full calculation of one pair only
  {
   RCH(sSym,db,de);
   if(ObjectFind(indicatorWindow,"oYZ"+sSym)==-1)
     {
      ObjectCreate(indicatorWindow,"oYZ"+sSym,OBJ_LABEL,indicatorWindow,0,0);
      ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_XDISTANCE,XD);
      ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_YDISTANCE,YD);
      ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_CORNER,CORNER_LEFT_UPPER);
      ObjectSetString(indicatorWindow,"oYZ"+sSym,OBJPROP_TEXT,sSym);
      ObjectSetString(indicatorWindow,"oYZ"+sSym,OBJPROP_FONT,"Arial");
      ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_FONTSIZE,7);
      ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_COLOR,lColorSym);
      ObjectSetInteger(indicatorWindow,"oYZ"+sSym,OBJPROP_SELECTABLE,true);
     }
   if(ObjectFind(indicatorWindow,"oYZ_"+sSym)==-1)
     {
      ObjectCreate(indicatorWindow,"oYZ_"+sSym,OBJ_LABEL,indicatorWindow,0,0);
      ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_XDISTANCE,XD+45);
      ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_YDISTANCE,YD);
      ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_CORNER,CORNER_LEFT_UPPER);
      ObjectSetString(indicatorWindow,"oYZ_"+sSym,OBJPROP_TEXT,sSym);
      ObjectSetString(indicatorWindow,"oYZ_"+sSym,OBJPROP_FONT,"Arial");
      ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_FONTSIZE,7);
      ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_COLOR,lColorCH);
      ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_SELECTABLE,true);
     }
   YD=YD+11;

   lColor=lColorCH;
   if(sSymb.CH>0)
     {
      lColor=lColorChPlus;
      ObjectSetString(indicatorWindow,"oYZ_"+sSym,OBJPROP_TEXT," "+DoubleToString(sSymb.CH,5));
      ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_XDISTANCE,XD+45);
     }
   if(sSymb.CH<0)
     {
      lColor=lColorChMinus;
      ObjectSetString(indicatorWindow,"oYZ_"+sSym,OBJPROP_TEXT,DoubleToString(sSymb.CH,5));
      ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_XDISTANCE,XD+46);
     }
   ObjectSetInteger(indicatorWindow,"oYZ_"+sSym,OBJPROP_COLOR,lColor);
  }
//
// end of class
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////





//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Code where the class is used in
// 

CChmcYZ chmc;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   chmc.RCHsay("EURUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16); // let's calculate current day of CH%
   chmc.RCHsay("AUDUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12   );
   chmc.RCHsay("GBPUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*2 );
   chmc.RCHsay("USDCHF",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*3 );
   chmc.RCHsay("USDCAD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*4 );
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
  {
   chmc.RCHsay("EURUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16); // let's calculate current day of CH%
   chmc.RCHsay("AUDUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12   );
   chmc.RCHsay("GBPUSD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*2 );
   chmc.RCHsay("USDCHF",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*3 );
   chmc.RCHsay("USDCAD",TimeCurrent()-86400*5,TimeCurrent(),5,16+12*4 );
   return(rates_total);
  }

 void OnDeinit()
  {
   int i=ObjectsTotal(0); // remove our objects
   while( i > 0  )
     {
      if(StringSubstr(ObjectName(0,i ),0,3)=="oYZ")
        {
         ObjectDelete(0,ObjectName(0,i ));
        }
        i--;
      }
  }

Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/11347

DynamicRS_C_HTF DynamicRS_C_HTF

The DynamicRS_C indicator with the timeframe selection option available in input parameters.

CronexRSI CronexRSI

The MACD Indicator, in which the price series is replaced by the series of values of the iRSI technical indicator. It is drawn in the form of a colored cloud.

Corr Corr

Correlation ratio.

WPRslow WPRslow

A semaphore signal indicator on the basis of Williams' Percent Range Oscillator. The indicator identifies slow trends.