Help me learn how to program. - page 7

 
Aleksei Stepanenko:

What a load of crap...

Yes, Dmitry's cycle call is not the most elegant, but he wrote an interesting code for getting the number of the week from the date. When I use it, I always think of it with a kind word.

But, Dimitri, you have to be more polite to people, gentler.

I'm polite to people.

 

Dmitri's code hasn't survived, but here's a rework based on it:

//получаем номер недели в году
int GetWeekNumber(datetime eTime)
   {
   MqlDateTime eDate;
   //получаем дату начала года
   TimeToStruct(eTime,eDate);
   eDate.mon=1;
   eDate.day=1;
   eDate.hour=0;
   eDate.min=0;
   eDate.sec=0;
   datetime StartTime=StructToTime(eDate);
   //возвращаем дату назад в структуру, чтобы определить день недели начала года
   TimeToStruct(StartTime,eDate);
   return(int((eTime-StartTime+86400*eDate.day_of_week)/604800));
   }
 
Dmitry Fedoseev:

I am polite to people.

Why such aggression, Dimitri?

I simply asked how to use PositionsTotal() in the loop correctly. And not you personally, but in general. And you just snapped. What's wrong, Dimitri?

I hope it wasn't me who was referring to your comment about dehumanizing your interlocutors.

 
Aleksei Stepanenko:

Dmitri's code hasn't survived, but here's a rework based on it:

Oh b(a)ogies! It's a magnificent creation of a genius mind! Unbelievable! Thank you for sharing. I have yet to grow and grow to such colossal heights! It's like a hacker's trick. That's amazing. I don't understand what's written. It's perfect code. Too bad you changed it a little, it doesn't shine as brightly as it could.

 
Nikolay Mitrofanov:

Oh b(a)ogs! This is a magnificent creation of an ingenious mind!

What an outlaw!

 
Dmitry Fedoseev:

What's also very funny is that once again everyone gets all excited - oh what a wrong code I've written for a newbie... and everyone's all over me about it... Amazing!

That never happened. No one criticized the code. It's all about preferences and views on the loop.

And at the moment with PositionsTotal(), a dispute has already arisen about it.

It seemed to you that you are being attacked for the code. But the reality is that nobody gives a shit.

There are not many variants of what should be right and what would work at the same time. It's a matter of choice.


And now, with my wonderful Expert Advisor, which shows you which approach to loops (out of three frequently used ones) to choose, all the need to argue about declaration of loops disappears at all) Isn't it wonderful news, Dmitry?

Let's rejoice together in our shared success! We have jointly resolved a long and centuries-old MQL forum controversy! Finally! Long live all the programmers and sympathizers!

 
Tio Nisla:
I wanted to add earlier that if somefunc() function performs some other manipulations besides returning some amount, e.g. calculates trade parameters, such usage may cause hard-to-catch artifacts and lead a code author into a stupor: "Ht? How come 4 times??? O_o F$#@!!! Isn't it supposed to be there three times? Why is my EA lying to me?". That's what I called "shithcod," which an expert was outraged to the roots of his hair. I didn't bring it up, for it's obvious, but you did it for me. But you failed to take into account that addressing by an index dynamically calculated without array reinitialization is something else. In bare sys this usually leads to GPF, in pluses with smart pointers and arrays to an exception and its handler. In mql it is not clear what it leads to.

There shouldn't be three times, but one time.

Can you draw how to make it so?

 
Dmitry Fedoseev:

I am polite to people.

Dimitri, this is a specialist of a very high calibre.

 
Nikolay Mitrofanov:

I am writing about understanding when developing. First study - then action.

On the contrary, you write: first action, then thinking and combing.

It seems to be the same thing. But then why do they write code examples and documentation?) Is it so that people would do less harm? I think that's exactly the reason. What do you think?

Learning while developing? Actually, we are talking about the first steps in programming. It's when writing the first EA that it's best to get results first, and then figure out the beauty and brevity of the code later.

I am leaving this dialog box now. It is all useless.

 
Aleksei Stepanenko:

Dmitri's code didn't survive, but here's a rework based on it:

I think it should be simpler, like this

return ((int)(day_of_year/7))

The sequence number of the day of the year is inMqlDateTime structure