Download MetaTrader 5

MQL5: Adviser not trading what is wrong?

To add comments, please log in or register
Martin
27
Martin  

Hi

My adviser does not want to trade. It compiles without errors but for the love of me doesn't open or close a trade.

What an i doing wrong.

Take note this is my first attempt so i might have missed some functionality.

Any advise would be appreciated.

Files:
DXO.mq5 7 kb
Fernando Carreiro
2956
Fernando Carreiro  
Martin: My adviser does not want to trade. It compiles without errors but for the love of me doesn't open or close a trade. What an i doing wrong. Take note this is my first attempt so i might have missed some functionality. Any advise would be appreciated.

Yikes! You are mixing apples, oranges, carrots, tomatoes, turnips and anything else under the sun!

Before considering coding an EA, you need first decide which language you want to learn and use (either MQL4 or MQL5), and after that, at least learn the structure of the functionality of an EA by looking at examples and reading the documentation.

Currently, your code mixes elements from MQL4 (old style), MQL4+ (new style) and MQL5.

  • ".mq5" extension - meaning you are targeting MQL5 for MetaTrader 5
  • #include <Trade\Trade.mqh> - Using MQL5 classes for Trading Operations
  • init(), deinit(), start() - Old Style MQL4
  • OnInit(), OnTick() New Style MQL4+ or MQL5
  • OnTrade() - MQL5 (but has nothing to do with OnTick)
  • iMA() - the way you are using it is MQL4 (not MQL5)
  • etc.

Suffice to say, that as it stands now, there is no correct basic skeleton structure, on which to build on!

Martin
27
Martin  
Fernando Carreiro:

Yikes! You are mixing apples, oranges, carrots, tomatoes, turnips and anything else under the sun!

Before considering coding an EA, you need first decide which language you want to learn and use (either MQL4 or MQL5), and after that, at least learn the structure of the functionality of an EA by looking at examples and reading the documentation.

Currently, your code mixes elements from MQL4 (old style), MQL4+ (new style) and MQL5.

  • ".mq5" extension - meaning you are targeting MQL5 for MetaTrader 5
  • #include <Trade\Trade.mqh> - Using MQL5 classes for Trading Operations
  • init(), deinit(), start() - Old Style MQL4
  • OnInit(), OnTick() New Style MQL4+ or MQL5
  • OnTrade() - MQL5 (but has nothing to do with OnTick)
  • iMA() - the way you are using it is MQL4 (not MQL5)
  • etc.

Suffice to say, that as it stands now, there is no correct basic skeleton structure, on which to build on!

Hi

Thank you for the feedback. 
Seems like i need another look at my code. If you maybe have a good resource other than the manual i would appreciate it a lot.

I find the manual quite complicated at the moment.

Maybe a few link to good videos i believe would benefit a lot of new developers.


Fernando Carreiro
2956
Fernando Carreiro  
Martin: Seems like i need another look at my code. If you maybe have a good resource other than the manual i would appreciate it a lot. I find the manual quite complicated at the moment. Maybe a few link to good videos i believe would benefit a lot of new developers.

How about some books? Have a look at the following post from another thread:

Forum on trading, automated trading systems and testing trading strategies

Account Management

Fernando Carreiro, 2017.09.09 08:47

I think you should first concentrate on learning the basics of the language, its structure, its syntax, code layout and readability, etc.

Then learn about the various functions that are available, how they work and how to use them properly.

The code you provided, will not even compile, because you are basically mixing apples, oranges, tomatoes, carrots, and anything else that fits in the basket.

For example, the OrderSelect() function is for selecting a particular Order either by Index or by Ticket Number. It does not by itself return the number of Orders of a certain type.

So, before you even think about "professional account management", first you need to learn the language, by reading the documentation and researching the example code in the CodeBase.

If you want or prefer, you can even get yourself a good book and follow it from start to end:

Martin
27
Martin  
Fernando Carreiro:

How about some books? Have a look at the following post from another thread:

Hi 
I think since this is something i want to do going forward i will get the book and get the required knowledge.

Thanks.
To add comments, please log in or register