Self-learning the MQL5 language from scratch - page 70

 
MrBrooklin:

We should call things by their proper names - at the moment I'm as dumb as a cork in programming! I don't understand elementary things. I have to call it by its name - at the moment I'm dumb in programming and I don't understand basic things. 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 abbreviation for short circuit, i.e. short circuit. Here is a photo 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!


Cool! These things, by the way, are close to each other.
When I was a student in the 90s these departments were located in the same department of information technology.
 
Roman Shiredchenko:

Here - let me disagree with you - you can and should code, what prevents you from getting to the bottom of it... to 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)

Hello Roman! It is gratifying to read that the subject matter created is still helpful to someone other than myself. Thank you!

Regarding the codes written by Vladimir Karputov, for me it is, so far, beyond my reach. In general, I don't understand the codes containing the included files and classes. Why one file or another has been included in another EA is a big mystery!

I'm mostly looking for and studying the codes written without the included files and classes. Expert Advisors written by Vladimir Khlystov are very good for self-study. A special BIG THANK YOU to him! It's a pity that there are too few Expert Advisors in MQL5.

Now I want to explain why I'm asking you not to suggest ready-made code. The reason is that the ready code may hint you and you are no longer interested in studying the language. You just paste the ready-made code into your Expert Advisor, it works, so what good will it do? And on the contrary, when you cannot immediately understand and write something, like, for example, the current misunderstanding of the loop operator, it is so spurring and motivating that one can hardly believe it!

I do not see anything wrong with learning MQL5. I'm just experiencing approximately the same stage in my life, when I was studying electronics and went from the study of one element base to the study of another. The only difference is that everything is perceived and assimilated more easily in youth than now. I've already experienced that.

Thank you ALL for the words of support and constructive suggestions! I continue studying MQL5! For half a day I will "disappear", because I need to go to the other end of Moscow on business, and then I will continue.

Sincerely, Vladimir.

 
Aleksey Masterov:

Cool! These things are all nearby, by the way...
At my university, I studied in the '90s, these departments were in the same IT department.

in the '90s, they were buying diplomas.

- can't you see now, there are these department heads sitting in all the offices

 
SanAlex:

back in the '90s, buying diplomas.

- Can't you see now, there are these department heads sitting in all the offices?

It's not even the possibility to buy a diploma at that time, the fact is that over the past 30 years technology has stepped so far that the knowledge is VERY lacking, for example, I had then to learn autocad which then simply did not exist, also made a VERY basic C++. and so in everything, you need to constantly learn more, improve, keep up with the times)

 
VVT:

It's not even about the ability to buy a degree at the time, the fact is that over the past 30 years, technology has advanced so far that the knowledge is already VERY lacking, for example, I then had to finish learning autocad which then simply did not exist, also did a VERY basic C++. and so in everything, you need to constantly learn, improve, keep up with the times)

technology has come so far in the last 30 years- it's still using those developments from the 60s

 

Good afternoon everyone!

If I wanted to add something interesting, I think the idea of "self-training in MQL5 from scratch" is not quite right. If a person is a 0 in programming, he has to learn how to program first. If the aim is to learn how to program in MQL from the scratch, a person must first learn howto program in C, at least the very basics, and then learn to write in MQL, because MQL is in fact C, but it is specialized for a certain task, a person doesn't understand how loops work, and already trying to write programs. It's like trying to learn Latin without knowing Russian...

Another thing is that C is not a very friendly language to learn programming, it is simple, but it is too concise, it is difficult for a beginner to read and understand code without having basic understanding of algorithms, data types, Boolean algebra. In C three characters in a row may mean several strings in another language.

To learn to program simply from scratch, for the base, to learn to talk to a computer in one (no matter what) language, I would recommend starting with Pascal, the easiest book to start with it (2-3 weeks at ease), then C (there after Pascal max week with diligence, master the syntax, I mean the basic language skills!) and then take up specialized languages like MQL, because MQL is C, which has a little twist and simplification, since it is designed for a single task and the compiler knows the obvious. And C in turn is a kind of RAR-compressed Pascal, but Pascal is almost English =).

Now about loops:

When I was learning to program, the analogy of sum in algebra helped me, where you specify the initial value of n, the final value of n and the formula with this n to calculate.

 
VVT:

It's not even about the possibility to buy a diploma at the time, the fact is that over the last 30 years technology has gone so far that that knowledge is VERY lacking, for example I had to learn autocad which didn't exist back then, also did VERY basic C++. and so in everything, you need to constantly learn more, improve, keep up with the times)



:-) autocad was around. We had classes based on it to learn circuitry and the layout of layers...circuit boards
 
Aleksey Masterov:
:-) autocad was. We had a class based on it to learn circuitry and layout of layers...of printed circuit boards
.

We had only 22 computers, which were loaded only at the end of the class) the teacher just kept them on during the day, it was impossible to work, we didn't even talk about cad...

 
MrBrooklin:

Hello Roman! It's nice to read that the topic is helping someone other than myself. Thank you!

As for the codes written by Vladimir Karputov, they are beyond my reach for now. In general, I don't understand the codes containing the included files and classes. Why one file or another has been included in another EA is a big mystery!

I'm mostly looking for and studying the codes written without the included files and classes. Expert Advisors written by Vladimir Khlystov are very good for self-study. A special BIG THANK YOU to him! It's a pity that there are too few Expert Advisors in MQL5.

Now I want to explain why I'm asking you not to use a ready-made code. The reason is that the ready code may hint you and you are no longer interested in studying the language. You just paste the ready-made code into your Expert Advisor, it works, so what good will it do? And on the contrary, when you cannot immediately understand and write something, like, for example, the current misunderstanding of the loop operator, it is so spurring and motivating that one can hardly believe it!

I do not see anything wrong with learning MQL5. I'm just experiencing approximately the same stage in my life, when I was studying electronics and went from the study of one element base to the study of another. The only difference is that everything is perceived and assimilated more easily in youth than now. I've already experienced that.

Thank you ALL for the words of support and constructive suggestions! I continue studying MQL5! For half a day I will "disappear", because I need to go to the other end of Moscow on business, and then I will continue.

Sincerely, Vladimir.

I agree - his codes are good too! You get yourself worked up over nothing. Quietly sort out the code without any rush, and that's all. Here's all elementary here - select and trawl: (how much easier - just your topic of choice NEEDED position ... :-))

//--- при таком методе мы будет сюда попадать на каждом тике.
   for(int i=PositionsTotal()-1;i>=0;i--)
      if(m_position.SelectByIndex(i))
         if(m_position.Symbol()==Symbol() && m_position.Magic()==m_magic)
           {
            //--- TrailingStop -> подтягивание StopLoss у ПРИБЫЛЬНОЙ позиции
            if(m_position.PositionType()==POSITION_TYPE_BUY)
              {
               //--- когда у позиции ещё нет StopLoss
               if(m_position.StopLoss()==0)
                 {
                  //--- пока StopLoss равен 0.0, TrailingStep не учитываем
                  if(m_symbol.Bid()-ExtTrailingStop>m_position.PriceOpen())
                    {
                     //--- модификация позиции
                     m_trade.PositionModify(m_position.Ticket(),m_position.PriceOpen(),0.0);
                    }
                 }
               //--- у позиции уже есть StopLoss
               else
                 {
                  //--- теперь TrailingStep нужно учитывать, иначе мы будет модифицировать
                  //--- поизцию НА КАЖДОМ ТИКЕ, а это ПЛОХО
                  if(m_symbol.Bid()-ExtTrailingStop-ExtTrailingStep>m_position.StopLoss())
                    {
                     //--- модификация позиции
                     m_trade.PositionModify(m_position.Ticket(),
                                            NormalizeDouble(m_symbol.Bid()-ExtTrailingStop,m_symbol.Digits()),0.0);
                    }
                 }
              }

            if(m_position.PositionType()==POSITION_TYPE_SELL)
              {
               //--- когда у позиции ещё нет StopLoss
               if(m_position.StopLoss()==0)
                 {
                  //--- пока StopLoss равен 0.0, TrailingStep не учитываем
                  if(m_symbol.Ask()+ExtTrailingStop<m_position.PriceOpen())
                    {
                     //--- модификация позиции
                     m_trade.PositionModify(m_position.Ticket(),m_position.PriceOpen(),0.0);
                    }
                 }
               //--- у позиции уже есть StopLoss
               else
                 {
                  //--- теперь TrailingStep нужно учитывать, иначе мы будет модифицировать
                  //--- поизцию НА КАЖДОМ ТИКЕ, а это ПЛОХО
                  if(m_symbol.Ask()+ExtTrailingStop+ExtTrailingStep<m_position.StopLoss())
                    {
                     //--- модификация позиции
                     m_trade.PositionModify(m_position.Ticket(),
                                            NormalizeDouble(m_symbol.Ask()+ExtTrailingStop,m_symbol.Digits()),0.0);
                    }
                 }
              }
           }
  }

Besides that, include files - it means you have them in your code as functions as well and that's it.

#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>  
 

Here's another article - trawl 2010 - trawl is in the advisor from the standard MACD delivery.



Here's another great chew on the volume of positions calculation!!! Got deep into it myself... :-)

Another way to determine the total position volume on a symbol is to go through all positions in the loop, the number of positions is determined by the PositionsTotal() function. By checking with the PositionGetSymbol() function, find the needed symbol and determine the position volume and direction(PositionGetDouble() with the POSITION_VOLUME identifier and PositionGetInteger() with the POSITION_TYPE identifier).

In this case, the complete function will look like this

double fSymbolLots(string aSymbol)
  {
   double TmpLots=0;
   for(int i=0;i<PositionsTotal();i++) // Перебор всех позиций
     {
      if(PositionGetSymbol(i)==aSymbol) // Найдена позиция с заданным символом
        {
         TmpLots=PositionGetDouble(POSITION_VOLUME);
         if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
           {
            TmpLots*=-1; // В зависимости от направления позиции устанавливаем знак числа
           }
         break;
        }
     }
   TmpLots=NormalizeDouble(TmpLots,2);
   return(TmpLots);
  }
Как создать свой Trailing Stop
Как создать свой Trailing Stop
  • www.mql5.com
Перед тем как приступить к разговору на тему статьи, предлагаю расставить точки над i. Лишний раз не помешает определиться с понятиями "позиция" и "ордер": Позиция - это рыночное обязательство, количество купленных или проданных контрактов по финансовому инструменту. Позиция по одному инструменту может быть только одна. Ордер - это распоряжение...
Reason: