Features of the mql5 language, subtleties and tricks - page 181

 
Andrey Khatimlianskii:

I usually have 1-2 charts on a terminal like this, it's hard to get confused. But the point is clear.

I trade more symbols, more EAs are running. Monitoring non-tradable symbols yet. Custom symbols are created, Tester is running, etc.

A workhorse, in general.
 
fxsaber:

Trading more symbols, more EAs running. Monitoring non-tradable symbols yet. Custom symbols are being created, Tester is running, etc.

A workhorse, in general.

I have a workhorse only under investor password for all accounts. And it doesn't matter if there are any EAs there or not.

 
trader_number_one:

I only have a workhorse under my invest password for all accounts. And I don't care if there are any advisers in it or not.

Advisors are not just for trading. Moreover, you have to be able to trade on a workhorse.

 
fxsaber:

I have ten Terminals. In turmoil at one, I switched to another account. Time passes, I look at the Terminal and see that I need another account - I switch to the old one. And completely without expecting that the EA is hanging, I see that the EA has started.

will this simple code work with account switching?

bool IsShowMessageBox = true;
//+------------------------------------------------------------------+
int OnInit()
{
   if(IsShowMessageBox && MessageBox("Произвести запуск эксперта?", "Run EA", MB_OKCANCEL) == IDCANCEL) return(INIT_FAILED);
   IsShowMessageBox = false;
   return(INIT_SUCCEEDED);
}


and will the re-login run this code when the connection is interrupted?

 
Igor Makanu:

will a simple code like this work with an account change?

No.

will the re-login when the connection is interrupted trigger this code?

Automatic re-login won't. Manual will.

 

The solution is on the surface. What doesn't change on the graph when you switch it? That's right - the graphical objects. When the robot starts, you create a graphical object, which you delete in DeInit, in the normal situation, respectively, in OnInit check for the object, if it exists, then something went wrong and return INIT_FAILED.

Approximately like this:

#define  NAME "test"

int OnInit()
  {
   static const string symbol=_Symbol;
   if (ObjectFind(0,NAME)>=0||symbol!=_Symbol) return INIT_FAILED;
   else ObjectCreate(0,NAME,OBJ_HLINE,0,0,0);
   return INIT_SUCCEEDED;
  }

void OnDeinit(const int reason){
   switch(reason){
      case REASON_PARAMETERS:
      case REASON_PROGRAM:
      case REASON_REMOVE:
      case REASON_INITFAILED:
      case REASON_CLOSE:
      case REASON_CHARTCLOSE:
      case REASON_TEMPLATE:
      case REASON_CHARTCHANGE: ObjectDelete(0,NAME);
      case REASON_RECOMPILE:
      case REASON_ACCOUNT: break;
   }
}

void OnTick(){
}
 
Vladimir Simakov:

The solution is on the surface. What doesn't change on the graph when you switch it? That's right - the graphical objects. When the robot starts, you create a graphical object, which you delete in DeInit, in the normal situation, respectively, in OnInit check for the object, if it exists, then something went wrong and return INIT_FAILED.

Approximately like this:

saving is not a problem, here in general we need to distribute EA initialization correctly, the case of switching accounts is the least of my worries, but how the chart itself is launched and when the chart is not ready is a mystery covered in darkness ))))

checked reading the commentary... it's not smooth - it's not even visible on the "black screen" when switching between accounts on a non-existent symbol ;)

int OnInit()
{
   string arr_comm[];
   if(StringSplit(ChartGetString(0, CHART_COMMENT), StringGetCharacter(";", 0), arr_comm) == 2) Print("_StopFlag = ", (bool)((int)arr_comm[0]), " ; _UninitReason = ", (int)arr_comm[1]);
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   Comment((string)_StopFlag + ";" + (string)_UninitReason);
}
 
Vladimir Simakov:

The solution is on the surface. What doesn't change on the graph when you switch it? That's right - the graphical objects. When the robot starts, you create a graphical object, which you delete in DeInit, in the normal situation, respectively, in OnInit check for the object, if it exists, then something went wrong and return INIT_FAILED.

This is something like this:

You may as well use global variables of the terminal. They are not deleted either.

 
Konstantin Nikitin:

You might as well use the terminal's global variables. They won't be deleted either.

Tastes and tastes... I don't like them...

 
Vladimir Simakov:

For taste and colour... I don't like them...

For example I delete all objects on VDS. Just that unnecessary not to load the schedule. And there's no need for them there. I use globals. So it all depends on the situation.

Reason: