Self-learning the MQL5 language from scratch - page 69

 
MrBrooklin:

If the MQL5 programming language handbook had written it like this straight away:

then there wouldn't be so many unnecessary questions. At least, beginners would have fewer questions.

Sincerely, Vladimir.

Everything is well written there. If there are no parentheses, then the for statement refers only to the next expression.
You're not stupid, try to find someone at your age, who will study programming from scratch.
 
Aliaksandr Hryshyn:
Everything is well written there. If there are no parentheses, it means that the for operator refers only to the next expression.
And don't say that he is stupid, try to find someone of your age who will learn programming from scratch from scratch.

Vladimir did not say that he is dumb, he is having a hard time because the time-limited express method of learning is not easy.

He grabbed the "tools" without reading and understanding the "instructions for use", and he had already been told about it; having understood the syntax it would be much easier to put the "puzzle" together.

And it's never too late to learn, if you want to, there are examples of defending a dessert or learning foreign languages at 65, for example...

 
MrBrooklin:

Igor, the desire to learn MQL5 language has not disappeared, on the contrary, it has only intensified. I'm just torn, why I'm so dumb and cannot understand simple things with this loop operator

You are not dumb, but impatient. You are trying to learn "the English language" with a dictionary - you are trying to put foreign words into the combinations you want, without considering that linguistic structures may be different.

I mean, you have to learn the syntax and the basics of C programming, but you won't be able to write anything useful .... Besides this "mysterious" for statement, there will be a misunderstanding... e.g. scope of variables? - understand what it is? - It's not hard, but you have to understand what the machine sees when it reads your program.


i don't know what tutorial i can advise you. i sometimes look up sharp herehttps://metanit.com/sharp/tutorial/1.1.php

there's also C and C++https://metanit.com/cpp/

If you use it, you may skip sections about pointers and classes and OOP. You don't need to learn it, you just need to organize (systematize) your knowledge.

 
MrBrooklin:

Igor, the desire to learn MQL5 language is not lost, on the contrary, it is only getting stronger. I'm just torn, why I'm so dumb and cannot understand simple things with this loop operator. The main thing is that without the loop operator the code works perfectly, but with the loop it is a complete mess. I will get to the bottom of this anyway. However I've got much less time for self-study since the quarantine period is over and I've got rare moments at work when I can study the language. Mostly I study the language in the evening and late at night.

I need to solve 2 tasks to finally get down to writing the Trailing Stop code:

  1. I need to write a code with the use of the for loop operator to search all open positions for all symbols, and if there are none, then open a Buy position between 09:00:00 and 09:01:00, and close it by force at 23:50:00, if during the trading day a stop loss did not trigger. Without the for loop operator, as I wrote before, everything works perfectly. Now I want to achieve the same result, but with using loop.
  2. Write 2 functions that determine the direction of position opening by the first tick that appears in the time frame from 09:00:00 to 09:01:00. If the first tick is upwards, a Buy position should open; if the first tick is downwards, the Sell position should open accordingly. It's not a strategy, it's just my "want" not to use the random condition.
Sincerely, Vladimir.
It's already looking a bit like a ToS. This is the goal. Now the solution algorithm needs to be formulated step by step
If something is not clear, please ask. Sometimes simple things take more time than complicated ones.
 
VVT:

Vladimir did not say he was stupid, he is having a hard time because the time-limited express method of learning is not easy.

He grabbed the "tools" without reading and understanding the "instructions for use", he has already been told that, having understood the syntax it will be much easier to put the "puzzle" together.

And it is never too late to study, if one had the desire, there are examples of defending a dessert or studying foreign languages at 65, for example...

We must call everything by its proper name - at the moment I am as dumb as a cork in programming! I do not understand elementary things. Although, here in electronics the knowledge I acquired in my youth, still help me to repair, for example, a remote radio button from a doorbell. Last weekend, I used a multimeter and my grandfather's magnifying glass to find a faulty SMD capacitor of microscopic dimensions. It showed a breakdown, short-circuit or "koza", as it used to be called from the acronym for short-circuit. Short-circuit. Here is a picture of the "punctured" SMD capacitor with 4x magnification on a smartphone and subsequent processing in Paint, as it is too microscopic element.


Decided to digress a bit and at least show off something!

And concerning the desire to learn the language, I have it, as well as a hope to master the basics of programming.

Regards, Vladimir

 
Igor Makanu:

not dumb, but impatient, and you are trying to learn "the English language" with only a dictionary - you are trying to put foreign words into combinations you see, without considering that the language constructions may be different

I mean, you have to learn the syntax and the basics of C programming, but you won't be able to write anything useful .... Besides this "mysterious" for statement, there will be a misunderstanding... e.g. scope of variables? - understand what it is? - It's not hard, but you have to understand what the machine sees when it reads your program.


i don't know what tutorial i can advise you. i sometimes look up sharp herehttps://metanit.com/sharp/tutorial/1.1.php

there's also C and C++https://metanit.com/cpp/

If you will use it, you may skip sections about pointers and classes and OOP. You don't have to study it, you just need to organize your knowledge.

