- [ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3.
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
- Indicator line Color Gaps
Hello.
How much is too much? Is it so much that it can't be broken down into files?
- 2016.03.20
- www.mql5.com
Hello.
Two basic principles:
1. Divide the code into functions. One function should be more or less logically complete and be no more than one screen to be covered in one glance.
2. Reduce the number of global variables. From global variables, it is desirable to use only parameters which do not change while the program is running.
...and more:
3. object-oriented programming.
4. Placing the code into several files (this complicates debugging, but there is a sense in it).
It's very simple: we need to precisely document the individual functions and allocate them into a separate file. The main file will immediately become smaller and more readable
I always have one mq4/mq5 file and a bunch of mqh files with classes, for each class a separate file. In general, this is how they do it in industrial development. No kilometer-long files where everything is mixed up.
Sometimes you can see a masterpiece where the entire EA is packed into OnTick with the same pieces of code for opening orders 20 times each in this ugly sheet. I want to take out the puke bag right away ))
Hello.
Do not write functions that are always constant and never change in this style
void CloseOrders(int cmd) { for(int i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderType()==OP_BUY && cmd==OP_BUY) { if(!OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue)) { Print("Order BUY not close! Error = ",GetLastError()); } } if(OrderType()==OP_SELL && cmd==OP_SELL) { if(!OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red)) { Print("Order SELL not close! Error = ",GetLastError()); } } } } } }
Write them concisely, no one ever looks at them anyway, and they take up half as much space.
void CloseOrders(int cmd) { for(int i=OrdersTotal()-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) { if(OrderType()==OP_BUY && cmd==OP_BUY) { if(!OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue)) Print("Order BUY not close! Error = ",GetLastError()); } if(OrderType()==OP_SELL && cmd==OP_SELL) { if(!OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red)) Print("Order SELL not close! Error = ",GetLastError()); } }}}}
Comment on the code all the time, what this piece of code is responsible for, it is not difficult, and now you will always know what the code is, and reduce the time to study it
Don't write functions that are always constant and never change in this style
Write them concisely, no one ever looks at them anyway, and they take up half as much space.
Comment on the code all the time, what this piece of code is responsible for, it's not difficult, and now you will always know what the code is, and reduce the time to study it
The comment must occupy half of the text of the program
Don't write functions that are always constant and never change in this style
Write them concisely, no one ever looks at them anyway, and they take up half as much space.
Comment on the code all the time, what this piece of code is responsible for, it's not difficult, and here in the revision will always know what the code, and reduce the time to study it
Rearranging parentheses does not make the lag less. Before giving advice, at least raise your level to an average one.
The commentary should occupy half of the programme text
No, well, then 90% of the code is comments. And you need as much pointless and poorly readable code as possible, so that you can put more comments!
Your ideas are also noteworthy. You should discuss them more often
I've been meaning to ask for a long time. If in mcl5 you get indicator data from include files, classes, will the optimization be faster?
That is, no indicator handles are called in the code of the Expert Advisor itself.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use