Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 380

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
When creating a graphical object (GO), such as TrendLine, you select the colour. When you recreate the TrendLine, it is created with the same colour. For Hline - you choose a colour - and the next one is like this. Take yellow, blue, ...
If CS creates Expert Advisor, indicator, script - then as you write in the programme. Sometimes the choice of parameters
If you think that someone looking at your code can quickly find an error, you are mistaken. The compiler looks for errors. The program text should be formatted - MetaEditor has a styling tool for that. If you like a different style - use, for example, the AStyle.exe program. After styling, you will quickly see that the program 1) has an extra closing parenthesis. 2) Declared variable: datetime date_Buf_1; // indicator date array - for this to be an array, it must be [size] or [] for a dynamic array and then the size must be set to ArrayResize it seems. And you have to do it before you use an array - see above posts about it. 3) FileOpen(InpDirectoryName+"//"+InpFileName - seems like the sticks should be tilted in the other direction. And it's better to do without InpDirectoryName+"//" - you will find the file in the Files folder anyway.
on the line: int copied=CopyTime(NULL,0,0,0,date_Buf_1); the compiler gets angry, start=0=0
Thanks. I managed to fix something, but more intuitively than by understanding. But we still have 3 errors concerning the array:
'Buf_1' - array required 111.mq4 93 21
'date_Buf_1' - array required 111.mq4 94 21
Thank you. I managed to fix something, but more intuitively than by understanding. But I still have 3 errors concerning the array:
'Buf_1' - array required 111.mq4 93 21
'date_Buf_1' - array required 111.mq4 94 21
Leave only names of variable arrays. Remove "[]" in those lines of code to which the compiler points you.
Thank you. I'll see what happens in real life. I have great doubts that something will be written to the file :)
A number of questions have arisen, I hope very much for your help. I have found a very sad thing, that EA's performance during testing and in real time is very different, so I would like to analyze the most common and typical errors. I will first write about the ones I have encountered. I would appreciate if you could share your experiences with the programmer who knows what he should keep in mind and what he should keep in his code.
1. The error of division by zero was appearing in the real trading mode, despite the fact that division by zero was not present in the code and it had not occurred during backtests. The programmer solved the problem by writing each divisor as NormalizeDouble(x,Digits);
2. The deal did not open. Friday's day the deal was opened when the backtest was running, but no deal was opened during real trading. Moreover, the journal of the Expert Advisor hasn't shown any errors. I do not know what may be the problem here, but I have a couple of things. First, I got warnings like "return value of 'ordersend' should be checked" but if I understand correctly, this should not affect the code execution? Or is it all about slippage? My value is 1, which is not too small. And the bar at which I should perform an entry opened without a gap.
I took the line "if(Volume[0]>1) return;" from the standard example with slips and inserted it at the beginning of the code. That is, my code is executed only during the first tick when a new bar appears. Can it be that a bar opens with a volume and my code is not executed?
4. Please advise on things to pay attention to or typical errors when working with EA with history and real time, please
A number of questions have arisen, I hope very much for your help. I have found a very sad thing, that EA's performance during testing and in real time is very different, so I would like to analyze the most common and typical errors. I will first write about the ones I have encountered. I would appreciate if you could share your experiences with the programmer who knows what he should keep in mind and what he should keep in his code.
1. The error of division by zero was appearing in the real trading mode, despite the fact that division by zero was not present in the code and it had not occurred during backtests. The programmer solved the problem by writing each divisor as NormalizeDouble(x,Digits);
2. The deal did not open. Friday's day the deal was opened when the backtest was running, but no deal was opened during real trading. Moreover, the journal of the Expert Advisor hasn't shown any errors. I do not know what may be the problem here, but I have a couple of things. First, I got warnings like "return value of 'ordersend' should be checked" but if I understand correctly, this should not affect the code execution? Or is it all about slippage? My value is 1, which is not too small. And the bar at which I should perform an entry opened without a gap.
I took the line "if(Volume[0]>1) return;" from the standard example with slips and inserted it at the beginning of the code. That is, my code is executed only during the first tick when a new bar appears. Can it be that a bar opens with a volume and my code is not executed?
4. Please advise on things to pay attention to, or typical mistakes when working with the EA with history and real time, please
Replace this wild construct "if(Volume[0]>1) return;" with a normal "New Bar" check, the forum is full of them.
Warnings of the "return value of 'ordersend' should be checked" kind are not errors so far, they are potential errors for the future. There shouldn't be any warnings in the code, much less when working online.
"I have 1, which is not too little" - this may be very little at opening a new bar, and especially at the opening of a half-hour or an hour, at this time the spread widens greatly.
What we need: to do a check on the new bar, and if it is new, then watch the conditions for entry, if they coincided - make a deal. After that we have to record that the bar worked out and wait for the new one.
What we have now: if(Volume[0]>1) return; = if there is a new bar, we look for conditions, the condition didn't fit == large spread = exit again in OnTick(), on the next tick if(Volume[0]>1) return; it will not go further, so the trade is already missed, even if the spread is 0.0001
Hello. Can you please tell me how to describe the following with the code: There is a flat, bounded by upper and lower horizontal lines. The Expert Advisor detects and sets them by itself.
We need the EA to detect when the price leaves the flat zone and then returns to this zone. And only after that it opens a position.
To filter the noise, I use a moving target with parameter 2 or 3
Replace such wild constructions "if(Volume[0]>1) return;" with normal "New Bar" check, there are plenty of them here on the forum.
Warnings like "return value of 'ordersend' should be checked" - this is not an error yet, this is a potential error for the future. There shouldn't be any warnings in the code, much less when working online.
"I have 1, which is not too little" - this may be very little at opening a new bar, and especially at the opening of a half-hour or an hour, at this time the spread widens greatly.
What we need: to do a check on the new bar, and if it is new, then watch the conditions for entry, if they coincided - make a deal. After that we have to record that the bar worked out and wait for the new one.
What we have now: if(Volume[0]>1) return; = if there is a new bar, then look at the conditions, the condition does not fit == large spread = exit again in OnTick(), on the next tick if(Volume[0]>1) return; it will not miss further, so the trade will be missed even if the spread is 0.0001
About opening a new bar. Would it be good? :
About opening a new bar. Would that be a good option? :
Let it be like this initially.
Next, we need to make a proper fixation that the bar is worked out, but here we need to calculate the whole approach to the TOR.
As far as I can see from your post, we have to do it this way:
The essence is this: if spread is higher than normal, then we exit again toOnTick, and on a new tick check the spread, if it is normal - we send an order and remember that there was a trade on this bar.
There is also a second way:
In general, you need to define the logic, when it should record, and do not check again before the formation of a "New Bar".