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

 
Andrey Sokolov #:

Greetings. Can you give me a hint? How in mt5 at initialization or at tick to define testing?

So far I've only found OnTester(), which is called right before OnDeinit().

MQLInfoInteger (MQL_TESTER).

Something like this.

 
Nerd Trader #:
last_time = iTime(NULL, 0, 0);

  if(last_time > bar.time_open){
    bar.time_open = last_time;
    coint++;//стартовое значение -1
  }

There's obviously something wrong here!

 
Alekseu Fedotov thank you
 

Why?

#property indicator_color1 clrIndianRed;
#property indicator_color2 clrMagenta;
#property indicator_color3 clrRed;

extern color Cl1 = clrIndianRed;
extern color Cl2 = clrMagenta;
extern color Cl3 = clrRed;

color sColor[] = {indicator_color1,indicator_color2,indicator_color3}; // Так нормально
color sColor[] = {Cl1,Cl2,Cl3}; // Так ошибки 'Cl1' - constant expression required 

---

What is the best way to build an array from input/extern strings?

 
Vitaly Muzichenko #:

Why?

---

What's the best way to build an array from an input/external string?

Put colours as a string in input and then separate the string into an array.

I don't want to put any code for colours right now, you'll figure it out yourself. I've got a list of characters transferred to an array like this

  string s_arr[]; // В этом массиве будет перечень нужных символов
  if(StringSplit(slist, ',', s_arr) <= 0)
   {
    Print(__FUNCTION__ + " Error converting !");
    return;
   }

This is a list in input variable.

 
Vitaly Muzichenko #:

Why?

---

What is the way to build an array from input/extern strings?

I agree with Alexei.

extern string Colors = "clrIndianRed/clrMagenta/clrRed";
color sColor[];
//+------------------------------------------------------------------+
int OnInit()
  {
   ushort sep  = StringGetCharacter("/",0);
   string tempLevel[];
   int sz1  = StringSplit(Colors,sep,tempLevel);
   ArrayResize(sColor,sz1);
   for(int i=0; i<sz1; i++)
   {
    sColor[i] = StringToColor(tempLevel[i]);Print(i," / ",sColor[i]);
   }
//---
   return(INIT_SUCCEEDED);
  }
 
Alexey Viktorov #:

Enter the colours as a string in the input and then divide the string into an array.

I don't want to pass code for colours right now, you can figure it out yourself. I have a list of characters transferred to an array like this

This is the list in the input variable.

I know this way, but it won't work - there's no way to select from the list


 

Right now the colours are like this, it's not convenient, and I can't find a reason why I can't change the colour, after applying the settings change to standard


 
Vitaly Muzichenko #:

Right now the colours are like this, it's not convenient, and I can't find a reason why I can't change the colour, after applying the parameters change to standard


Then it's like this

extern color Cl1 = clrIndianRed;
extern color Cl2 = clrMagenta;
extern color Cl3 = clrRed;
string Colors = ColorToString(Cl1)+"/"+ColorToString(Cl2)+"/"+ColorToString(Cl3);
color sColor[];
//+------------------------------------------------------------------+
int OnInit()
  {
   ushort sep  = StringGetCharacter("/",0);
   string tempLevel[];
   int sz1  = StringSplit(Colors,sep,tempLevel);
   ArrayResize(sColor,sz1);
   for(int i=0; i<sz1; i++)
   {
    sColor[i] = StringToColor(tempLevel[i]);Print(i," / ",sColor[i]);
   }
//---
   return(INIT_SUCCEEDED);
  }
 
MakarFX #:

That's it, then.

Great, just what I need!

Thank you!

P.S. Found the reason why parameters were not saved, there were semicolons at the end, got caught when copying from input - removed and everything worked. Inattention.


Reason: