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

 
Alexey Viktorov:

The question seems to be about MT5. The answer is: Not programmatically. The question can be closed.

Thank you

 

Good afternoon everyone, as promised I'm back for more tutorialsЈ ;-) Of course I got the grail machine running, but it's been slow in testing so I've been searching for ways to execute code within it tick only when new bar arrives. Found the following option. On the global level, a variable is defined

int intBars;// ГЛОБАЛЬНО ОПРЕДЕЛЁННАЯ ПЕРЕМЕННАЯ ДЛЯ ОПРЕДЕЛЕНИЯ НАСТУПЛЕНИЯ

Then I wrote a function that checks whether a new bar has occurred - this is a masterpiece


bool f_IsNewBar()
{
   if(intBars != Bars) 
   {
      intBars = Bars;
      return(true);
   } 
return(false);
}

When I found this variant, they say that I should create a function with all the logic from the on-tick. I don't like this approach with functions, frankly speaking, so I just check if there is a new bar and if it's true, I will execute code in the on-tick. In simplified form - without any real work it looks like this

void OnTick()
{//НАЧАЛО ОН ТИК
   // если появился новый бар:
   if(f_IsNewBar()) // ЕСЛИ ПОЯВИЛСЯ НОВЫЙ БАР
    {// ВЫПОЛНЯЕМ ВЕСЬ КОД В ОН ТИК
/*
МНОГО МНОГО СЕКРЕТНОГО ГРААЛЬНОГО КОДА😃😃😃
*/

    }
}// КОНЕЦ ОН ТИК

I have a different question. The grail will of course work on the real case. So, this check should be removed in the version of the grail that will not be tested in the tester but will be executed on the real tick, so that the EA will operate on every tick, or should we leave this check for the real tick as well? If this check is also included into the real account version, how should we plan a second attempt to open orders if they were not opened the first time?

 
DanilaMactep:

Good afternoon everyone, as promised I'm back for more tutorialsЈ ;-) Of course I got the grail machine running, but it's been slow in testing so I've been searching for ways to execute code within it tick only when new bar arrives. Found the following option. On the global level, a variable is defined

Then I wrote a function that checks whether a new bar has occurred - this is a masterpiece


When I found this variant, they say that I should create a function with all the logic from the on-tick. I don't like this approach with functions, frankly speaking, so I just check if there is a new bar and if it's true, I will execute code in the on-tick. In simplified form - without any real work it looks like this

I have a different question. The grail will of course work on the real case. So, in the version of the grail that will not be tested in the tester but will work on the real account, should we remove this check to make the EA work on every tick or should we leave it for the real account as well? If this check is also included into the real account version, how should we plan a second attempt to open orders if they were not opened the first time?

If calculations are performed on bar values of OPT, HI, LO, CLOSES, we don't need to count on every tick. But it is correct to monitor the price on every tick. This should be separate calculations or condition checks.

The new bar is also tracked by the zero bar opening time.

FlagNewBar=false;   // глобальная или статик булева переменная
   if(BarTime!=Time[0])
     {
      BarTime=Time[0];
      FlagNewBar=true;
     }
 
Artyom Trishkin:

In this thread I want to begin to help those who really want to understand and learn programming in the new MQL4 and want to easily switch to MQL5 - the languages are very similar.

This blog will be a good place to discuss problems, algorithms of their solution and any other questions concerning MT programming one way or another.

I hope that other experienced members of our forum will join the discussion and the branch will be interesting to all.

MQL4 Tasks: Determine the position number of a capital letter in a string. Thank you.

 
Mikhail Nazarenko:

MQL4 Task: Determine the position number of a capital letter in a string. Thank you.

string str="preved mEdved";
string uppercase="ABCDEF.....ZАБВГД....Я";

int finish=StringLen(str)-1;
int pos=-1;
for(int i=0; i<=finish; i++)
   {
   pos=StringFind(uppercase,StringSubstr(str,i,1));
   if(pos>=0) break;
   }
printf(pos);
 
Aleksei Stepanenko:

Thank you.

 
Mikhail Nazarenko:

Thank you.

Wrong, it's not the StringFind result we want, it's the i.

Right:

string str="preved mEdved";
string uppercase="ABCDEF.....ZАБВГД....Я";

int finish=StringLen(str)-1;
int pos=-1;
for(int i=0; i<=finish; i++)
   {
   if(StringFind(uppercase,StringSubstr(str,i,1))>=0)
      {
      pos=i;
      break;
      }
   }
printf(pos);
 
Mikhail Nazarenko:

MQL4 Task: Determine the position number of a capital letter in a string. Thanks.

You can use StringGetCharacter() The character "A" is 65 and "a" is 32 more - 97. And so are all the characters. Hence, if a character code is > 90 and <= 122, it is a lowercase Latin character. Cyrillic characters also differ by 32

 
Alexey Viktorov:

You can

Exactly, a good option.

 
Hi. How do I make a leadership account here?