Self-learning the MQL5 language from scratch - page 28

 
Vasiliy Sokolov:

That's right! Everyone tries to learn programming using misconceptions about software based on life experience. For example, that a program is like a text in a book with a table of contents, an introduction, a table of contents and a conclusion. That is, the program is a kind of sequential scheme from the beginning to the end. At first stages, this idea works, but then, as the program becomes more complex, difficulties arise, and it is not possible to write a reliable working program in any way. Kovalev is a very good at rendering bearish services: he tries to explain to the reader, using his accessible conceptual apparatus, that the program is the same book with such-and-such a scheme. But there are no schemes! The script has a fundamentally different "scheme" than the Expert Advisor, and the Expert Advisor has a different scheme than the indicator.

So how do you think a person should learn? Right from the PLO philosophy? It is impossible.
 

Vasiliy Sokolov:

... 4) The strangest block is the "error handling" block. You can get into it, but you cannot get out of it. That is, the program caught an error and sits in this block (it must hang until it is completely rebooted, or, better yet, the terminal hangs permanently, for sure it won't make more errors - this is the idea!) ...

Hi Vasiliy! Thank you for the detailed and highly skilled explanation! The only thing I can't agree with is point 4. The fact is that the arrows go both to and from the " Error handling unit". The line connecting this unit to the other has arrows at its ends and from the institute's computer science curriculum I still remember that it means a two-way process, i.e. back and forth. Therefore, I have no doubts about the situation. As for the rest of your message, everything is clear to me.

Regards, Vladimir.

 
MrBrooklin:

Hello Vasily! Thank you for the detailed and highly qualified explanation! The only thing I can't agree with is point 4. The fact is that the arrows go both to and from the "Error handling unit". The line connecting this unit to the other has arrows at its ends and from the institute's computer science program I still remember that it means a two-way process, i.e. back and forth. Therefore, I have no doubts about the situation. As for the rest of your message, everything is clear to me.

Regards, Vladimir.

That's right the first one caught on :-)

Use his expa as a template in your research - competent code!

there and


"The
  • Expert Advisor can be optimized by 'Working
  • timeframe' There
  • can be only one 'enter market' trade per bar (this is an internal parameter, it is not put in the input parameters and it has nothing to do with the 'Only one positions
  • ' parameter)
  • When working in 'inside bar' mode ('Search signals,
  • or equal to '10') the current bar is bar #0, in
  • 'Search signals, in seconds' mode ('Search signals, in seconds
  • ' less than '10') the current bar is bar #1
  • : ' parameter - restriction on which side to trade. Can take on values 'Allowed only BUY positions', 'Allowed only SELL positions' and 'Allowed BUY and SELL positions
  • '
  • Parameter 'Use time control' - time frame for searching trading signals from 'Start Hour':'Start Minute' to 'End Hour':'End Minute'
  • .
  • The 'Pips Or Points:'
  • parameter sets the standard calculation of Stop Loss, Take Profit and Trailing

    и

    Reverse and other stuff and plug standard libraries in the code at the beginning to simplify position opening fie - STUDY AND DON'T WORRY.

    The flag'Positions: Only one' set to'true' allows the Expert Advisor to have no more than one position in the market. The flag'Positions: Reverse' is responsible for reversal of signals. Interesting flag'Positions: Close opposite' - if this flag is set to 'true' before opening a position, it guarantees the deletion of opposite positions.Print log' prints the extended logging of all operations. The'Freeze and StopsLevels Coefficient' parameter defines a coefficient for stop and freeze levels for cases when these levels are equal to zero for a symbol. It is recommended to apply a value of '3'.

    iFractals iAMA
    iFractals iAMA
    • www.mql5.com
    Получать сигнала на откате (по iFractals (Fractals) ), а тренд определять по iAMA (Adaptive Moving Average, AMA). По индикатору iAMA (Adaptive Moving Average, AMA) определяется тренд. Условия тренда: на текущем баре и на двух предшествующих индикатор равномерно растёт (тренд вверх) или равномерно падает (тренд вниз). При этом цена (High или...
     

    I will write principles which I highly recommend to the author for the awareness of what the programme is all about. Unlike Kovalev's leaflets, where some of the material is correct, some contains gross errors, and some is general speculation with the reader, these principles are ALWAYS and 100% correct, no matter what you write in MQL: Expert Advisors, scripts or Expert Advisors:

    First Principle. Any program in MQL handles events. An event is a notification that contains information about something, usually about something that has changed. For example, a new tick has come or our pending order has been executed. Other events do not contain any information, they just happen. For example, the "timer" event can call the user function with a set periodicity. It doesn't notify the user that something has changed. It simply calls the user's code, so it doesn't need any additional information. From the event definition, several non-trivial methods follow:

    • The first implication is that once we receive an event, we should handle it as soon as possible. There can be many events, and events can pile up in a queue. MeteTrader (not our program) handles the events. To do this it uses a special resource called flow. This resource is very valuable and limited. The thread owned by MetaTrader generously executes our crude, sub-optimal and slow code written in a script on the CPU of our PC. If event processing slows down the thread in our code, in some cases other programs running in MetaTrader will not be able to execute properly. They will wait for us to free the thread from our useless calculations and then execute their code on the freed thread.
    • There are many events. We can handle many of the available events or just one. When we make a script, it handles only one event, OnStart, which happens once. When we write an Expert Advisor, it can handle multiple events at once. This means that it is useless to cram your program into the "program this book" paradigm. Instead, we should just understand that the program is a handler of certain events. They may be called in any order, they may not be called at all. The events are independent of each other. So, the parts of the program handling these events do not depend on each other. They are non-linear and not sequential.

    (that's all for now, I'll continue if I feel like it).
    Документация по MQL5: Основы языка / Функции / Функции обработки событий
    Документация по MQL5: Основы языка / Функции / Функции обработки событий
    • www.mql5.com
    В языке MQL5 предусмотрена обработка некоторых предопределенных событий. Функции для обработки этих событий должны быть определены в программе MQL5: имя функции, тип возвращаемого значения, состав параметров (если они есть) и их типы должны строго соответствовать описанию функции-обработчика события. Именно по типу возвращаемого значения и по...
     
    Roman Shiredchenko:

    here's the first one I got for good luck :-)

    Use his expa as a template in your research - competent code!

    there and


    "The
  • Expert Advisor can be optimized by 'Working
  • timeframe' There
  • can be only one 'enter market' trade per bar (this is an internal parameter, it is not put in the input parameters and it has nothing to do with the 'Only one positions
  • ' parameter)
  • When working in 'inside bar' mode ('Search signals,
  • or equal to '10') the current bar is bar #0, in
  • 'Search signals, in seconds' mode ('Search signals, in seconds
  • ' less than '10') the current bar is bar #1
  • : ' parameter - restriction on which side to trade. Can take on values 'Allowed only BUY positions', 'Allowed only SELL positions' and 'Allowed BUY and SELL positions
  • '
  • Parameter 'Use time control' - time frame for searching trading signals from 'Start Hour':'Start Minute' to 'End Hour':'End Minute'
  • .
  • The 'Pips Or Points:'
  • parameter defines the standard calculation of Stop Loss, Take Profit and Trailing

    и

    Reverse and other stuff and connect standard libraries in the code at the beginning to simplify position opening fie - STUDY AND DON'T WORRY, but get used to writing standard code - there's indentation and everything else

    The flag'Positions: Only one' set to'true' allows the Expert Advisor to have no more than one position in the market. The flag'Positions: Reverse' is responsible for reversal of signals. Interesting flag'Positions: Close opposite' - if this flag is set to 'true' before opening a position, it guarantees the deletion of opposite positions.Print log' prints the extended logging of all operations. The'Freeze and StopsLevels Coefficient' parameter defines a coefficient for stop and freeze levels for cases when these levels are equal to zero for a symbol. It is recommended to use the value of '3'.

    Hello Roman! Thank you for the example. Many times I tried to understand the codes written by Vladimir Karputov, but for me it is still an unreachable level. A little later, when I will have more information in my head, it is likely that I will return to his codes. But thanks for the tip!

    Regards, Vladimir.

     
    Vasiliy Sokolov:

    I will write principles which I highly recommend to the author for the awareness of what the programme is all about. Unlike Kovalev's leaflets, where some of the material is correct, some contains gross errors, and some is general speculation with the reader, these principles are ALWAYS and 100% correct, no matter what you write in MQL: Expert Advisors, scripts, or Expert Advisors:

    First Principle. Any program in MQL handles events. An event is a notification that contains information about something, usually about something that has changed. For example, a new tick has come or our pending order has been executed. There are events that have no information but just happen. For example, the event "timer" can call the user function with a set periodicity. It doesn't notify the user that something has changed. It simply calls the user's code, so it doesn't need any additional information. From the event definition, several non-trivial methods follow:

    • The first implication is that once we receive an event, we should handle it as soon as possible. There can be many events, and events can pile up in a queue. MeteTrader (not our program) handles the events. To do this it uses a special resource called flow. This resource is very valuable and limited. The thread owned by MetaTrader generously executes our crude, sub-optimal and slow code written in a script on the CPU of our PC. If event processing slows down the thread in our code, in some cases other programs running in MetaTrader will not be able to execute properly. They will wait for us to free the thread from our useless calculations and then execute their code on the freed thread.
    • There are many events. We can handle many of the available events or just one. When we make a script, it handles only one event, OnStart, which happens once. When we write an Expert Advisor, it can handle multiple events at once. This means that it is useless to cram your program into the "program this book" paradigm. Instead, we should just understand that the program is a handler of certain events. They may be called in any order, they may not be called at all. The events are independent of each other. So, the parts of the program handling these events do not depend on each other. They are non-linear and not sequential.

    (That's all for now, I'll continue if I feel like it).

    Well done Vasily, I'm waiting for the sequel, if you don't mind writing it! Everything you told me was laconic and understandable for me!

    Regards, Vladimir.

     
    MrBrooklin:

    Well done Vasily, looking forward to the sequel, if you don't mind writing it! Everything you reported is concise and understandable for me!

    Regards, Vladimir.

    Yes, interesting judgement.

    1. any program is a hierarchy of function blocks and is a system of related and mutually dependent parameters.

    2. The event is the result of interaction of the program with the external software environment, or internal changes. The environment "informs" about the event by calling the program (OnTick, OnChartEvent...).

    4. The environment (terminal) is neutral to the program, but can influence it.

    5. The program receives information about its environment in the terminal and the market by means of special functions and can use it in its logic.

    6. The program may receive information about itself or its objects by special queries and use it in its logic.

    7. Events are described in if() statements.

    8. Events are handled by handlers reacting to changes.

    9. Reaction may be a change of object(s) state (mass change of their parameters values) or some computing work.

    10. Event handlers are grouped into hierarchical structures (event models).

    11. Software objects may subscribe to various events and be in the list of recipients.

    ... and a lot more... :)

    P.S. Vasiliy will describe it better and more clearly.
     

    Moving on:

    • Since there are many events, there are many event handlers. Since events are called inconsistently, their event handlers are called inconsistently as well. Since there is inconsistent calling, event handlers cannot depend on each other, and they cannot depend on each other's data either. The only construct that meets these strict requirements is a function.
    • Functions cannot depend on each other. If one function returns the sum a+b, and the second returns the product a*b, then the result of these two functions will not depend on the sequence of calls. We can call the first function with arguments 3 and 5 and get 8. Then call the second function with the same arguments and get 24. Then swap their calls. The results will be the same. The addition function will always return 8 with arguments 3 and 5. The multiplication function will always return 24 with the same arguments.
    • It is clear from the above that the event handler can only be a function. If a new tick event occurs, this is handled by the OnTick function. If the Start event (a one-time launch of the script) occurs, this is handled by the special OnStart function.
    • This function is universal. This function can handle not only events. The function can return something useful, e.g., the current time. A function can perform complex calculations with the arguments passed to it and return the final result of these calculations as a single value. Finally, a function can be a data provider: You call the function and get the data you need, such as quotes, from it.
    • Internally, MetaTrader consists of thousands of functions, of which around 1500 thousand are kindly made available to users. These are very useful functions. They allow you to check the system time and obtain the data for an instrument you are interested in. The functions are used to send trade orders. You can open ICL handbook and see that it consists of functions and their arguments. So MetaTrader, as far as user programmes are concerned, is one big set of functions.
    • Universal functions are not enough. No matter how many new functions are added to the system, there will always be shortage of them. The reason is that everyone has different needs. There is no one-size-fits-all feature for all occasions. The most generic and universal features are already included in MetaTrader and are kindly shared with us. However, user needs are endless. MetaQuotes can't meet the individual needs of 100,000 users of their terminal. Instead, they did something more flexible: they let users create the features they want themselves. The users benefited from this. Instead of using a system function which is not suitable for them, they can write their own function which solves their problem perfectly. No system function is perfect because of its universality.
    • The skill a user is able to write his own functions and understand how they work tells you how skilled a programmer is. If he/she understands that a program is a disjointed set of handlers (in the form of functions) that do not consistently handle incoming events, it is good. If he knows how to write his own functions, that's another plus. If he can combine the work of several functions (both his own and system functions) into a common algorithm, that's another plus for him.
    • If you understand that everything in MetaTrader (the fourth and fifth) is somehow based on functions, functions and functions - everything suddenly becomes clear. Help is no longer presented as a thick book with a bunch of scattered code snippets, but as a guide to available functions and what they do. Everything else, like data types, arrays, structures, classes, is irrelevant. It's all about supporting functions so that they can return something and accept something.

    (that's all for now)
     
    You've flooded a newcomer with useless information.)
     
    Реter Konow:
    A beginner is flooded with useless information).

    This suggests that you should not flaunt your desires in such a way. Vladimir might as well have asked questions specifically about this or that function and received useful advice, rather than the nonsense of "experts" like learn C++ or learn assembler. You could start by studying punchcards.