Tutorial how to work with classes!

 

Search engine doesnt give me the exampe i seek!!

I'm looking an good and step by step tutorial how to create a class. For example a class that can open 4 buttens.

Someone got a good tutorial?

 

Thank you in forwarding!! 

 

Do you know the magnifier on the top right corner on this page?

Open it and enter OOP and start reading!

Another MQL5 OOP Class
Another MQL5 OOP Class
  • 2013.07.22
  • Jordi Bassaganas
  • www.mql5.com
This article shows you how to build an Object-Oriented Expert Advisor from scratch, from conceiving a theoretical trading idea to programming a MQL5 EA that makes that idea real in the empirical world. Learning by doing is IMHO a solid approach to succeed, so I am showing a practical example in order for you to see how you can order your ideas to finally code your Forex robots. My goal is also to invite you to adhere the OO principles.
 
Carl Schreiber:

Do you know the magnifier on the top right corner on this page?

Open it and enter OOP and start reading!

Ok, i got something like this. Is that good?

 

It opens 4 labels that when you move them go back to the original place. And refreshes the first label according to the close and open price or current barr! 

 

//+------------------------------------------------------------------+
//|                                              Countdown Class.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
int OnInit(){
   EventSetMillisecondTimer(1000);
   return(INIT_SUCCEEDED);
  
}
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[]){
  
   return(rates_total);
  }
void OnTimer(){
   Analyze one,two,three,four;
   one.bars = 1;
   two.bars = 2;
   three.bars = 3;
   four.bars = 4;
   Label een,twee,drie,vier;
  
   een.num = 1;
   een.text = DoubleToString(one.avg(),5);
   een.SetText();
   een.Location();
   twee.num = 2;
   twee.text = DoubleToString(two.avg(),5);
   twee.SetText();
   twee.Location();
   drie.num = 3;
   drie.text = DoubleToString(three.avg(),5);
   drie.SetText();
   drie.Location();
   vier.num = 4;
   vier.text = DoubleToString(four.avg(),5);
   vier.SetText();
   vier.Location();
}
class Analyze{
   public:
   int bars;
   double GetAVG(void);
   double avg(){return(GetAVG());}
  
   private:
   double open(){return(iOpen("J225",PERIOD_D1,bars));}
   double close(){return(iClose("J225",PERIOD_D1,bars));}
};

double Analyze::GetAVG(void){
   return((open()+close())/2);
}
class Label{
   public:
   int num;
   int x;
   int y;
   string text;
   void Location(void);
   void SetText(void);
  
};
void Label::Location(void){
   if(ObjectFind(0,"label"+IntegerToString(num,0,0)))ObjectCreate(0,"label"+IntegerToString(num,0,0),OBJ_LABEL,0,0,0);
   if(ObjectGetInteger(0,"label"+IntegerToString(num,0,0),OBJPROP_XDISTANCE,0)!= (5))ObjectSetInteger(0,"label"+IntegerToString(num,0,0),OBJPROP_XDISTANCE,5);
   if(ObjectGetInteger(0,"label"+IntegerToString(num,0,0),OBJPROP_YDISTANCE,0)!= (num*15))ObjectSetInteger(0,"label"+IntegerToString(num,0,0),OBJPROP_YDISTANCE,num*15);
}
void Label::SetText(void){
   ObjectSetText("label"+IntegerToString(num,0,0),text,10,NULL,clrBlack);
}
Reason: