Discussion of article "MQL5 Wizard: How to Create a Module of Trading Signals"

 

New article MQL5 Wizard: How to Create a Module of Trading Signals is published:

The article discusses how to write your own class of trading signals with the implementation of signals on the crossing of the price and the moving average, and how to include it to the generator of trading strategies of the MQL5 Wizard, as well as describes the structure and format of the description of the generated class for the MQL5 Wizard.

Figure 1. The structure of the CExpert base class

Author: MetaQuotes

 
Gentlemen Comrades! I read the article! I did everything as written in it, well I think now I will get to heaven. But no - Master MKL 5 did not see my file with signals. I checked everything again, did it all again, checked again, but the signal is not visible in the wizard of creating Expert Advisors. I attach my file, which I created in accordance with the recommendations in the article. Help me to understand what I did wrong or on the contrary, the author of the article did not add something important, because of which it does not come together in any way. In short, help me in any way you can.
Files:
 
Tincup:
Gentlemen Comrades! I read the article! I did everything as written in it, well I think now I will get to heaven. But no - Master MKL 5 did not see my file with signals. I checked everything again, did it all again, checked again, but the signal is not visible in the wizard of creating Expert Advisors. I attach my file, which I created in accordance with the recommendations in the article. Help me to understand what I did wrong or on the contrary, the author of the article did not add something important, because of which it does not come together in any way. In short, help me in any way you can.


Theclass descriptor is an important part of the source text.

There are two obvious errors in your descriptor. One of them prevents you from detecting the signal because a non-existent ENUM is specified. The second one will cause problems during compilation (incorrect parameter name).

One more subtlety. There should be only one space before the keyword, in each descriptor line. (I think this restriction will be removed in the future, but for now it is like this).

// wizard description start
//+---------------------------------------------------------------------------+
//| Description of the class                                                |
//| Title=Сигнал пересечению ценой скользящей средней                     |
//| Type=Signal                                                             |
//| Name=Sample                                                             |
//| Class=CSampleSignal                                                     |
//| Page=                                                                   |
//| Parameter=PeriodMA,int,12                                                |
//| Parameter=ShiftMA,int,0                                                  | было SniftMA
//| Parameter=MethodMA,ENUM_MA_METHOD,MODE_EMA                               |
//| Parameter=AppliedMA,ENUM_APPLIED_PRICE,PRICE_CLOSE                      | было ENUM_MA_APLLIED_PRICE
//| Parameter=Limit,double,0.0                                               |
//| Parameter=StopLoss,double,50.0                                           |
//| Parameter=TakeProfit,double,50.0                                         |
//| Parameter=Expiration,int,10                                              |
//+---------------------------------------------------------------------------+
// wizard description end


Further on the text.

Not having a constructor is bad. You should initialise member-data with default values. After all, in the general case, the method of setting a parameter may not be called.

And lastly, the methods are incorrectly described

   void     LimitMA (int value)                    {m_limit=value;}
   void     StopLoss (int value)                   {m_stop_loss=value;}
   void     TakeProfit (int value)                 {m_take_profit=value;}

must

   void     LimitMA (double value)                    {m_limit=value;}
   void     StopLoss (double value)                   {m_stop_loss=value;}
   void     TakeProfit (double value)                 {m_take_profit=value;}

 

Thank you very much for your reply, of course. I fixed everything and it worked.

But when compiling the Expert Advisor itself, it gave me an error, which I would not have found by myself if the compiler had found it. By the way, when you were answering me, you must have fixed it unnoticeably for yourself, but it is there in the original text of the article.

In the article.

  void               Limit(double value)                 { m_limit=value;                  }

in response to my request for help

  void               LimitМА(double value)                 { m_limit=value;}

absence of MA in the signal file, when compiling the Expert Advisor itself after its successful generation, it generates the following error

'Limit' - member function is not defined 123456.mq5 77 11
1 error(s), 0 warning(s) 2 1

Following in my case at least in line 77 we see

signal.Limit(Inp_Signal_Sample_Limit);

insert MA after the word Limit

The error in the Expert Advisor text disappears.

If I am wrong, I apologise. I am not a professional.

 
And accordingly, the description should not be Limit, but LimitMA.
 

And one more thing: this error comes up no matter what:

'--' - l-value required 1234.mq5 31 57

'--' - l-value required 1234.mq5 31 59
'--' - l-value required 1234.mq5 31 61
'--' - l-value required 1234.mq5 31 63
'--' - l-value required 1234.mq5 31 65
'--' - l-value required 1234.mq5 31 67
'--' - l-value required 1234.mq5 31 69
'--' - l-value required 1234.mq5 31 71
'--' - l-value required 1234.mq5 31 73
'--' - l-value required 1234.mq5 31 75
'--' - l-value required 1234.mq5 31 77
'--' - l-value required 1234.mq5 31 79
'--' - l-value required 1234.mq5 31 81
'--' - l-value required 1234.mq5 31 83
'--' - l-value required 1234.mq5 31 85
'--' - l-value required 1234.mq5 31 87
'--' - l-value required 1234.mq5 31 89
'--' - l-value required 1234.mq5 31 91
'--' - l-value required 1234.mq5 31 93
'--' - l-value required 1234.mq5 31 95
'--' - l-value required 1234.mq5 31 97
'--' - l-value required 1234.mq5 31 99
'--' - l-value required 1234.mq5 31 101
'--' - l-value required 1234.mq5 31 103
'--' - l-value required 1234.mq5 31 105
'--' - l-value required 1234.mq5 31 107
'--' - l-value required 1234.mq5 31 109
'--' - l-value required 1234.mq5 31 111
'--' - l-value required 1234.mq5 31 113
'--' - l-value required 1234.mq5 31 115
'-' - operand expected 1234.mq5 31 117
'Inp_Signal_Sample_Expiration' - undeclared identifier 1234.mq5 77 22
32 error(s), 0 warning(s) 33 1

Go to line 31 of the EA to see the following

input double Inp_Signal_Sample_StopLoss =50.0;
input double Inp_Signal_Sample_TakeProfit=50.0;
input int Inp_Signal_Sample_Expiration=10-------------------------------------------------------------;
//--- inputs for money
input double Inp_Money_FixLot_Percent =10.0;

input double Inp_Money_FixLot_Lots =0.1;

Remove the tail in the form of a dotted line coming from 10 and all errors disappear.

The Expert Advisor is ready to work and optimise.

Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Стили рисования
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Стили рисования
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы индикаторов / Стили рисования - Документация по MQL5
 
Tincup:
Yes, and accordingly, the description should not be Limit, but LimitMA as well

Yes, LimitMA, I looked it up.

In general, for the future... When creating a class descriptor, use copypaste more actively, because the compiler does not check comments (which make up the descriptor), and coincidence of method names and parameter names of the descriptor is important. This "comes out" only when compiling the Expert Advisor and causes negative emotions. Although, as you can see, it is nothing fatal.

 
Tincup:

And one more thing: this error comes up no matter what:

'--' - l-value required 1234.mq5 31 57

This error occurs because of the length of the class descriptor string. After the holidays, we will sort it out.
Документация по MQL5: Основы языка / Типы данных / Тип string
Документация по MQL5: Основы языка / Типы данных / Тип string
  • www.mql5.com
Основы языка / Типы данных / Тип string - Документация по MQL5
 
Good stuff... well written and certainly an eye opener.
 

Good afternoon!

  1. There is a misprint in the attached file, if I am not confused! In the description of the CheckOpenLong function in the lines for calculating the sl and tp variables, the signs should be reversed.
  2. I changed the CheckOpenLong function as follows:
    bool CSampleSignal::CheckOpenLong(double& price,double& sl,double& tp,datetime& expiration)
      {
    
       Print("Close(0)=",DoubleToString(Close(0),5)," Close(1)=",DoubleToString(Close(1),5));
       Print("Open(0)=",DoubleToString(Open(0),5)," Open(1)=",DoubleToString(Open(1),5));
       Print("MA(0)=",DoubleToString(MA(0),5)," MA(1)=",DoubleToString(MA(1),5));
    
       return(false);
       
      }
    i.e. it should simply output the values of Close, Open and MA for the last and previous bar. So if the value of EveryTick is false, then everything works as it should, but if true - instead of values, it outputs zeros! Can you tell me what's wrong? What am I doing wrong?

Thank you!

 
lVlaxim:

Good afternoon!

  1. There is a misprint in the attached file, if I am not confused! In the description of the CheckOpenLong function in the lines for calculating the sl and tp variables, the signs should be reversed.
  2. I changed the CheckOpenLong function as follows:i.e. it should just output the values of Close, Open and MA for the last and previous bar. So if the value of EveryTick is false, then everything works as it should, but if it is true - instead of the values it outputs zeros! Can you tell me what's wrong? What am I doing wrong?

Thank you!

On point 1, thanks for finding the error. It will be fixed.

On item 2, there was a small inconsistency with MQL5, fixed. It should appear in the next build.