A question for MQL experts - page 14

 

continuation of the question:

The algorithm for such a condition is implemented as follows, here is the filter itself:

//================фильтр   - начало схождения ===================
 if (FILTER_ ) { //если выключатель   фильтра включен
//------------------------------------------------ 
//задаем вычисление ценовых линий на втором   баре
double  MA_11= (iMA(Symbol_1,Period(),per2,0,ma_method,Price,2)-
                iMA(Symbol_1,Period(),per1,0,ma_method,Price,2)) ;  
double  MA_21= (iMA(Symbol_2,Period(),per2,0,ma_method,Price,2)-
                iMA(Symbol_2,Period(),per1,0,ma_method,Price,2))  ;    
double ДЕЛЬТА_MA_2 = MathAbs(MA_11 - MA_21);//разность между ценовыми линиями на 2 баре
//
if (ДЕЛЬТА_MA_2 >=  ДЕЛЬТА_MA) // если линии начинают сходится, разрешаем вход
       Trade_Filter2=true;       else Trade_Filter2=false; 
//-------------------------------------------------                 
         }  // выключатель   фильтра включен
//================== конец блока 2-го фильтра ======================

And here is the entry condition itself:

if  ( TradeDOWN==true  && .... ) {            //если условия соответствуют заданным 
if (Trade_Filter2==true || ! FILTER_ ) {       //  фильтр включен/выключен  
 ..... открвываем позиции: продаем первый инструмент и покупаем второй    

But the Expert Advisor does not seem to see the filter condition! It continues to open positions without paying attention to

if (Trade_Filter2==true || ! FILTER_ ) { .....

I do not understand why. Repeatedly monitored online opening of positions. But the filter does not work! The Expert Advisor does not see it. Please, tell me where it is wrong ?

And another question. What is the correct way to set in global variables (it is the first option at the moment)

bool Trade_Filter2=0; or just bool Trade_Filter2;

 
Rita:

the continuation of the question:

...

Output MA_11, MA_21, DELTA_MA_2 in Coment() and see what's there. Comment() inserted after double DELTA_MA_2...

The MACD is being compared from two different symbols, they can have very different dimensions.

 

There is a comment. The comment is set to "Filter allows (or denies) entry"), like this:

Made this way:

string on_off=StringConcatenate  (on_off,
"1-й(текущий)инстр.=",Symbol_1," 2-й инстр.=",Symbol_2," ",.....
"ДельтаТекущая/ДельтаЗаданная = ", ДЕЛЬТА_MA," / ",ДЕЛЬТА, "\n", 
 "MA_1 ",Symbol_1, "= ", MA_1 , "\n",
 "MA_2 ",Symbol_2, "= ", MA_2 , "\n",

 //--------------------------------------------------------------------------------

if (Trade_Filter2==true && FILTER_==true )  
        string  on_off4 = StringConcatenate (on_off4, "Фильтр Разрешает вход", "\n");
if (Trade_Filter2==false && FILTER_==true )  
        string  on_off41 = StringConcatenate (on_off41, "фильтр Запрещает вход", "\n");
if (FILTER_==false   )  
        string  on_off42 = StringConcatenate (on_off42, "Фильтр Отключен", "\
I visually observe that the lines still diverge and the comment displays "Filter prohibits input"! But the entry is still implemented - the EA does not pay attention to the filter.

The dimensionality of the tools is the same, or (with different dimensionality) - programmatically reduced to the same using coefficients (this is not shown in the code above, not to clutter it up)). That's fine!

 

But double DELTA_MA_2, MA_11, MA_21- are declared below f-i Comment()

But Trade_Filter2 is declared in global variables! So, I think everything is done correctly in the comment!

 
Disable your comment for a while and try to output it from different places. From where you check the filter conditions to where you use it. That way you will find the line where the distortion occurs.
 
OK, thanks, Dimitri! I'll try to use your recommendation after the weekend.
 
Print the values of all your parameters in Print and place it immediately after the order opening operator.
 

Good afternoon. After today's update of mt4 I can't compile EA code. There are 30 strange errors coming out of the compiler.

Could you please tell me why errors suddenly appear on the following lines
code:

if (Trade_Filter2==true && FILTER_==true )  
        string  on_off4 = StringConcatenate ( on_off4, "Фильтр Разрешает вход", "\n");
if (Trade_Filter2==false && FILTER_==true )  
        string  on_off41 = StringConcatenate (on_off41, "фильтр Запрещает вход", "\n");
if (FILTER_==false   )  
        string  on_off42 = StringConcatenate (on_off42, "Фильтр Отключен", "\n");       
'on_off' - undeclared identifier Exp_ARBITR_2Line_Spread_002Mod.mq4 125 35

'on_off4' - undeclared identifier Exp_ARBITR_2Line_Spread_002Mod.mq4 140 47

'on_off41' - undeclared identifier Exp_ARBITR_2Line_Spread_002Mod.mq4 142 47

And how to correct them?

 
if (Trade_Filter2==true && FILTER_==true )  
 {
  string on_off4;
  on_off4 = StringConcatenate ( on_off4, "Фильтр Разрешает вход", "\n");
 }
if (Trade_Filter2==false && FILTER_==true )  
 {
  string on_off41;
  on_off41 = StringConcatenate (on_off41, "фильтр Запрещает вход", "\n");
 }
if (FILTER_== false)  
 {
  string on_off42;
  on_off42 = StringConcatenate (on_off42, "Фильтр Отключен", "\n");
 }

Does it compile like this?

But it's better this way:

string on_off4;
string on_off41;
string on_off42;
if (Trade_Filter2 == true && FILTER_ == true) on_off4 = "Фильтр Разрешает вход\n";
if (Trade_Filter2 == false && FILTER_ == true) on_off41 = "фильтр Запрещает вход\n";
if (FILTER_ == false) on_off42 = "Фильтр Отключен\n";
 
string on_off4, on_off41, on_off42;
if (Trade_Filter2==true && FILTER_==true )  
        on_off4 = StringConcatenate ( on_off4, "Фильтр Разрешает вход", "\n");
if (Trade_Filter2==false && FILTER_==true )  
        on_off41 = StringConcatenate (on_off41, "фильтр Запрещает вход", "\n");
if (FILTER_==false   )  
        on_off42 = StringConcatenate (on_off42, "Фильтр Отключен", "\n");       

If I've telepathised correctly, this should work