Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1384

 

leonerd #:
Здравствуйте. А как программно узнать символ и таймфрейм активного чарта в клиентском терминале? Т.е. чарта выбранного в настоящее время во вкладке. Есть какая-то функция из MQL5 для этого?

long  ChartGetInteger(
   long  chart_id,          // идентификатор графика
   int   prop_id,           // идентификатор свойства
   int   sub_window=0       // номер подокна, если требуется
   );

CHART_BRING_TO_TOP

Display chart on top of all other charts

bool


string  ChartSymbol(
   long  chart_id=0      // идентификатор графика
   );
ENUM_TIMEFRAMES  ChartPeriod(
   long  chart_id=0      // идентификатор графика
   );

How do I define a chart identifier to show too?

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

CHART_BRING_TO_TOP

Display chart on top of all other charts

bool


How do I define a chart ID to show too?

https://www.mql5.com/ru/docs/constants/chartconstants/charts_samples#chart_foreground

Thank you. CHART_FOREGROUND is probably the most suitable. I don't need to set the active chart forcibly, I just need to determine which one is active. Am I right to think that I will have to go through all open charts checking CHART_FOREGROUND ?

Документация по MQL5: Константы, перечисления и структуры / Константы графиков / Примеры работы с графиком
Документация по MQL5: Константы, перечисления и структуры / Константы графиков / Примеры работы с графиком
  • www.mql5.com
Примеры работы с графиком - Константы графиков - Константы, перечисления и структуры - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
leonerd #:

https://www.mql5.com/ru/docs/constants/chartconstants/charts_samples#chart_foreground

Thank you. CHART_FOREGROUND is probably the most suitable. It's not like I need to forcibly set the active chart, but only identify the one that is active. Do I understand correctly that I have to go through all open charts checking CHART_FOREGROUND ?

CHART_FOREGROUND is a chart on top.

And not to enforce it, you should replace ChartSetInteger by ChartGetInteger

 

Good afternoon.
Can you give me a hint - I am thinking about a robot and there are four different conditions - I don't know which ones to remove yet: I want to find out later when optimising for different timeframes.

That is: four conditions (f1,f2,f3,f4). There can be many combinations (0,0,1,1) or (1,0,1,0) and so on - a total of 16 combinations. Exactly 15 - the variant (0, 0, 0, 0) is not considered.

Question: how to create program logic in order not to describe all 15 combinations in the code. There is a function for checking each of these conditions, and in which combinations of these conditions apply - check how else.

I would be glad if you can show me some Expert Advisor, which allows me to enter a lot of conditions in a concise code.

 
qadexys #:

Good afternoon.
Can you give me a hint - I am thinking about a robot and there are four different conditions - I don't know which ones to remove yet: I want to find out later when optimising for different timeframes.

That is: four conditions (f1,f2,f3,f4). There can be many combinations (0,0,1,1) or (1,0,1,0) and so on - a total of 16 combinations. Exactly 15 - the variant (0, 0, 0, 0) is not considered.

Question: how to create program logic in order not to describe all 15 combinations in the code. There is a function for checking each of these conditions, and in which combinations of these conditions apply - check how else.

I would be glad if you show me some Expert Advisor, which allows me to introduce multiple conditions in a concise code.

I may go like this:

input bool F1;
input bool F2;
input bool F3;
input bool F4;

   ...
   if(  ( !F1 || f1)
      &&( !F2 || f2)
      &&( !F3 || f3)
      &&( !F4 || f4)
     )
     {
      open_pos();
     }
   ...

Or something like this:

#define  MODE_f1    0x1
#define  MODE_f2    0x2
#define  MODE_f3    0x4
#define  MODE_f4    0x8

bool expert::create_strategy(ulong m, int om, int cm)
  {
   magic=m;
   open_mode=om;
   close_mode=cm;
   ...
  }

int OnInit()
  {
   ...
   my_strat[i].create_strategy(MAGIC, MODE_f1|MODE_f2|MODE_f4,MODE_c2|MODE_c3);
   ...
  }

expert::check_open()
  {
   ...
   if(  ((open_mode & MODE_f1)==0 || f1)
      &&((open_mode & MODE_f2)==0 || f2)
      &&((open_mode & MODE_f3)==0 || f3)
      &&((open_mode & MODE_f4)==0 || f4)
     )
     {
      open_pos();
     }
   ...
  }
 
Alexey Viktorov #:

CHART_FOREGROUND is the chart on top

And in order not to force it, replace ChartSetInteger with ChartGetInteger

thanks

 
JRandomTrader #:

You could do this:

Or something like this:

And here's the first construction - what would be the behaviour of the code under the conditions (0, 1, 0, 1)?

Could you please explain the body of the If condition

 
qadexys #:

And here is the first construction - what would be the behaviour of the code under (0, 1, 0, 1) conditions?

Could you please explain the body of condition If

It's very simple here. If F1==false, then ( !F1 || f1) will be true regardless of the condition f1.

I.e., if Fn==true, condition fn is checked, and if Fn==false, condition fn is not checked.

Accordingly, for (0, 1, 0, 1) only conditions f2 and f4 will be checked, and if they both hold, the open_pos() code will be executed

 
JRandomTrader #:

This is very simple. If F1==false, then ( !F1 || f1) will be true regardless of condition f1.

I.e., if Fn==true, condition fn is checked, and if Fn==false, condition fn is not checked.

Correspondingly, for (0, 1, 0, 1) only conditions f2 and f4 will be checked, and if they both hold, the code open_pos() will be executed

But for the case when f1 and others are not only 0 or 1. I thought that if condition f1 is satisfied for a short position, then one is returned. If it is for a long position, it returns 2. If the condition is not fulfilled at all - 0.

But in such a construction we probably should not count on such a variety of parameter values and formulate the condition in some other way?

 
qadexys #:

But for the case where f1 and others are not only 0 or 1. Thought that if condition f1 is fulfilled for short position, then one is returned. If for a long position it returns 2. If the condition is not fulfilled at all - 0.

But perhaps we should not count on such a diversity of parameter values in this construct and formulate the condition in some other way, should we?

Sets of conditions for opening long and short are considered separately.

I mean, for example, like this:

 ...
   if(  ( !F1 || f1==1 )
      &&( !F2 || f2==1 )
      &&( !F3 || f3==1 )
      &&( !F4 || f4==1 )
     )
     {
      open_short();
     }
   else if(  ( !F1 || f1==2 )
           &&( !F2 || f2==2 )
           &&( !F3 || f3==2 )
           &&( !F4 || f4==2 )
          )
     {
      open_long();
     }
 ...

I'll even sell a piece of my real code - it won't reveal any know-how without information about "battle" values of variables and conditions of position holding.

You can actually specify one of 224 options here:

   if(true
      && ((OpenMode & MODE_St1)==0 || St_Buf[St_Rq-1]>80)
      && ((OpenMode & MODE_St2)==0 || St_Buf2[St_Rq-1]>80)
      && ((OpenMode & MODE_BB1)==0 || last_tick.bid > bb[BandsReq-1].U)
      && ((OpenMode & MODE_BB2)==0 || last_tick.bid > bb2[BandsReq-1].U)
      && ((OpenMode & MODE_D1)==0  || rt[RtReq-1].high<rt[RtReq-2].high) 
     )
     {
      switch(OpenMode & (MODE_VR|MODE_OR|MODE_A))
        {
         case 0 :
         case MODE_A :
           res=-2;
           break;
         case MODE_VR :
           if((1/VR)>VRO)
             res=-2;
           break;
         case MODE_OR :
           if((1/OR)>VRO)
             res=-2;
           break;
         case MODE_VR|MODE_A :
           if((1/AVR)>VRO)
             res=-2;
           break;
         case MODE_OR|MODE_A :
           if((1/AOR)>VRO)
             res=-2;
           break;
         case MODE_VR|MODE_OR :
           if((1/VR)>VRO && (1/OR)>VRO)
             res=-2;
           break;
         case MODE_VR|MODE_OR|MODE_A :
           if((1/AVR)>VRO && (1/AOR)>VRO)
             res=-2;
           break;
        }
Reason: