Beta version of the online book on MQL4 programming - by Sergey Kovalev (SK.) - page 3
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I have tried Meta Trader for the first time a week ago and found out that it is much more convenient than my previous terminals (Rumus and Forex Trader). About two years ago, when I got to know about Forex and opened my first demo account, I wondered how to automate everything. Then I opened the terminal and saw the message Autotrading in the mail section. And here I am))) Intensely reading the book, and I hope that soon I will write my first Expert Advisor for my developed strategy. I had absolutely nothing to do with programming before, it was even hard to imagine that I would ever study programming))) As I was reading, questions arose, but they also disappeared as I went along. The question appeared, I looked ahead and was satisfied, because I saw the answer after a couple of chapters and went back to read everything in order. I was especially attracted by the possibility to test the strategy on historical data and adjust the strategy as a result.
Anyway, thanks a lot for the book.
It is excellent. You are a new MT user. And you know practically nothing about programming at the moment.
Allow me to suggest that you report at least two or three times a month how things are going (and more often if you wish). That would be extremely interesting.
In the meantime, if you allow me, I have a question. You say that a question has arisen which is answered in the following sections. I've tried to put it together in a way that avoids that situation. Could you please clarify what question you are referring to?
A week ago I installed and tried Meta Trader for the first time. It turned out that this terminal is much more convenient than my previous ones (Rumus and Forex Trader). About two years ago, when I got to know about Forex and opened my first demo account, I wondered how to automate everything. Then I opened the terminal and saw the message Autotrading in the mail section. And here I am))) Intensely reading the book, and I hope that soon I will write my first Expert Advisor for my developed strategy. I had absolutely nothing to do with programming before, it was even hard to imagine that I would ever study programming))) As I was reading, questions arose, but they also disappeared as I went along. The question came up, I looked ahead and was satisfied, as I saw the answer after a couple of chapters and went back to read everything in order. I was especially attracted by the possibility to test the strategy on historical data and to correct it as a result.
Anyway, thanks a lot for the book.
It is excellent. You are a new MT user. And you know practically nothing about programming at the moment.
May I offer you: to let me know at least 2 or 3 times a month how you are doing (or more often, if you wish). It would be very interesting.
In the meantime, if you allow me, I have a question. You say that a question has arisen which is answered in the following sections. I've tried to put it together in a way that avoids that situation. Could you please clarify which question you are referring to?
I will let you know the progress of course, as in my situation and without communication)). I hope for a constructive feedback.
Thank you for your time and attention.
Please break up the following messages into paragraphs, as it is difficult to understand what is being written.
But having started reading the book, I was a bit confused by structure of program's construction and then by int start () function, which is repeated at every tick and if at the time of its execution I know the price of bid, then it is written to a variable and is stored in it throughout the execution time, then how will I know when the price has changed and the program can perform any other actions based on the new price? I thought that the price in my program would be updated by some loop code, constantly asking for it.
You are right to say that for the program to be able to work in real time, it is necessary to be informed periodically about the fact of a new price and the price itself.
In fact, there are 2 methods:
1st way is to run in endless loop some function and from it periodically request price.
But this method has disadvantages:
- If queries are made often, the result is a heavy load on the communication channel and a waste of PC resources;
- If you make queries infrequently, you may miss a new price between queries.
The 2-nd method (accepted as a basic one in MQ technology) is quite different in that the launch of the necessary code belongs to the terminal. The terminal receives information from the server, understands that a new tick has come (the fact of a new price and the price itself) and based on this information, the terminal starts() function. All this is described in the Program in MQL4 section.
Now I have a question: I realized that when executing init function I'll call function of calculating opened price of my order, and also lot size calculation, based on balance data on my account; after init execution execution will start start start function start...
Incorrect. init() and start() are special functions. They are called by the client terminal according to their own properties (or more simply, according to the rules, conditions under which they are called for execution). This is described in the Special Functions section. The init() function is executed once, when the program is loaded in the window. And start() is called on each tick. This is very convenient. A tick came and brought a new price = the terminal launches start() that is executed until it is executed. All calculations must be inserted into it - calculation of the number of lots, conditions of opening/closing orders and everything else.
Then the most puzzling thing for me is where to write the code expecting the "close" price of the order and return to the beginning, i.e. again, calculating the opening price, waiting for this price, etc.. I looked ahead into the sections; I think I saw something in the titles, which will probably answer my question. I will enjoy reading the Opening and Setting Orders section.
Judging by your questions, you do not need to write programs and you do not need to read what you are now reading. In this situation, it is strongly recommended to start reading the book again. Consistently and without getting ahead of yourself. And as you go along, type all of the presented examples into ME and execute them on your PC. And do not proceed to the next section until every letter of the code is fully understood. Look up the concepts of Tick, Control, Function, Special Function, Operator, and generally check the Dictionary of Terms from time to time.
I will certainly report the progress as in my position and without communication)) I hope for a constructive feedback.
Thank you for your feedback.
I hope you will take the advice correctly and follow it.
Then the most puzzling thing for me is where to write the code waiting for the "close" price and return to the beginning, i.e. again counting the opening price, waiting for this price, etc. I looked ahead into the sections; I think I saw something in the titles, which will probably answer my question. I am still reading the Opening and Setting Orders section.
Judging by the questions you have, you don't need to write programs yet and you don't need to read what you're reading now either.
Quickly scribbled it down in the vdp, here you go:
Init
Start
I set the maximum number of open orders = 1;
Check how many orders are open;
if 1 is open, then I call the function to close the order,
If no orders are opened, then I call the function "calculate price and number of lots".
--------------------------
Necessary to calculate a favourable buy and sell price and to calculate the number of lots;
--------------------------
querying the current price;
if the current price >= bargain price to sell,
then open a sell order equal to the number of lots already determined;
if not, compare the current price with the winning bid price;
if the current price is <= Bid price,
respectively open a Buy order;
--------------------------
Call function to close the order;
return
deinit
Got that right?Got it right?
Well, right on the whole :) Congratulations to you. It's always nice to understand something else.
Still, take my advice: go back to the beginning and go from the beginning without skipping or skipping over, methodically executing on your PC all the codes suggested in the tutorial.
There is an interesting ROC indicator in the book - the rate of price change indicator(https://book.mql4.com/ru/samples/iroc). I understand that this book is a textbook and the author is not obliged to give semi- or even quarter-grain source code, but the idea of the indicator is very good, and I've tweaked it a bit to make the lag even weaker.
Two times division character is missing (disappeared during creation of html file?).
The indicator file linked in the text is normal.
Well, right on the whole :) Congratulations to you. It's always nice to understand something else.
Still, follow my advice: you need to go back to the beginning and go from the beginning without skipping and skipping, methodically executing on your PC all the codes suggested in the tutorial.
Yes, I agree, it is very important to see and feel any result of what you read, that is when it is fixed in the long term memory, all the more under the influence of emotional content, more than one association appears:) By the way, I also wanted to emphasize that in order to stimulate interest, it is necessary to go back or use those chapters that are most important, then the interest itself will lead to the goal and expand the circle of knowledge. The most difficult thing in our situation is to understand what is interesting as we go along, to work out the order that will be most effective, as we see the effectiveness of everything we own. I would relate the operation of associative memory to guided memory, where a distributed area exists as long as there is at least one link(association) to it, the more links, the more likely the area will not be released, thus ensuring its use and subsequent usefulness. It is therefore necessary to constantly replenish the stock of associations in order to consolidate what you have read.
P.S.: Sorry if I went too far:)
The division symbol is missing twice (disappeared when creating the html file?).
Indicator file linked in the text is normal.
Yes, there is such a thing. In source codes no errors detected yet, but text codes are screwed up in some places for some reason. We will sort it out.
P.S.: Sorry if I overreacted:)
I'm already having a hard time with loops (I'll come back to these sections more than once), and then there are those sheep.
Just my opinion, if considered a specific example of trading (almost raiding:)), okay, trading, then if the reader meets an example similar to his idea (which he does not know how to implement), he will with great interest consider this example and think how to modify and customize it to implement his idea (I think you know what I mean).
I had such an example, I was interested in how to open an order for 1/3 of the balance. You can't imagine what kind of mathematical operations were performed in my head in order to convert 1/3 in dollars, so that I got the sum in lots (0.1 or 3.5 lots...). And how happy I was when I saw an example ofopenbuy.mq4, which opens a Buy order worth 35% of available funds, with some specified values of stop orders. I looked it through and through, looked into each line, what, why, and where. I looked at the standard functions used in it (MathFloor, MarketInfo. ....).