Questions from Beginners MQL5 MT5 MetaTrader 5 - page 282

 

amavladi:


I want to understand the mechanics of loops so I can write a complex EA. The operator "return" throws me to a new "start" I do not always need it.

Thanks for the reply anyway.

You're welcome. The point is that if you want to understand the "mechanics" with the help of "third parties", then you need to formulate the problem to those very "third parties", i.e. describe what you would like to get from the algorithm, not what you got.

"The loop loops" is not a problem, because if there is nothing in the loop except the continue operator, then it is bound to loop until the loop condition becomes false.

I.e., you should not ask silly questions like: "what doesn't work in non-working code". After all, even a drunken hedgehog knows that non-working code doesn't work because it's non-working. But no one without telepathic powers, except the author of the code, can understand what should have worked in the working code.

 
amavladi:

HELP!

I am looking for good people on this site, please advise me of my mistakes. I just started to learn MQL4and wrote a simple Expert Advisor that opens an order and then closes it with a smalltakeprofit.I tried to check it in strategy tester and found out that my for and while statements loop gets looped if written like this:

//--------------------------------------------------------------------

   while (Ask<=Level)

   { RefreshRates();

     continue;

   }         

Well here everything seems to be simple.

The strategy tester generates a tick, calls start() and waits until this function finishes to generate the next tick.

So, if you want your robot not to hang in the tester, get away from such a construction. In your case, the Ask price will not change until it exits from start().

And when the return command is received, the function start will terminate, and the tester will understand that the next tick should be generated.

Moreover, not in the strategy tester, but in the real mode, your code will work as you expect, because RefreshRates will update the Ask price.

Your code works fine, but for the strategy tester it enters an infinite loop.

Using return will help here. When you gain more experience you will get rid of such constructions. Good luck to you.

 
Reshetov:


That is, you should not ask silly questions like "what doesn't work in non-working code". After all, even a drunken hedgehog knows that non-working code does not work because it does not work. But no one without telepathic powers, except the author of the code, can understand what should have worked in the working code.

The code works, it's just that there are always nuances that newbies don't know about...
 
Reshetov:

You're welcome. The point is that if you want to understand the "mechanics" with the help of "third parties", then you need to formulate the problem to those same "parties", i.e. to describe what you would like to get from the algorithm, not what you got.

"The loop loops" is not a problem, because if there is nothing in the loop but the continue operator, it is bound to loop until the loop condition becomes false.

I.e., you should not ask silly questions like: "what doesn't work in non-working code". After all, even a drunken hedgehog knows that non-working code doesn't work because it's non-working. But no one without telepathic powers, except the author of the code, can understand what should have worked in the working code.

I don't like it when people throw a lot of dirt on beginners. Just write in a human way like - the question is poorly/inaccurately/wrongly worded, or - a mistake here or there. Remember yourself when you started to learn to do something, too, more than once probably asked a stupid question. And does the metaphor of a drunken hedgehog bring any positive solution to the problem? It is only pleasant to feel cool in the glow of your own greatness in front of a newcomer.
 
paladin800:
I don't like it when newbies get a lot of dirt thrown on them.

A pig finds dirt everywhere © Folk proverb

Where did you find the dirt? If you found it, ask a moderator.

paladin800:
Does the metaphor of the drunken hedgehog bring any positivity to the problem?

Ask the administration to add a ban on metaphors and hedgehogs to the rules.

 
Reshetov:

A pig finds dirt everywhere © Folk proverb

Where did you find the dirt? If you find it, go to a moderator.

Ask the administration to add a ban on metaphors and hedgehogs to the rules.

And why moderators and admins... It's a matter of breeding, professional ethics, tact, tolerance, humanity in the end... ...admins can't help.

And if you don't fully understand the problem, you'd better not give advice... Sometimes it's better to chew... Although showing off at the expense of others is your right...

 
elugovoy:

It's all about upbringing, professional ethics, tact, tolerance, humanity in the end...

Mm-hmm. The kindergarten and the noblewomen's institute all rolled into one.

So why don't we skip the personal stuff and keep answering questions from the newbies? Otherwise, we get a kind of fluderasty from supporters of humanitarian approaches in a purely technical topic.

 
I would like to thank Evgeniy Lugovoy (he has great telepathic skills). You answered my question about the real and tester cycle problems one hundred percent. The same evening I read the article "Testing and Optimizing Expert Advisors " by the link http://articles.In the same evening, I ran across the article "Testing and optimizing the EA" by the link . mql4.com/en/824 (this is for newbies like me) and realized that the tester creates a real price move discretely and gives new quotes only at the next iteration of the EA, so I rewrote the code for testing, using a series of IF statements, where there were operators loops before. For beginners like me I advise to get acquainted with "Common Functions" of MQL4 (link http://docs.mql4.com/ru/common). I was surprised to find out the difference in operation of one and the same function in real terminal and in strategy tester, for example Sleep() in tester doesn't make any delay like it should and works only in real terminal.And finally, for the reckless (like me) lovers of conditional infinite loops int start() { double Level=1300; while (Ask<=Level) The last two lines of the code, despite its innocence, after running it on a terminal in a real money window, as long as the price reaches 1300, will take a huge amount of CPU time (on my 25 % 2-core).My friend suggested that if you can not give up the loop, you need to insert Sleep ( int 100), that is, give an interval of 100 to 200 milliseconds to relieve the processor.int start() { double Level=1300; while (Ask<=Level) { Sleep( int 100) continue; }
P.S. For "third-party" admirers of the expressions: drunken hedgehog, screwball, fluderasty and so on. (although we are in a purely technical topic), allow myself to give a little reference to Fyodor Mikhailovich Dostoyevsky, who in his novel "The Idiot" through Prince Myshkin says a very strange thing: "Beauty will save the world! And to you Eugene, I beg you to say hello to Moldova, even though I live in another country, but I was born in Kishinev.
 
amavladi:

There's no telepathic thing )))) I think everyone has made the same mistakes when they want to "catch" a price for, say, a trawl... including me about 6 years ago.

By the way, the topic is for newbies and it's not "strictly technical".

I'll say hello.

Good luck.

 
elugovoy:

There's no telepathic thing )))) I think everyone has made the same mistakes when they want to "catch" a price for, say, a trawl... including me about 6 years ago.

By the way, the topic is for newbies and it's not "strictly technical".

I'll say hello.

Good luck.

About telepathy and "purely technical" - I am for Mr.Reshetov: ))).

Good luck to you too.

Reason: