Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1304

 
Николай К:

Can you give me a hint? This entry:

var1=(var<10)?1:0;

What it means, how to interpret it, options for use. Parameters.

Read documentation.

Документация по MQL5: Основы языка / Операторы / Условный оператор ?:
Документация по MQL5: Основы языка / Операторы / Условный оператор ?:
  • www.mql5.com
Условный оператор ?: - Операторы - Основы языка - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Николай К:

Can you give me a hint? This entry:

var1=(var<10)?1:0;

What it means, how to interpret it, options for use. Parameters.

If var<10 = true, then var1 = 1
otherwise var1 = 0;

 

Hi! ! Can you please tell me if the code written in MQL5 with OOP elements (CLASSES) will not work in the MQL4 Terminal? When I try to compile a program with classes included, I get errors in parameters passed when calling methods of the class. But the class itself compiles in the 4 editor without errors.


 

Hello, Can you help!

How can I transfer the value of horizontalindicator levelsto my EA?

***

 
Oleg Kolesov:

Hello, Can you help!

How to pass the ID of horizontal levelsof an indicator to an Expert Advisor?

The indicator handle in MQL5 MUST be created in OnInit - and it is created this way ONE time. This is the first thing you need to fix.

 
Vladimir. Created in OnInit(). The Expert Advisor sees the indicator. When visualization, it sends parameters correctly, it draws. It does not want to trade.
 
Oleg Kolesov:
Vladimir. Created in OnInit(). The Expert Advisor sees the indicator. When visualization, it sends parameters correctly, it draws. It does not want to trade.

Insert the code correctly.

 
//+------------------------------------------------------------------+
//|  Настраиваемые параметры                                         |
//+------------------------------------------------------------------+
input string Expert_Title="Exp_Tangents2";                        // The name of the EA
input int Period1=29;                                             // Period1
input int Period2=145;                                            // Period2
input int Period3=609;                                            // Period3
input double level1=46.0;                                         //                                    
input double level2=22.0;                                         //
input double level3=0.0;                                          //
input double level4=-22.0;                                        //
input double level5=-46.0;                                        //
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
// получаем хэндл индикатора Tangents
   HLHandle=iCustom(NULL,0,"Examples\\Tangents2",Period1,Period2,
                      Period3,level1,level2,level3,level4,level5);
// если хэндл неверный
   if(HLHandle<0)
     {
      Alert("Ошибка создания хэнла индикатора Tangents2 - ошибка: ",GetLastError(),"!!");
      return(-1);
     }
   }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//+---------------------------------------------------------------------+
//| Копируем значения индикаторов в массивы, используя хэндлы индикатора
//+---------------------------------------------------------------------+
   if(CopyBuffer(HLHandle,0,0,3,L1)<0 || CopyBuffer(HLHandle,1,0,3,L2)<0
      || CopyBuffer(HLHandle,2,0,3,L3)<0)
     {
      Alert("Ошибка копирования буферов хэндла индикатора Tangents2 - ошибка:",GetLastError(),"!!");
      return;
     }
  }
//+------------------------------------------------------------------+
//|  Проверяет условия на покупку                                    |
//+------------------------------------------------------------------+
bool checkBuy()
  {
   bool dobuy = false;
   if(L2[2]<level1 && L2[1]>level1 && L3[2]<level1 && L3[1]>level1 && (L1[1]>level1 || L1[1]<level5))
           {
            dobuy = true;
           }
   return(dobuy);
  }
 
Oleg Kolesov:

Why copy something twice from buffer '0'?

 
Oleg Kolesov:

Did you remember to flip the arrays you are copying into usingArraySetAsSeries(***,true) ?

Reason: