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

 
SanNneK:
Can you tell me what the condition is, if the chart went down by even one point, then all orders were closed?
The condition is less than or equal to. In ontik you assign the bid price to a global variable. If the bid is less than or equal to the global variable, then it closes the pending orders. Otherwise, the global variable equals the bid.
 
Good evening. Could you please give me the code for the emergency closure of all trades that have just been opened?
 
Can you tell me how I can close all the positions I want at the same time?
 

This way you can close all open trades (MQL4):

for(int i=OrdersTotal()-1; i>=0; i--)
   {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderType()<=OP_SELL)
      {
      OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),(int)SymbolInfoInteger(OrderSymbol(),SYMBOL_SPREAD),OrderType()==OP_SELL?clrRed:clrBlue);
      }
   }
And if you want to selectively, you need to describe the selection condition.
 
О.
 
Aleksei Stepanenko:

This way you can close all open trades (MQL4):

And if you want to selectively, you need to describe the selection condition.

Thank you

 
Igor Makanu:

2020.09.13 08:33:57.508 tst (EURUSD,H1) v1 = 1

2020.09.13 08:33:57.508 tst (EURUSD,H1) v2 = 1.01

2020.09.13 08:33:57.508 tst (EURUSD,H1) v3 = qwerty

2020.09.13 08:33:57.508 tst (EURUSD,H1) v4 = 3.1415

2020.09.13 08:33:57.508 tst (EURUSD,H1) v5 = 777

2020.09.13 08:33:57.508 tst (EURUSD,H1) v6 = 1

2020.09.13 08:33:57.508 tst (EURUSD,H1) v7 = 1.01

2020.09.13 08:33:57.508 tst (EURUSD,H1) v8 = qwerty

2020.09.13 08:33:57.508 tst (EURUSD,H1) v9 = 3.1415

2020.09.13 08:33:57.508 tst (EURUSD,H1) v10 = 777

2020.09.13 08:33:57.508 tst (EURUSD,H1) v11 = Value_11

Is it possible to make predefined variables in a template function so that it is not possible to specify everything when calling it? A simple assignment will still give an error if not all variables are specified.

#define  PRINT(VAL) Print(#VAL," = ",VAL)
template <typename T1, typename T2, typename T3, typename T4, typename T5,
          typename T6, typename T7, typename T8, typename T9, typename T10,typename T11>
void func(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5,
          T6 v6, T7 v7, T8 v8, T9 v9, T10 v10,T11 v11="")//не помогло, но ошибку не вызвало
{
   string s1 = (string) v1; PRINT(v1);
   string s2 = (string) v2; PRINT(v2);
   string s3 = (string) v3; PRINT(v3);
   string s4 = (string) v4; PRINT(v4);
   string s5 = (string) v5; PRINT(v5);
   string s6 = (string) v6; PRINT(v6);
   string s7 = (string) v7; PRINT(v7);
   string s8 = (string) v8; PRINT(v8);
   string s9 = (string) v9; PRINT(v9);
   string s10 = (string) v10; PRINT(v10);
   string s11 = (string) v11; PRINT(v11);
   
   printF( v1,  v2,  v3,  v4,  v5,  v6,  v7,  v8, v9,  v10, v11); // не получается, дает несоответствие типов.
   
}
//+------------------------------------------------------------------+
void OnStart()
{
   func(1, 1.01, "qwerty", 3.1415 f, 777, 1, 1.01, "qwerty", 3.1415 f, 777,"");// любой тип, но нужно указывать все 
                                                                             //переменные
   printF(1, 1.01, "qwerty", 3.1415 f, 777, 1, 1.01, "qwerty", 3.1415 f); //несоответствие типов, но можно не все 
                                                                        //переменные указывать
}
//+------------------------------------------------------------------+
void printF(string v1="", string v2="", string v3="", string v4="", string v5="",
          string v6="", string v7="", string v8="", string v9="", string v10="",string v11="")
{
Print( v1,  v2,  v3,  v4,  v5,  v6,  v7,  v8, v9,  v10, v11);
}
Документация по MQL5: Предопределенные переменные
Документация по MQL5: Предопределенные переменные
  • www.mql5.com
Для каждой выполняющейся mql5-программы поддерживается ряд предопределенных переменных, которые отражают состояние текущего ценового графика на момент запуска программы - эксперта, скрипта или пользовательского индикатора. Значение предопределенным переменным устанавливает клиентский терминал перед запуском mql5-программы на выполнение...
 
Valeriy Yastremskiy:

Is it possible to make predefined variables in a template function

no,it can'T.

I can't explain how.... templates work it's roughly how - until such a function is called, the compiler knows nothing about its existence (often, there are even no compiler errors if there is no call)

then you call such a template function and the compiler fills the needed types and only then checks that everything will work properly

and then you make another call to the template with different types of parameters - and the compiler creates a new function, i.e. another one, i.e. as if you write 2 functions, which do the same thing, but with different types of parameters


whew, that's how it works ))))



UPD:

you can, but if the types in the template match, here's an example, it works correctly:

template<typename T1, typename T2>
int myfunc(T1 val1=0, T2 val2=0)
{
   return((int) (val1 + val2));
}

//+------------------------------------------------------------------+
void OnStart()
{
   int i1 = 2, i2 = 3;
   Print(myfunc(i1, i2));
   double d1 = 10.0, d2 = 30.0;
   Print(myfunc(d1, d2));
}
//+------------------------------------------------------------------+
 
Igor Makanu:

No,you can'T.

I can't explain how.... templates work it's like this - until you call such a function, the compiler knows nothing about its existence (often, there are even no compiler errors if there is no call)

then you call such a template function and the compiler fills the needed types and only then checks that everything will work properly

and then you make another call to the template with different types of parameters - and the compiler creates a new function, i.e. another one, i.e. as if you write 2 functions, which do the same thing, but with different types of parameters


Phew, so it goes ))))

And how do I know the type of input parameter?

If I pass a string type to a template and want to process it further.

The input parameters can be up to 64, any may have any type, how to determine that it is a string ?

 
Vladimir Pastushak:

How do I know the type of the input parameter?

If I pass a string type to a template and want to process it further.

There can be up to 64 input parameters and any of them can have any type, how can I know it is a string ?

typename