[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 609

 

Hello again everyone.

How to make a time delay in an EA before opening a new trade after the end of a previous trade.

I.e. the deal ended t/p and after that I need to wait for example 15 minutes and only then the formula will go on working:)

Found

OrderCloseTime( )
I found it, but how to connect it to program time and to avoid conflicts with EA's history run. Thanks in advance
 
Tragedy:

Hello again everyone.

How to make a time delay in an EA before opening a new trade after the end of a previous trade.

I.e. the deal ended t/p and after that I need to wait for example 15 minutes and only then the formula will go on working:)

Found

OrderCloseTime( )
But how do I link this to the program time, and so that there is no conflict with running the EA through the history. Thanks in advance


https://www.mql5.com/ru/forum/131859

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает количество секунд после открытия последней позиций. |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
datetime SecondsAfterOpenLastPos(string sy="", int op=-1, int mn=-1) {
  datetime t;
  int      i, k=OrdersTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderOpenTime()) t=OrderOpenTime();
            }
          }
        }
      }
    }
  }
  return(TimeCurrent()-t);
}
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает количество секунд после закрытия последней позиций. |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
datetime SecondsAfterCloseLastPos(string sy="", int op=-1, int mn=-1) {
  datetime t;
  int      i, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) {
              if (t<OrderCloseTime()) t=OrderCloseTime();
            }
          }
        }
      }
    }
  }
  return(TimeCurrent()-t);
}
 
Prompt:) Thank you
 
rigonich:

int iHighest( string symbol, int timeframe, int type, int count=WHOLE_ARRAY, int start=0)
Returns the index of the highest value found (offset relative to the current bar).
Parameters:
The value is returned as thevalue of the highest bar:

int iHighest( string symbol, int timeframe, int type, int count=WHOLE_ARRAY, int start=0)
Returns the index of the highest value found (offset relative to the current bar).
Parameters:
symbol - Symbol name of the symbol, the data of which will be searched. NULL means current symbol.
timeframe - Period. Can be one of the periods of a chart. 0 indicates the period of the current chart.
type - The identifier of the timeseries. Can be any of the timeseries identifiers.
count - Number of elements of the timeseries (in the direction from the current bar to the ascending index), among which the search should be performed.
start - The index (offset from the current bar) of the start bar from which the search for the highest value will start. Negative values are ignored and replaced by zero values.
The question is how to specify that the search should be performed before the bar above which the fractal appeared and if the period is less than one minute..... how should it be done?
 

I'm sorry,

that would be great. I've looked through the tutorial on global variables, I understand that this is what I need, but I don't understand the nuances. Where to declare them, how to write the right values into them, etc.

If there are, for example, 5 EAs hang in the terminal on 5 different pairs and each EA has 4 variables that need to be written, it means that we need 20 global variables and they must be named somehow using the Symbol() command so that I don't have to write each name in the EA.

All in all, it is not for my brain yet((

 
i999i:



Remember the opening time of the bar where the last fractal was set, use it to find the number of this bar. if the period is less than a minute........, how is that? If the period of the chart, less than a minute is simply not there.
 
i999i:

Thanks for the reply, but what I meant was how to know if the current fractal has been broken or not before the next fractal appears

If you look for the price of a fresh fractal (you may scroll the mouse wheel on this page), then you will know if this fractal is broken through. My profile has links to the B. Williams ProfitUnity expo. I wrote it myself. Now I trade by reverse signals, in the direction of price returning to its moving average.
 
xant:

I'm sorry,

that would be great. I've looked through the tutorial on global variables, I understand that this is what I need, but I don't understand the nuances. Where to declare them, how to write the right values into them, etc.

If there are, for example, 5 EAs hang in the terminal on 5 different pairs and each EA has 4 variables that need to be written, it means that we need 20 global variables and they must be named somehow using the Symbol() command so that I don't have to write each name in the EA.

All in all, it's not for my brain yet((

If I don't have enough brains for Global Variables of the terminal, then about writing them into a file too...

double Var1, Var2, Var3, Var4;  // 4-ре переменных для сохранения (у Вас они свои !!!)
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);
//----
}
// в init()
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);
//----
}

But, there's a first time for everything. fSave_MineGV() inside start() and fGet_MineGV() inside init().

I hope you'll figure it out, and write your save variables instead of Var1, etc.
 
xant:

I'm sorry,

that would be great. I've looked through the tutorial on global variables, I understand that this is what I need, but I don't understand the nuances. Where to declare them, how to write the necessary values in them, etc.

If there are, for example, 5 EAs hang in the terminal on 5 different pairs and each EA has 4 variables that need to be written, it means that we need 20 global variables and they must be named somehow using the Symbol() command so that I don't have to write each name in the EA.

Well, it's not for my brain yet((

The variables you need is really 20, you don't want to write them in your EA, make it a separate file, there are preprocessor commands for predefining constants, and for a beginner it is much easier to work with global variables, than with files, but of course you are the boss.

string perem = "peremEURUSD-1";
string perem = "peremEURUSD-2";
double A;
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
GlobalVariableSet(peremEURUSD-1,2.5); //create or assign a new value
A=GlobalVariableGet(peremEURUSD-1); //thereby read value
if(GlobalVariableGet(peremEURUSD-1)==....) //check this way
return(0);
}

//+------------------------------------------------------------------+

P.S. It's better to predefine variables (for a currency pair) once init.

 

rigonich,

why, in the EA I just want to, I thought on the contrary that recording files is easier.

TarasBY ,

Thank you, it's all clear, I'll try it, I think it will work.

Reason: