[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 103

 
220Volt: As you know, there are no classes in the language, but it's convenient. You can create some semblance of a class using a header file. In it, we create an environment that describes the object (variables) and define functions that will work with this environment. Pretty convenient (provided that the project is quite complex).

Can you be more specific? Could you give me an example, please?

To a beginner like Las-tochk'i these your clever letters say absolutely nothing.

 
Mathemat:

Can you be more specific? Please give us an example of some kind.

For a beginner like Las-tochk'i these smart letters of yours say absolutely nothing.

I don't think anyone would be interested in digging through someone else's code, an example of such a class:

//+------------------------------------------------------------------+
//|                                                  WaveCounter.mq4 |
//|                                                             Паха |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Паха"

#define wC_SHADECOLOR   C'121,0,0'
#define wC_NAMEPART  "WaveCounter"
//#define NEW_LINE_COLOR  DarkKhaki
#define NEW_LINE_STILE  2
#define NEW_LINE_RAY 0
#define SCARP_LINE_STILE   1
//#define SCARP_LINE_COLOR White

#include <WaveCounterCore.mqh>
///////////////////////////////////////////////////////////////////// Var
string wC_sName = "";
int wC_iTimeframe;
int wC_iDirection;
bool wC_bFirst;
int iwC_iLockBar;
double wC_dSizePorog[][2];
//------------------------ rez
int wC_iMoveBar[2];
double wC_dMovePrice[2];
bool wC_bScarp;
int wC_iStop;
/////////////////////////////////////////////////////////////////////
/*
//-------------------------------------------------- private
bool wC_vn_getWaveSizeArray();
//-------------------------------------------------- public
string wC_Create(bool bSizeFilter,
                  bool bAddToExtr);
bool wC_Check(string &sName, 
               bool bFromBegin, 
               bool bFirst);
bool wC_IsScarp();
int wC_IsStop();
bool wC_Redraw();
*/
/////////////////////////////////////////////////////////////////////

string wC_Create(bool bSizeFilter,
                  bool bAddToExtr)
   {
   //----
   string sShadeName[2] = {"wC_Shade1", "wC_Shade2"};
   
   //--//
      if(ObjectFind(sShadeName[0]) < 0)
         {
         Shade_create( sShadeName[0], wC_SHADECOLOR );
         return("");
         }
      
      if(ObjectFind(sShadeName[1]) < 0)
         {
         Shade_create( sShadeName[1], wC_SHADECOLOR );
         return("");
         }
   //--\\
   
   if( ! Shade_attach(sShadeName, false) ) 
      return("");      
   if( ! Shade_direction(wC_iDirection, 0, 1) )
      return("");
   if( ! Shade_minTimeframe(0) )
      return("");
   wC_iTimeframe = Shade_getTimeframe();
   int iCorrectIndex[2] = {0, 1};
   Shade_correctKoord(iCorrectIndex); 
   
   datetime datPoint0;
   double dPoint0, dPoint1;
   if(wC_iDirection == 2)
      {
      if( ! Shade_getPointTimePrice(0, CONTMOV1,  false, datPoint0, dPoint0) )
         return("");
      }
   else
      {
      if( ! Shade_getPointTimePrice(0, CONTMOV1,  true, datPoint0, dPoint0) )
         return("");
      } 

   if(bSizeFilter)
      {
      if( ! wC_vn_getWaveSizeArray() )
         return("");
         
      int iIndexPoroga[1];
      if( ! MyInputBox("Индекс порога", iIndexPoroga) )
         return("");
      if( iIndexPoroga[0] < 0  || iIndexPoroga[0] + 1 > ArrayRange(wC_dSizePorog, 0) )
         {
         Alert("Недопустимый индекс");
         return("");
         }
         
      if(wC_iDirection == 2)
         dPoint1 = dPoint0 + wC_dSizePorog[ iIndexPoroga[0] ][0] * dPoint0;
      else
         dPoint1 = dPoint0 - wC_dSizePorog[ iIndexPoroga[0] ][0] * dPoint0;
      iwC_iLockBar = MYEMPTY;
      }
   else
      {
      if(wC_iDirection == 2)
         {
         if( ! Shade_getPoint(1, CONTMOV2, true, iwC_iLockBar) )
            return(false);
         dPoint1 = iHigh(NULL, wC_iTimeframe, iwC_iLockBar);
         }
      else
         {
         if( ! Shade_getPoint(1, CONTMOV2, false, iwC_iLockBar) )
            return(false);
         dPoint1 = iLow(NULL, wC_iTimeframe, iwC_iLockBar); 
         }
      if(dPoint1 == 0)
         return(false);
      if(bAddToExtr)
         iwC_iLockBar --;
      }

   if( ! Fun_partOfName(wC_sName) )
      return("");   
   wC_sName = StringConcatenate(wC_sName, wC_NAMEPART);
   
   if( ! ObjectCreate(wC_sName, OBJ_TREND, 0, datPoint0, dPoint0, datPoint0, dPoint1) )
      return("");
   if( ! ObjectSetText(wC_sName, "2") )
      return("");
   if( ! ObjectSet(wC_sName, OBJPROP_RAY, NEW_LINE_RAY) )
      return("");
   if( ! ObjectSet(wC_sName, OBJPROP_COLOR, Fun_ColorFromPanel()) )
      return("");
   if( ! ObjectSet(wC_sName, OBJPROP_STYLE, NEW_LINE_STILE) )
      return("");
   
   Fun_deleteObjects(sShadeName);
   return(wC_sName); 
   }
//--------------------------------------------------

bool wC_vn_getWaveSizeArray()
   {
   static bool bSizePorogInit = false;
   if(bSizePorogInit)
      return(true);
   string sSymbol = Symbol();
   if( sSymbol == "USDCHF" )
      {
      if(ArrayResize(wC_dSizePorog, ArrayRange(prop_dWaveSizeUSDCHF, 0)) < 0)
         return(false);
      if(ArrayCopy(wC_dSizePorog, prop_dWaveSizeUSDCHF) < 1)
         return(false);
      bSizePorogInit = true;
      return(true);
      }
         
   if( sSymbol == "AUDJPY" )
      {
      if(ArrayResize(wC_dSizePorog, ArrayRange(prop_dWaveSizeAUDJPY, 0)) < 0)
         return(false);
      if(ArrayCopy(wC_dSizePorog, prop_dWaveSizeAUDJPY) < 1)
         return(false);
      bSizePorogInit = true;
      return(true);
      }
         
   if( sSymbol == "EURUSD" )
      {
      if(ArrayResize(wC_dSizePorog, ArrayRange(prop_dWaveSizeEURUSD, 0)) < 0)
         return(false);
      if(ArrayCopy(wC_dSizePorog, prop_dWaveSizeEURUSD) < 1)
         return(false);
      bSizePorogInit = true;
      return(true);
      }
         
   if( sSymbol == "EURGBP" )         
      {
      if(ArrayResize(wC_dSizePorog, ArrayRange(prop_dWaveSizeEURGBP, 0)) < 0)
         return(false);
      if(ArrayCopy(wC_dSizePorog, prop_dWaveSizeEURGBP) < 1)
         return(false);
      bSizePorogInit = true;
      return(true);
      }
     
   if( sSymbol == "EURJPY" )           
      {
      if(ArrayResize(wC_dSizePorog, ArrayRange(prop_dWaveSizeEURJPY, 0)) < 0)
         return(false);
      if(ArrayCopy(wC_dSizePorog, prop_dWaveSizeEURJPY) < 1)
         return(false);
      bSizePorogInit = true;
      return(true);
      }
         
   if( sSymbol == "GBPUSD" )            
      {
      if(ArrayResize(wC_dSizePorog, ArrayRange(prop_dWaveSizeGBPUSD, 0)) < 0)
         return(false);
      if(ArrayCopy(wC_dSizePorog, prop_dWaveSizeGBPUSD) < 1)
         return(false);
      bSizePorogInit = true;
      return(true);
      }
         
   if( sSymbol == "USDCAD" )            
      {
      if(ArrayResize(wC_dSizePorog, ArrayRange(prop_dWaveSizeUSDCAD, 0)) < 0)
         return(false);
      if(ArrayCopy(wC_dSizePorog, prop_dWaveSizeUSDCAD) < 1)
         return(false);
      bSizePorogInit = true;
      return(true);
      }
         
   if( sSymbol == "USDJPY" )            
      {
      if(ArrayResize(wC_dSizePorog, ArrayRange(prop_dWaveSizeUSDJPY, 0)) < 0)
         return(false);
      if(ArrayCopy(wC_dSizePorog, prop_dWaveSizeUSDJPY) < 1)
         return(false);
      bSizePorogInit = true;
      return(true);
      }
         
   if( sSymbol == "AUDUSD" )            
      {
      if(ArrayResize(wC_dSizePorog, ArrayRange(prop_dWaveSizeAUDUSD, 0)) < 0)
         return(false);
      if(ArrayCopy(wC_dSizePorog, prop_dWaveSizeAUDUSD) < 1)
         return(false);
      bSizePorogInit = true;
      return(true);
      }
      
   Alert("У символа нет размерного массива, или он не прописан в функции Tl_vn_getWaveSizeArray()");
   return(false);
   }
//--------------------------------------------------

bool wC_Check(string &sName, 
               bool bFromBegin, 
               bool bFirst)
   {
   if(StringFind(sName, wC_NAMEPART) == -1)
      return(false);
   wC_bScarp = false;
   wC_iStop = -1;
   wC_sName = sName;
   string sDescrip = ObjectDescription(sName);
   int iID = StrToInteger(sName);
   if(iID == 0)
      return(false);
      
   datetime datLastTime;
   if(sDescrip == "1"  &&  ! bFirst)
      {
      datLastTime = FL_LastTime();
      if(datLastTime == -1)
         datLastTime = MYEMPTY;
      if( ! tlC_Load(iID, datLastTime) )
         return(false);
      wC_bFirst = false;
      if(bFromBegin)
         if( ! tlC_SeekToBegin())
            return(false);
      }
   else
      {
      if(sDescrip == "2"  &&  bFirst)
         {
         int iBeginBar = iBarShift(NULL, wC_iTimeframe, ObjectGet(sName, OBJPROP_TIME1), true);
         if(iBeginBar == -1)
            return(false);
         datLastTime = FL_LastTime();
         if(datLastTime == -1)
            datLastTime = MYEMPTY;
         if( ! tlC_Attach(iID, wC_iDirection, wC_iTimeframe, iBeginBar, ObjectGet(sName, OBJPROP_PRICE2), iwC_iLockBar, datLastTime) )
            return(false); 
         if(iwC_iLockBar != MYEMPTY)
            tlC_SetStops(false, MYEMPTY);
         wC_bFirst = true;
         }
      else
         return(false);
      }
   
   if( ! tlC_Check() )
      return(false);
      
   wC_bScarp = tlC_IsScarp();
   wC_iStop = tlC_IsStop();
   tlC_GetCurView(wC_iMoveBar, wC_dMovePrice);
   if(wC_bScarp)
      {
      int iTempVar;
      double dTempVar;
      tlC_GetCurPos(iTempVar, dTempVar);
      wC_iMoveBar[1] = iTempVar;
      wC_dMovePrice[1] = dTempVar;
      }
   
   return(true);
   }
//--------------------------------------------------

bool wC_IsScarp()
   {
   return(wC_bScarp);
   }
//--------------------------------------------------

int wC_IsStop()
   {
   return(wC_iStop);
   }
//--------------------------------------------------


  
 

One function did not fit:

bool wC_Redraw()
   {
   if(wC_iStop != -1)
      {
      ObjectDelete(wC_sName);
      return(true);
      }
   if(wC_bFirst)
      if( ! ObjectSetText(wC_sName, "1"))
         return(false);
   int iTimeframe = tlC_GetTimeframe();
   double dLockPrice = tlC_GetPriceLock();
   datetime datMoveTime[2];
   datMoveTime[0] = iTime(NULL, iTimeframe, wC_iMoveBar[0]);
   if(datMoveTime[0] == 0)
      return(false);
   if( ! ObjectMove(wC_sName, 0, datMoveTime[0], wC_dMovePrice[0]) )
      return(false);
   
   if(dLockPrice == MYEMPTY)
      {
      datMoveTime[1] = iTime(NULL, iTimeframe, wC_iMoveBar[1]);
      if(datMoveTime[1] == 0)
         return(false);
      if( ! ObjectMove(wC_sName, 1, datMoveTime[1], wC_dMovePrice[1]) )
         return(false);
         
      if(wC_bScarp)
         {
         if( ! ObjectSet(wC_sName, OBJPROP_RAY, false) )
            return(false);
         if( ! ObjectSet(wC_sName, OBJPROP_STYLE, SCARP_LINE_STILE) )
            return(false);
         if( ! ObjectSetText(wC_sName, "0"))
            return(false);
         //ObjectSet(wC_sName, OBJPROP_COLOR, SCARP_LINE_COLOR);    
         return(true);
         }
      else
         ObjectSet(wC_sName, OBJPROP_RAY, true);
      }
   else
      if( ! ObjectMove(wC_sName, 1, datMoveTime[0], dLockPrice) )
         return(false);
      
   if( ! tlC_Save())
      return(false);
   
   return(true);
   }
 
alsu:

No, at the moment t3. The point is that t3 is the first tick of the bar, and that means, because calculations have not been performed on it yet, the value of IndicatorCounted() has not yet had time to change - it happens only after the function start() finishes its work. This is quite logical - the function gives the number of calculated bars, so there's no sense to change its value until at least one tick of the given bar has been calculated. Therefore at the moment t3 we still see the value 299, but at the next tick it will be 300.

Is that clearer?

Yes, that makes more sense, thank you.
 
when an advisor works, the comments are displayed on the screen in the upper left corner. how can they be moved 100-200 pips to the right? because it is impossible to read anything in that corner usually because of character overlaps... ((((
 
w_ersoc:
when the EA is running, the comments are displayed in the top left corner. how can they be moved 100-200 pips to the right? as it's usually impossible to read anything in that corner due to character overlaps... ((((

spaces at the beginning of the commentary text is easiest

or like this:

   ObjectCreate("label_object1", OBJ_LABEL, 0, 0, 0);  
   ObjectSet("label_object1", OBJPROP_XDISTANCE, 720);  
   ObjectSet("label_object1", OBJPROP_YDISTANCE, 45);
   ObjectSetText("label_object1", StringConcatenate("Процент отрицательных %:     ", PercentMinus), 8, "Lucida Console", NavajoWhite);
   



 
moskitman:

spaces at the beginning of the commentary text is easiest

or so...

Thank you!)
 
I would like to explain a little bit about what I posted above. For example, we have the task of making a car model in MKL4. We know that the car has some properties: oil pressure, crankshaft speed, coolant temperature, etc.. But if we abstract a bit, we can understand what we want from the car: to go forward, to go backward, to go left, to go right. This is why all properties are declared as variables in our package and leave them untouched. For interaction with the external environment, we leave the functions: forward(), backward(), left(), right(). Basically, it smells like encapsulation. This will help a lot when complicating the project.
 
Guys, how do I write the expression correctly? I need to compare two prices.
Close[2]>=Open[1]

but Open[1] needs to write that the price is lower by 1 ppt.

I have 5 decimal places, so I wrote

Close[2] >= (Open[1]-10*Point)

but it turns out this term is wrong because it doesn't work.

what's the right way to write it?

 
kilnart:

but it turns out this deadline is wrong because it doesn't work.

What exactly isn't working?