Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 94

 
Vikon:
Here's the thing about calling a function inside a class: how private: public:, how to pass data to the class and how to get a result from the class. So far this is it!

Within the class, the result has to be calculated somehow. And how will the class without your involvement understand that it needs to return the result now, but not at some other time?

So, you need a method inside the class that can be called from outside. So it must be public.

Although of course you can make a private method that will read all the data inside the class and write it to the class variable, and the public method will call the private method. But some method must be called anyway. And what will be counted there in private method, how complex calculations will be, and what variables will be involved in calculations - everything is up to you, and on your own responsibility.

 
Vikon:
That's the point, how to call a function within a class, namely how private: public:, how to pass data to a class and how to get the result from the class. So far, here it is!
#property version   "1.00"
#property strict
#property script_show_inputs
//--- input parameters
input int      inputA=1;
input int      inputB=3;

class ASD
  {
private:
   // Здесь располагаются переменные и функции, доступные только внутри класса
public:
   int Add(int a,int b)
     {
      Print(__FUNCTION__,": Результат сложения: a",a," + b",b," = ",a+b);
      return(a+b);
     }
  } ar;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   ar.Add( inputA, inputB );
  }
//+------------------------------------------------------------------+
Seems like it should work, I haven't checked if it's correct)
 
Alexey Kozitsyn:
I think it should work, I haven't checked it to see if it's correct)

Here you go, thank you, I'm already starting to move -

the script:

#include <ASD.mqh>
ASD ar;
void OnStart()
  {
   ar.fg (3,5);
   ar.sf ();
  }

class:

class ASD
  {
private:
  int d;
  int g (int a_s,int a_d){d=a_s+a_d;return (d=a_s+a_d); }
public:
void fg (int a_s,int a_d)  { g (a_s,a_d); }
void sf ()                 {Alert (d);}
  };

Alert gives a result of 8, but it's an alert from the class, and I now need an alert from the script

 
Vikon:

Here, thank you, I'm already starting to move -

the script:

#include <ASD.mqh>
ASD ar;
void OnStart()
  {
   ar.fg (3,5);
   ar.sf ();
  }

class:

class ASD
  {
private:
  int d;
  int g (int a_s,int a_d){d=a_s+a_d;return (d=a_s+a_d); }
public:
void fg (int a_s,int a_d)  { g (a_s,a_d); }
void sf ()                 {Alert (d);}
  };

Alert gives a result of 8, but it's an alert from the class, and now I need an alert from the script

Ok, you declare an Alert() method in the class and call it ar.Alert(), although now the sf() method does the same. I'm not quite sure what you want to see after you've written a value in the d field?
 
Alexey Kozitsyn:
Ok, you declare Alert() method in class and call it ar.Alert(), although now sf() method does the same. I'm not quite sure what you want to see after you've written a value to field d?
If you want to get the value of d without calling the sf() method, then you need to add a public method int GetD() const { return( d ); }. And in the script write Alert( ar.GetD() );
 
Alexey Kozitsyn:
Looks like it should work, haven't checked it yet)

Everyone! Thank you so much! Got it -

script:

#include <ASD.mqh>
ASD ar;
void OnStart()
  {
   ar.fg (3,5);
   Alert ( ar.sf ());
  }

class:

class ASD
  {
private:
  int d;
  int g   (int a_s,int a_d)  {return (d=a_s+a_d); }
public:
  void fg (int a_s,int a_d)  { g (a_s,a_d); }
  int sf  ()                 {return (d);}    
  
  };


I'll chew on it!

 

I don't remember who wrote me in this thread that the tester is broken, but I can answer that it may well be broken. It either swallows different chunks of time or starts counting from an arbitrary segment (although all the quotes are there).

I think who needs to see will understand.

 
Good afternoon, could you please tell me if the MRoubd function can be imported from MSDN
?
(returns a number rounded up to a multiple of a given value)

or how to round, for example, 2285.13 to be a multiple of (0.25) 2285.00 __ 2285.25 ___ 2285.50 ___ 2285.75
 
How do I know the leverage of a pair, not an account?
 
SAMER:
how do I know the leverage of a pair rather than an account?

The amount of leverage provided:

long liverage=AccountInfoInteger(ACCOUNT_LEVERAGE);