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

 
Yurij Kozhevnikov:

Thank you, such implementation has occurred to me, but it is not quite the same due to absence of Value1 itself. That is, the example I created is, of course, extremely simplified, but it is implied that this is not the main value of the class, that there can be a number of such values and that for each such a construct can be described.

Or for such an implementation, is it possible to describe only a separate class or structure in which to implement the overloading, and in this class to describe variables of the created type? But, if other variables of the class are involved in the assignment operation, then again, it does not add up.

Actually, I wanted to implement something similar to Let/Set/Get methods in vbs.

I don't quite understand the question but C++ / MQL doesn't have a key property Property

maybe you need a template classhttps://www.mql5.com/ru/docs/basis/oop/class_templates


UPD: Here's an article on Habra about the same thinghttps://habr.com/ru/post/121799/ , but I doubt it applies "directly" to MQL

 

Thank you very much!

This is a bit beyond my knowledge, because I've never studied C++, but it seems to be exactly what I wanted. I'll try to figure it out.

 
Yurij Kozhevnikov:

Thank you very much!

It's a bit beyond my knowledge, because I've never studied C++, but it seems to be exactly what I wanted. I'll try to figure it out.

Try formulating your question briefly in this thread:https://www.mql5.com/ru/forum/85652

there are some really cool programmers there and they do stuff like this... well, maybe this will help you figure it out faster

 

Yes, thank you.

I, remembering I had used one, had forgotten it was called Property, and was being obtuse in explaining what I wanted.

It was mentioned in the comments to the article that you can use macro substitution, it got me thinking that perhaps by adopting a strict syntax agreement with myself, you can implement a not so common case much easier.

 
class TestClass
{
  private:
    double cValue1;
    double cValue2;
    double cValue3;
    int cIndex;
    void _Set(double mValue);
  public:
    TestClass():cIndex(-1){}
    double Value1()
    {return cValue1;}

    TestClass* Value(int param)
    {
      cIndex=param;
      return &this;
    }
    void operator =(double mValue) {_Set(mValue);}
};
//---------------------------------------------
void TestClass::_Set(double mValue){
   switch(cIndex){
      case 1:  cValue1=mValue; break;
      case 2:  cValue2=mValue; break;
      case 3:  cValue3=mValue; break;
   }
   cIndex=-1;
}

void TestFunction()
{
  TestClass test;
  test.Value(1)=0.5;
  Print(test.Value1());
}

void OnStart(void)
  {
   TestFunction();
  }
Such a crutch can be portrayed)
 
Vladimir Simakov:
This is the kind of crutch you can make)

Thank you, this crutch is obviously much simpler, although even with this one I still don't understand everything.

Is it impossible to put any set of characters into a macro substitution? Something like this:

#define .<один любой набор символов>()=<второй любой набор символов> Set<один любой набор символов>(<второй любой набор символов>)
#define .<один любой набор символов>(par1)=<второй любой набор символов> Set<один любой набор символов>(par1,<второй любой набор символов>)
 
Aleksey Mavrin:

simply overload DoubleToString, if it returns the string "EMPTY_VALUE" otherwise call ::DoubleToString

I don't get it here.

 
Fast235:

I don't get it here.

but otherwise

#define DoubleToString(value,digits)  (value!=EMPTY_VALUE?DoubleToString(value,digits):"EMPTY_VALUE") 
 
Aleksey Mavrin:

but otherwise

in a rare case, make and delete the source so you don't see it again)


if the buffer was an indicator buffer, you could replace it with EMPTY_VALUE

PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

but the number of buffers is unknown
 

Afternoon. I am trying to attach a stop loss read from atr indicator to my EA. The input variables are as follows.

  extern   ENUM_TIMEFRAMES   PeriodForWork_sl        =  PERIOD_H4;           // ТФ РАСЧЁТА ЗНАЧЕНИЙ СТОП ЛОСА ПО АТР
  extern double sl= 14; // ПЕРИОД АТR СТОП ЛОССА

I am adding the atr values to a variable for a stop loss.

sl=iATR( NULL,PeriodForWork_sl,sl,1);// ПОЛУЧЕНИЕ ЗНАЧЕНИЙ АТР ДЛЯ ВЫСТАВЛЕНИЯ СТОПЛОССА

Then I try to open orders like this.


OrderSend(Symbol(),OP_BUY,lot,Ask,slippages,Bid-sl*Point,Bid+tp*Point,"ДИВЕРГЕНЦИЯ НА БАЙ АО"); // ОТКРЫВАЕМ БАЙ ОРДЕР

But nothing works. I print the value of Stop Loss variable but report that its value is 0. What am I doing wrong? Where do I need to fix it and tweak it to make it work?

Reason: