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

 
yiduwi:

Help, how do I find out the first time coordinate of the trend line?

long  ObjectGetInteger( 
   long     chart_id,         // идентификатор графика 
   string   object_name,      // имя объекта 
   int      prop_id,          // идентификатор свойства 
   int      prop_modifier=0   // модификатор свойства, если требуется 
   );
 

Why can't I do the following? I declare a variable and an array globally and want to assign the value from the variable to the array immediately.

int yo=6;
int masss[4]={0,0,yo,0};

And the same problem with functions, if you assign a variable to an argument, it fails

void Fulr(int ty=yo){}
 
Seric29:

Why can't I do the following? I declare a variable and an array globally and want to assign the value from the variable to the array immediately.

And the same problem with functions, if you assign a variable to an argument, it fails

Документация по MQL5: Основы языка
Документация по MQL5: Основы языка
  • www.mql5.com
Язык MetaQuotes Language 5 (MQL5) является объектно-ориентированным языком программирования высокого уровня и предназначен для написания автоматических торговых стратегий, пользовательских технических индикаторов для анализа разнообразных финансовых рынков. Он позволяет не только писать разнообразные экспертные системы, предназначенные для...
 
Alekseu Fedotov:

Thank you.

 
Artyom Trishkin:

Apparently, it's impossible to say normally. In C++ you can do so, I think it's because mql4 works through a descriptor, i.e. it doesn't have direct access to memory, because every value has an address and if you access that address you can find out what's there, this makes mql4 excessively static and limits many possibilities, especially working with arrays.

 

Is it possible to make two timers in the EA? For some reason I thought OnTimer() was called in a separate thread. But I tried to add an infinite loop in OnInit() and set the timer before it, only the loop worked, OnTimer() was not called.

I need two independent actions to execute constantly on timer. Each with its own interval. How can this be implemented, do you know?

 
leonerd:

Is it possible to make two timers in the EA? For some reason I thought OnTimer() was called in a separate thread. But I tried to add infinite loop in OnInit() and set timer before it, only loop worked, OnTimer() was not called.

I need two independent actions to execute constantly on a timer. Each with its own interval. How can this be implemented, do you know?

For example: count to a hundred and execute the first code, count to 150 and execute the second code. But in a good way, you should make yourself a multitimer class.
 
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 tasks, 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.

Good afternoon. I am writing a trial Expert Advisor for self-study and practical experience. Now it can receive a signal from the indicator and has the function for opening BUY and SELL positions ( Open_BUY_SELL() ). I made this function from some scripts published in CodeBase.

QUESTION - may I ask a knowledgeable person in this thread to check this code for cumbersomeness? ???

I have special doubts and fears in these places:

    m_trade         = new CTrade();
    m_symbol        = new CSymbolInfo();   
    m_position_info = new CPositionInfo();   
    m_account       = new CAccountInfo();
    
    m_symbol.Name(Symbol());
    m_symbol.RefreshRates();

Is it appropriate to write this inside a function? Is it worth moving it to OnInit()? I made the function from two scripts, files pinned to the post

CEngine        engine;
CTrade         trade;
CPositionInfo  apos;
CSymbolInfo    asymbol;

CTrade         *m_trade;
CSymbolInfo    *m_symbol;
CPositionInfo  *m_position_info; 
CAccountInfo   *m_account;

This place is also confusing, if I understand correctly - objects of the same classes duplicate each other. I have just left some declarations from working with the indicator and others from remaking the scripts into a function.


I have not connected the function with the signal yet, I want to understand and clean up the code first. I understand that I have made a mistake somewhere, but I still lack the knowledge and experience to understand exactly where and how to make it right.

Please support.

 

Attached files - EA, two scripts and indicator.

The compiler won't swear, no errors to look for, just some strategic/tactical considerations, as to whether it's OK to do so, and if not, how it should have been done.

Please.

Files:
 
Artyom Trishkin:
But in a good way - the class multitimer need to make.

you can't complicate simple tasks! ... said Me, who idly wrapped the new bar definition function into a class ))))

to the point:

leonerd:

Is it possible to make two timers in an EA? For some reason, I thought OnTimer() was called in a separate thread. But I tried to add an infinite loop in OnInit() and set the timer before it, only the loop worked, OnTimer() was not called.

I need two independent actions to execute constantly on a timer. Each with its own interval. How this can be implemented, do you know?


#property strict
//--- input parameters
input int      Timer1=13;
input int      Timer2=21;
static int timer1=0,timer2=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   if((timer1++)>Timer1) { timer1 = 0; Print("Timer №1"); }
   if((timer2++)>Timer2) { timer2 = 0; Print("Timer №2"); }
  }
//+------------------------------------------------------------------+