Discussion of article "Step-by-Step Guide to Writing an Expert Advisor in MQL5 for Beginners" - page 7

 
Renat:

Using uninitialised (or incompletely) variables (especially structures) is a very common mistake in programming.

Man, this is the only Russian-language resource where (1) you are brainwashed and (2) you feel grateful for it :))

For 1.5 years I've known that variables should be initialised; 1.5 years I deliberately use the phrase "structure type variable"; but for 1.5 years I've been assigning values only to separate (mandatory) fields of Mqltraderequest type variable, because the Reference Manual says that " mandatory fields should be specified for each trade operation"....

 
papaklass:
Renat, it would be nice if you (MQ) would publish an article or a series of articles on "working with memory and variables". In general, what is the correct way to work with memory and variables? After disqualification of several EAs at the Championship due to high memory consumption, these articles would be appropriate. Rosh wrote in some thread that users should order articles they are interested in, but I didn't find this thread, so I'm writing here.
Yes, it would be interesting to read an article on this topic. It is very interesting why at the championship some participants had experts using so much memory and how you can avoid such a situation. I didn't have such problems, but it's all random. I mean I don't know why it doesn't happen to me, but I would like to know what to do if it does.
 
First of all, memory consumption is related to indicator calls. Before you create handles of dozens of indicators on different symbols/tpymframes, think about what you will pay for it. I can recommend the article Reducing memory consumption for auxiliary indicators and read the interview of one of the disqualified participants - Interview with Atsushi Yamanaka (alohafx).
Интервью с Ацуси Яманака (alohafx) - Automated Trading Championship 2011
  • championship.mql5.com
Что общего между трейдингом, скайдайвингом, фьючерсами, Гавайями, переводами и шпионами? Мы тоже не знали, пока не пообщались с дисквалифицированным участником Ацуси Яманака (alohafx). Его кредо - ''Life is Good! - Жизнь прекрасна!'', и с этим трудно не согласиться. Было интересно узнать, что расстояние между разными континентами - не помеха в общении участников нашего Чемпионата.
 

Why when tighten the S/L to 5 (supposed to be 5 pips)

I have the following

 

Files:
Capture.PNG  8 kb
 
statarb:

Why when tighten the S/L to 5 (supposed to be 5 pips)

I have the following

 

You should check Stop Levels (SYMBOL_TRADE_STOPS_LEVEL) for a symbol before sending of trade request. The SL/TP mustn't be closer than this distance to current price to close. The sample to get this property:

int StopLevel_Distance=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
double SL=... // get new SL by calculation
//--- check current calculated Stop Loss level
if(SL>SymbolInfoDouble(_Symbol,SYMBOL_ASK)-StopLevel_Distance*_Point) 
   SL=SymbolInfoDouble(_Symbol,SYMBOL_ASK)-StopLevel_Distance*_Point;
//... modify SL for position
 

Thanks, but neither my SL nor my TP are being carried out. In the compiler "Terminal" they are listed as "0.00" or "0.0"  Anyway it's impossible to give a general stoploss for all orders. And I haven't been successful yet in changing the parameter values from "outside", i.e. without changing the code in the editor.

Otherwise it's working great! And the comments are a great help!

Thanks again,

locan BBS

.locan.BBS:

 

Hi Olowsam,

Thanks for this step-bystep guide. I have a few question, which I hope you'll be able to help me with.

        I have followed your instruction to the letter, but have failed to reach the desired result. First of all, I am working with the latest version of Meta Trader 5.00, Build 6.55 (6th June 2012).  I have noted several differences, the 1st being the MQL5 wizard template has extra options, then what you show in your notes. Any way, I have ensured the program is exactly as you have described. I have compiled it. No problems. Zero errors. I have managed to insert all the 5 debug break points as suggested in your notes in the OnTick subroutine. Click the Green Run button & NOTHING happens. The program execution does not get to this point. Why? What's happening? If I insert the debug breakpoints @ the start of OnInit sub, @ say, adzHandle=iADX9Null,0,ADX_Period) line, then this is OK. The debug STEP tabs, light up & I can single step this control all the way to the end of the OnInit sub. However, after that, again nothing. In short, I cannot reach the OnTick sub. What's happening & why? Is this a known bug in the operation of the Meta Trader system? How can I resolve this issue & move on?

I hope the above explains the problem I've had, & hope that you can see what's going on & that you will be able to assist.

Thanks.

Best Regards

Kishor 

 

Hey Great Article,

Typed all the code out as i went along and didnt get any compile errors at the end so must of been well explained. A good excersise for first time using the metatrader5/mql5 system.

Might need to do some optimisation to make the graph go in an upward direction thou :D

All the best, and thanks!!

Mike

 

Hi, 

I really liked the coding style of this article,  very easy to read and follow.  I just have one request if you don't mind, can you also give an example of how to implement trailing stops with this sample?

Thank you very much! 

 
Thank you very much for a wonderful guide!