Thanks, Igor, for your continuous support and advice. I googled both C and C++, but I feel that once again I need to rest a bit, digest and consolidate what I already understand. And then, start reading books again.

Regards, Vladimir.

 
Valeriy Yastremskiy:
You are already on the TOR. This is the purpose. Now the algorithm of the solution should be formulated step by step
If anything is not clear, please ask. Sometimes simple things are more time-consuming than complex ones.

Valery, I have long had the ToR(terms of reference) written in my advisor, I just haven't posted them in the theme for all to see.

Regards, Vladimir.

/* Краткое описание советника Trailing_Stop. Код советника разрабатывается в соответствии с
   планом самообучения языку программирования MQL5. В советнике применена неттинговая система
   учёта позиций. Эта система учета подразумевает, что в один момент времени на счете может быть
   только одна открытая позиция по одному и тому же символу (финансовому инструменту). Алгоритм
   работы советника прост: один раз в торговый день ровно в 9 ч. 00 мин. по московскому времени
   будет открываться одна позиция в ту сторону, куда будет направлен первый тик. Например, если
   первый тик будет направлен вверх, то значит откроется позиция BUY, если первый тик будет вниз,
   то значит откроется позиция SELL. У открытой позиции сразу будет устанавливаться ордер Stop Loss
   фиксированного размера для минимизации потерь в том случае, если цена финансового инструмента
   станет двигаться в убыточном направлении. Если цена инструмента достигнет этого уровня, то
   позиция полностью закроется автоматически. Если цена финансового инструмента будет двигаться
   в прибыльном направлении, то тогда автоматически включится в работу Trailing_Stop (Трейлинг Стоп).
   Схема работы Трейлинг Стоп:
   1. С приходом новых котировок советник проверяет, прибыльна ли открытая позиция.
   2. Как только прибыль (в пунктах) станет равной либо большей той величины, которая указана во
      входном параметре советника "Уровень перестановки Stop Loss в безубыток", автоматически
      поступит команда для перемещения ордера Stop Loss на тот уровень цены, по которому открылась
      существующая позиция, т.е. в безубыток.
   3. Если цена и дальше продолжит движение с увеличением прибыльности позиции, то при превышении
      величины, указаной во входном параметре советника "Уровень перестановки Stop Loss в безубыток"
      на величину, которая указана во входном параметре "Шаг трейлинг стопа", Stop Loss вслед за
      текущей ценой автоматически переместится с уровня безубытка на величину этого шага.
   4. Если прибыльность позиции уменьшится, то модификации ордера происходить не будет. Таким
      образом, будет автоматически фиксироваться прибыль торговой позиции.
   Если в течении торгового дня открытая позиция не закроется по Stop Loss или Trailing_Stop, то в
   23 ч. 50 мин. советник принудительно закроет эту позицию.

   ВАЖНО!!! Советник создан для демо-счёта исключительно в учебных целях!
            Не предназначен для торговли на реальном счёте и извлечения прибыли!*/
 
MrBrooklin:

Valery, I have long had the ToR(terms of reference) written in my advisor, I just haven't posted it in the thread for all to see.

Regards, Vladimir.

The scheme of work is more like a goal. It's not even a problem statement. The solution is an algorithm at first, a general one. It is a problem statement. And then the algorithms for solving those problems.
 
Valeriy Yastremskiy:
A scheme of work is more like a goal. It's not even a problem statement. The solution is a general algorithm. This is a problem statement. And then the algorithms for solving those problems.

I see.

Respectfully, Vladimir.

 
Valeriy Yastremskiy:

The loop operator and operators in the loop body. Not exactly classic Russian.

Everything is good, of course, but where is the iterator i in the loop body? And in order to get the position symbol and its magic number, it has to be selected first. The position description is a structure (in µl5 all structure and orders and time and deals) and it is filled out through selection, by the iterator that is not position ticket, but position number. And we should remember that in the position description structure, it is always the last position selection.

MrBrooklin:

Good day and good mood everyone!

I continue studying the MQL5 programming language. I've started a detailed study of the for loop operator... Please advise me how to use it, not with corrected code, but with words, or I will never study MQL5.

Sincerely, Vladimir.

Here - let me disagree with you, you can and should code, what prevents you from getting into its essence... understand and so on ... also IMHO, there are articles, there are robots in kodobase - read, parse the code already ready - learn the style of writing right away. Why would you want to reinvent the wheel? Learn from literate code straight away.

Here's a trawl by V. Karputov - it is in ROBOTS, look - adjust it to your needs (terms and your fantasies).

P.S. Thanks to you, the subject of this branch, I began to understand the code, its features ..., to study articles and repeating basic things for myself ...

Thanks for the tip! :-) (no kidding)

TrailingStop
TrailingStop
  • www.mql5.com
Это простой пример советника с реализацией трейлинг-стопа. В нем всего два параметра: TrailingStop — собственно отступ между ценой и уровнем StopLoss. TrailingStep — защита от чрезмерно частой модификации позиции.  Как работает TrailingStop (трейлинг, TrailingStop) — на примере позиции Buy: ...