Questions from Beginners MQL4 MT4 MetaTrader 4 - page 121
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
Write at least one block and show it. The next step is to suggest it here.
On arrays: here I have declared 4 arrays at global level:
Then I zeroed them out in the position opening function:
How do I fill them now? In the example I'm trying to do it with, an additional variable is applied, but I don't understand how to use it:
Although it's not quite clear why I need all these arrays when I can get the values of the ticket, position type, open price and open time with the corresponding function.
On arrays: here I have declared 4 arrays at global level:
I then zeroed them out in the position opening function:
How do I fill them now? The example I'm trying to use applies an additional variable, but I don't understand how to use it:
Although it's not quite clear why all these arrays, when I can get the values of the ticket, position type, open price and open time with the corresponding function.
Try writing from scratch, outputting all intermediate data using Alert(. For example
And if you take someone's example, take it completely and study it. Who knows what the author of the example is using arrays for
On arrays: here I have declared 4 arrays at global level:
Use an array of structures. It will be much easier to access. Here is a variant with a static array. It is easier to understand. But I use dynamic arrays myself. But the code will get a bit larger with them.
Then I zeroed them in the function of position opening:
No, you haven't. Because dynamic arrays are declared which have zero size by default. So in this case these four lines of code do nothing.
Now how do you fill them in? The example I'm trying to use has an additional variable, but I don't understand how to use it:
Next - a loop of orders is organized, in which each "own" order is stored in an array:
Although, I'm not quite sure what all those arrays are for, when I can get the values of the ticket, position type, open price and open time using the corresponding function.
It is much faster and more convenient to work with arrays, since in general, not all of the orders present in the account need to be processed by this particular EA. And we will save a lot of efforts and money as a result.
Besides, I mentioned above is a general case. Universalism is not always needed, of course. Usually, such arrays are created based on the requirements of a strategy. For example, we can divide orders by type right away: Buy, Sell, BuyStop, SellStop, BuyLimit, SellLimit. Then we will need four such arrays. But later, when making trading decisions, we will not have to go through the entire list of open orders again. We only need to know the number of orders of a certain type and refer to the necessary array.
There is one more important thing to consider: changing the array of orders during processing of one tick. It may well happen that one list of orders was received at the entry to OnTick, and another one somewhere in the middle. This will lead to an error in the program operation that is difficult to catch. And the array of orders that was already formed when entering OnTick will not change (unless, of course, you change it yourself during the execution of the program).
string s=FileReadString(F1); // Read string of the text file
StringSplit(s, "," , a); // Comma-separated string elements into an array
datetime T1=StrToTime(a[4]); // Further, the transformation ...
int ord=StrToInteger(a[8]);
double Price=StrToDouble(a[12]);
Thank you, just what I wanted.
Next, there are 5 products made
We throw in an alert reading (any reading)
for example level "200"
When the alert goes off, something opens the pose, something deletes itself, something does other things. I want to implement a mechanism for giving a signal in this way
P.S.
I have finished what I wanted to, I can send it for review. Sheds perfectly. But it is forbidden to post here.
For example, it is possible to divide orders by type at once: Buy, Sell, BuyStop, SellStop, BuyLimit, SellLimit. Then we will need four such arrays. But then we will not need to go through the entire list of open orders again when making trade decisions. We only need to know the number of orders of a certain type and refer to the necessary array.
That is exactly what I need, or rather just forBuy and Sell. The main thing for my simple strategy is not to let the open positions interfere with each other to see the closing conditions. Maybe, we can do without arrays? I do not understand them: how to create them, how to address them - I'm in the dark. Maybe my situation will become clearer to you on the screenshot:
It seems that everything in the code is simple and works clearly, but this is the only case of incomprehension.
This is exactly what I need, or rather only forBuy and Sell. For my simple strategy, the most important thing is that open positions do not interfere with each other's closing conditions. Maybe we can do without arrays? I do not understand them: how to create them, how to address them - I'm in the dark. Maybe my situation will become clearer to you on the screenshot:
It seems that everything in the code is simple and works clearly, but this is the only case of incomprehension.
Of course, in the simplest (and medium complexity) without arrays is more convenient. But when you get to the point of using hundreds of orders - then...
Could it be the reason for my situation that the log writes: 2018.01.25 20:22:12 2018_WPR14_AMarkets EURUSD,M5: OrderClose error 138 and repeats solidly to
2018.01.26 16:38:12 2018_WPR14_AMarkets EURUSD,M5: Alert: Total orders = 3 ? On the screenshot you can see that this period captures two close conditions of the SELL.
And the signals to open a position are triggered by a combination of several indicators and are closed by one indicator. And they do not work that often: it may be silent for a few days during five minutes. For example, since February 1 this year only 14 positions triggered.
Could it be the reason for my situation that the log writes: 2018.01.25 20:22:12 2018_WPR14_AMarkets EURUSD,M5: OrderClose error 138 and repeats solidly to
What is your situation? Are you saying that the terminal is making a log entry which is causing the error ? and what does 138 mean ? do you know where to look? How did you achieve this is a very rare error. What you see in the screenshot is half the battle. How to explain this to the Expert Advisor? You have to write some mathematical condition - instead of viewing the screenshot, the Expert Advisor operates with numbers
Are you saying that the terminal makes a log entry, which causes the error? ... What does 138 mean? Do you know where to look?
No, I'm saying that the tester fails at this interval of history, which prevents the signals from working correctly. Because the requotes can't go on for 24 hours.
No, what I mean to say is that there is a glitch in the tester at this point in the history, which prevents the signals from working correctly. Because requotes can't go on for 24 hours.
Requotes in the tester? That's the first I've heard. The tester is ideal - it doesn't even have slippage
...something's kicking the indicator - trending upwards. I'll buy ... Got it... Although it's not enough I wanted to move TP up - it already worked...
So set an EA that if it does that, then it will exit, and will continue on the next tick. And try it on the demo