Discussion of article "Create Your Own Trading Robot in 6 Steps!" - page 7

 

I tried to use this article to make my own program,  but it's too complicated for my simple purposes. Here I tried to make a simple program, but the compiler found (only) one error: Class with "no type". And no matter what I put in as a Class "type" or "name" there was no change.

Here is the beginning. What am I doing wrong?:


//|                                                  KaufVerkauf.mq5 |

//|                                             Copyright ....  2012 |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright .... 2012"
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Include                                                          |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>


//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Expert object initialization                              |
//+------------------------------------------------------------------


//---- handles for indicators
int         RSI_handle = 0;           // handle of the indicator iRSI
int         ADX_handle = 0;           // handle of the indicator iADX
int         Force_handle = 0;           // handle for the indicator iForce
int         AD_handle = 0;           // handle for the indicator iAD
int         Close_handle = 0;
int         High_handle = 0;
int         Low_handle = 0;
int         VTick_handle = 0;
int         VReal_handle = 0;
int         sig =0;

                
  double MqlParams[];      // Array for storing indicator params

//+------------------------------------------------------------------+
//| Expert initialization function RSI                               |
//+------------------------------------------------------------------+

Class CExpertSignal

{
private:

int OnInit()
 
//--- creation of the indicator iRSI...........
 
Automated Trading and Strategy Testing
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 

Thanks alot.

I try to test this:

- Download your code, copy to MQL5 and compiled: successful no errors.

- But EA cannot run, it generate an error as below:

  TestMA_Cross (EURUSD,H1)	MA_Cross::CreateFastMA: Error initializing the object of the fast MA

Please help me what wrong with this parameters:

//--- Setting parameters of the fast MA
   MqlParam parameters[4];
//---
   parameters[0].type=TYPE_STRING;
   parameters[0].string_value="Examples\\Custom Moving Average.ex5";
   parameters[1].type=TYPE_INT;
   parameters[1].integer_value=m_period_fast;      // Period
   parameters[2].type=TYPE_INT;
   parameters[2].integer_value=0;                  // Shift
   parameters[3].type=TYPE_INT;
   parameters[3].integer_value=m_method_fast;      // Method of averaging
//--- Object initialization
   if(!m_fast_ma.Create(m_symbol.Name(),m_period,IND_CUSTOM,4,parameters))
     {
      printf(__FUNCTION__+": Error initializing the object of the fast MA");
      return(false);
     }

Once again, thank you alot.

  

 

 

First off all I would like to thank the author(s) for this article.
I'm new to MetaTrader, MQL5 and Forex trading, so these articles are really useful!

When I test this EA, I notice that for closing a long position, it gives a sell signal with a doubled lot size.
Why does it not only close my long position, but directly enters a short at the same signal?
As a first test to understand all the programming, I would like to only go long, so only open and close a long
position without entering a short position at the closing/sell signal.

Thanks in advance.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
 

Good afternoon,

Please advise me how to increase (top up) a position in an Expert Advisor, which is written on the basis of MQL5 Wizard and where positions are opened via

virtual int LongCondition();
virtual int ShortCondition();

I wrote the robot according to the recommendations in the article

https://www.mql5.com/en/articles/367 "create a trading robot in 6 steps" and it works fine, but attempts to influence the position size (no matter whether to increase or decrease)

(no matter whether to increase or decrease) through repeated generation of the condition in , for example in

LongCondition();

does not lead to anything, the already open position is not changed, it can only be deleted by executing the close condition or by triggering sl , tp.

I like the MQL5 Wizard, you can easily and quickly "build" a multi-indicator Expert Advisor, change the sl tracking module, change the money management module.

But my attempt to write an Expert Advisor that opens a minimum position when a condition is formed by one indicator and increases (fills) the position when the trend is confirmed by another indicator.

I came across the above described problem - the already opened position does not change when the signal to open through. e.g. LongCondition() is issued again;

Thank you.

Создай торговый робот за 6 шагов!
Создай торговый робот за 6 шагов!
  • 2012.06.01
  • MetaQuotes Software Corp.
  • www.mql5.com
Вы не знаете, как устроены торговые классы, и пугаетесь слов "Объектно-ориентированное программирование"? На самом деле вовсе не обязательно всё это знать, чтобы написать свой собственный модуль торговых сигналов - достаточно следовать простым правилам. Всё остальное сделает Мастер MQL5, и вы получите готовый торговый робот!
 

If I run this example in the mt5 strategy tester, and choose the asset as pex. Vale5, genetic algorithm, d1, ohlc 1 minute, max balance, it gives an error!

If I run it on a forex pair, the same optimisation seems to complete (I didn't expect it to because it takes too long on the local agent).

The error that appears in the tester's diary, in this case for Vale5, has something to do with OnInit. Has anyone detected the same problem? If so, have you reached any solutions and/or conclusions?

Thanks if anyone can help!

 
fspyna:

If I run this example in the mt5 strategy tester, and choose the asset as pex. Vale5, genetic algorithm, d1, ohlc 1 minute, max balance, it gives an error!

If I run it on a forex pair, the same optimisation seems to complete (I didn't expect it to because it takes too long on the local agent).

The error that appears in the tester's diary, in this case for Vale5, has something to do with OnInit. Has anyone detected the same problem? If so, have you reached any solutions and/or conclusions?

Thanks if anyone can help!

Hi, please provide additional information, such as an error log or screenshots, so we can try to better analyse the problem.

A simple description like the one you gave above doesn't help much in identifying the problem.

Best regards,
Malacarne

 

I do not have any experience (yet) with programming in MQL, but I do have some experience in programming in other languages.  One of the easiest errors to make in programming (my specific class was Java, which is very similar in style to C++ and apparently MQL) is not closing the braces properly.  It is one of the easiest errors to make, and conversely, also one of the harder ones to find.  KJG, as far as the closing a long and heading right into a short, it is probably what this style of EA is designed to do.  I have seen many trading styles with just that type of setup, I believe they were designed for a market that has a lot of volatility and wide price swings happening all the time, like something that would likely happen on a minute time frame chart.

Good article as well.  I definitely will be making use of this one and many others here I am sure.

 
I followed the instructions in steps 1 and 2, but the signal doesn't appear in the Wizard list of available signals. I tried with other signals and none works. Maybe there's a limitation in the number of signals that can be displayed in the wizard. Anyone can help?
 

Good evening,

You are getting the following error when you try to test the robot.

2017.07.04 18:20:27.404 tester stopped because OnInit failed

Am I doing something wrong or is there a setting to make in the robot?

Cheers

Carlos F.

 

The different stages of construction are well explained. It's a clear and useful job, especially for those who have never developed a robot.  Thank you