Errors, bugs, questions - page 2247

 
A100:
build 1755\1795 compiles without errors. So it's up to the doctor... Especially since it's fine without the template... and how could the template affect it?!

I am using 1816. Yes, it compiles in 1795 without any problems. Looked at another 1881 - it doesn't compile. So, about the doc, that was a strong point.

 
fxsaber:

A usability example would be nice to see.

Since STL comes from C++, examples of usability can be seen there. The point of porting to MQL is to replicate as much as possible the principle of container abstraction and generalization of algorithms. In particular, you can simplify the programming style - write in one line what is otherwise usually written as several loops with calculations.

 
Stanislav Korotky:

Since STL comes from C++, you can see examples of how to use it there.

Unfortunately, I don't understand this language.

 

Is it correct that in indicators global variables are reset to zero when the period is changed ????

string test="";
int OnInit()
  {
   Print("N 1 = ",test);
   test="Rezult";
   Print("N 2 = ",test);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   Print("N 3 = ",test);
   return(rates_total);
  }

In theory it should be like in EAs, they should not reset.....

How do I save the global variable data when I change period?

 
Vladimir Pastushak:

Guys, is it correct that the global variables are reset when you change period in the indicators ????

I think it's abnormal that they are not zeroed in EAs
 
TheXpert:
I find it abnormal that they are not zeroed in EAs

Such variables should be reset if necessary.

A global variable should not be reset when the period is changed...

We have no way to save the data when the period changes...
 
Vladimir Pastushak:

Such variables should be reset if necessary.

A global variable should not be reset when the period is changed...

We don't have the option to save data when the period changes...

How is that not possible?
There are a lot of options.
The most convenient one seems to me to be through a resource.
I myself have been using it for a long time now.

 
Nikolai Semko:

How can it not be?
There are plenty of options.
The most convenient for me seems to be through rusursy.
I myself have long been using.

Give me an example please...

 
Vladimir Pastushak:

Such variables should be reset if necessary.

A global variable should not be reset when the period is changed...

We don't have the option of saving the data when the period changes...

Why shouldn't it? New period --> new indicator instance. And what can a variable of a deleted indicator instance have to do with a new one?

 
Vladimir Pastushak:

Give me an example please...

union DoubleUint { double d; uint u[2]; };


class Cdouble
  {
private:
   string            Name;
   uint              Var[2];
   uint              w;
   uint              h;
   DoubleUint        du;

public:
                     Cdouble(const string name,double var);
                    ~Cdouble();
   bool              Ok;
   bool              Set(double var);
   double            value;
  };

Cdouble::Cdouble(const string name,double var)
  {
   w=2;
   h=1;
   Ok=false;
   Name="::"+name+ IntegerToString(ChartGetInteger(0,CHART_WINDOW_HANDLE));
   if(ResourceReadImage(Name,Var,w,h))
     {
      du.u[0]=Var[0];
      du.u[1]=Var[1];
      value=du.d;
      Ok=true;
     }
   else
     {
      du.d=var;
      Var[0]=du.u[0];
      Var[1]=du.u[1];
      value=var;
      if(!ResourceCreate(Name,Var,2,1,0,0,0,COLOR_FORMAT_XRGB_NOALPHA)) printf("Error create Resource: "+DoubleToString(GetLastError(),0));
      else Ok=true;
     }
  }

Cdouble::~Cdouble()
  {
   if(_UninitReason!=REASON_RECOMPILE && _UninitReason!=REASON_CHARTCHANGE) ResourceFree(Name);
  }
//+------------------------------------------------------------------+
bool Cdouble::Set(double var)
  {
   du.d=var;
   Var[0]=du.u[0];
   Var[1]=du.u[1];
   value=var;
   Ok=false;
   if(!ResourceCreate(Name,Var,2,1,0,0,0,COLOR_FORMAT_XRGB_NOALPHA)) {printf("Error create Resource: "+DoubleToString(GetLastError(),0)); return(false);}
   else { Ok=true; return(true);}
  }
//+------------------------------------------------------------------+

And here is the indicator itself, using this class
Click on the TF and you will see that everything is ok.
#include <CVar\Variable.mqh>

Cdouble d ("abracadabra",-898767.98798);

int OnInit()
  {
   EventSetMillisecondTimer(1000);
   return(INIT_SUCCEEDED);
  }
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   return(rates_total);
  }

void OnTimer()
  {
   Comment(DoubleToString(d.value,5));
   d.Set(d.value+0.01);  
  }