[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 619

 
xant:

rigonich

Well, it's finally starting to make sense. So, the short strings in curly braces are function calls, and the functions themselves need to be placed somewhere.

Now in order.

I add a call of the first function to the init, I do it immediately after starting the init function, i.e. just like this, it will be correct, right?

Similarly, I add the call of the second function to the start block. If I do this immediately after the calculation of the variables, would this be correct? For example like this:

Are these first 2 steps correct?

Well, I actually told him thanks for that right away.


Almost. In the inite remove the first { that you had before inserting the call, in the start -- both{} before and after the call. Now you only need to copy the function code, put it after all your EA code and compile the EA.

Sorry, my mistake, it's hard when there's no code in front of my eyes.There you go.

int init()
{
fGet_MineGV();
//... и далее мой код, который был ранее (без первой { )
 

rigonich

I removed the brackets to leave an even number of brackets. That is, both functions are inserted without curly brackets.

The result is as follows:

int init()
{
    fGet_MineGV();
//... и далее мой код
//...разрыв кода...
if ((SUA==100)&&(zigNN>4.5))
{
BUA=0;
BUA1=0;
}

fSave_MineGV();
//... продолжение моего кода...

Then after all the EA code I inserted

}
}
}


Comment(fd+f+d);

}
//... тут мой советник закончился


        void fGet_MineGV (string fs_PrefName = "") // префикс имени переменной
     {
        string ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_1");
        if (GlobalVariableCheck (ls_Name)) SUA = GlobalVariableGet (ls_Name);
        ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_2");
        if (GlobalVariableCheck (ls_Name)) SUA1 = GlobalVariableGet (ls_Name);
        ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_3");
        if (GlobalVariableCheck (ls_Name)) BUA = GlobalVariableGet (ls_Name);
        ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_4");
        if (GlobalVariableCheck (ls_Name)) BUA1 = GlobalVariableGet (ls_Name);
     }
               
      void fSave_MineGV (string fs_PrefName = "") // префикс имени переменной
{
 static datetime ldt_NewBar;
 datetime ldaTBeginBar = iTime (Symbol(), 1, 0)
 //---- Сохраняемся в начале каждой минуты
 if (ldt_NewBar == ldaTBeginBar) return;
 ldt_NewBar = ldaTBeginBar;
 //---- Сохраняем поочереди значения каждой переменной
 string ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_1");
 GlobalVariableSet (ls_Name, SUA);
 ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_2");
 GlobalVariableSet (ls_Name, SUA1);
 ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_3");
 GlobalVariableSet (ls_Name, BUA);
 ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_4");
  GlobalVariableSet (ls_Name, BUA1);
}

I take it so, after the last curly bracket, in fact, separately from the EA. Is it correct?

If it's right, then this is what you get after compilation:

'fGet_MineGV' - function already defined and has a body         K:\TEST\experts\01___AUDUSD.mq4 (1679, 14)
'ls_Name' - variable already defined                            K:\TEST\experts\01___AUDUSD.mq4 (1681, 16)
2 error(s), 0 warning(s)        

Извиняюсь, ошибся, сложно, когда нет кода пнред глазами.Вот так.
If the code were short, I would post it here and all my problems would be solved quickly. BUT the EA has 1700 lines, plus 3 more external indicators, in which most of the calculation is done... So only by mail, but it's obviously not done for free anymore.
 
xant:

rigonich

I removed the brackets to leave an even number of brackets. That is, both functions are inserted without curly brackets.

The result is as follows:

Then after all the EA code I inserted

I take it so, after the last curly bracket, in fact, separately from the EA. Is it correct?

If it's right, then this is what you get after compilation:


These warnings say that the function and variable in your EA have already been defined before. see if you forgot to delete the code you inserted before? if not -- send me the owl code and I'll paste the functions into it for you.
 
lottamer:


Exactly. You must first take the ticket of the last closed position GetTicketLastPos , and then use the standard functions to take out what you need from this ticket.

Thank you.


Darn... there's no such function as GetTicketLastPos,

there isa GetTicketLastPos ticket for the last open position...

 
xant:

rigonich

I removed the brackets to leave an even number of brackets. That is, both functions are inserted without curly brackets.

The result is as follows:

Then after all the EA code I inserted

I take it so, after the last curly bracket, in fact, separately from the EA. Is it correct?

If it's right, then this is what you get after compilation:

If the code were short, I would have posted it here and all my problems would have been solved quickly. BUT the EA has 1700 lines, plus 3 more external indicators, in which most of the calculation is done... So only by mail, but it's obviously not done for free anymore.

I think this makes more sense:

//+------------------------------------------------------------------+
//|                                                       Priner.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"


double Var1, Var2, Var3, Var4;// 4-ре переменных для сохранения (у Вас они свои !!!)
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   fGet_MineGV();
//----
//Здесь ваш код
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   //Здесь ваш код
//----
   fSave_MineGV();
   return(0);
  }
//+------------------------------------------------------------------+
void fSave_MineGV (string fs_PrefName = "")     // префикс имени переменной
  {
    static datetime ldt_NewBar;
    datetime ldaTBeginBar = iTime (Symbol(), 1, 0);
//----
    //---- Сохраняемся в начале каждой минуты
    if (ldt_NewBar == ldaTBeginBar) return;
    ldt_NewBar = ldaTBeginBar;
    //---- Сохраняем поочереди значения каждой переменной
    string ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_1");
    GlobalVariableSet (ls_Name, Var1);
    ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_2");
    GlobalVariableSet (ls_Name, Var2);
    ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_3");
    GlobalVariableSet (ls_Name, Var3);
    ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_4");
    GlobalVariableSet (ls_Name, Var4);
//----
  }
void fGet_MineGV (string fs_PrefName = "")     // префикс имени переменной
  {
    string ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_1");
//----
    //---- Восстанавливаем значения переменных
    if (GlobalVariableCheck (ls_Name)) Var1 = GlobalVariableGet (ls_Name);
    ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_2");
    if (GlobalVariableCheck (ls_Name)) Var2 = GlobalVariableGet (ls_Name);
    ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_3");
    if (GlobalVariableCheck (ls_Name)) Var3 = GlobalVariableGet (ls_Name);
    ls_Name = StringConcatenate (fs_PrefName, Symbol(), "_N_4");
    if (GlobalVariableCheck (ls_Name)) Var4 = GlobalVariableGet (ls_Name);
  }  
//----
 
lottamer:


crap...there is no such function asa ticket for the last closed position,

there isa GetTicketLastPos ticket for the last open position...


the ticket of the last closed position is in the history.
 
не забыли ли вы удалить код, который вставляли раньше? если нет -- пришлите мне код сова и я вам вставлю в него функции.

Maybe there really is one left somewhere.

I inserted it into another, clean EA, which didn't have my experiments, and it gave out other errors:

'if' - too complex expression     K:\test2\experts\02___AUDUSD.mq4 (1664, 2)
'=' - assignment expected         K:\test2\experts\02___AUDUSD.mq4 (1662, 24)
'if' - semicolon expected         K:\test2\experts\02___AUDUSD.mq4 (1664, 2)
3 error(s), 0 warning(s)        

Anyway, I email ed

 

I'm looking carefully - I've done exactly as you've written.

But I have no return or deinit in my EA. Is it all right? I still get errors.

 
xant:

I'm looking carefully - I've done exactly as you've written.

But I have no return or deinit in my EA. Is it all right? I still get errors.

TarasBY respondent, but there is a small error in his code, that's why the compiler complains about it.

In my post, there's no cussing.
 
rigonich:

the last closed ticket is in history.


Can you teach me how to access the history?

how do I get the last ticket out of there?

Reason: