Download MetaTrader 5

Order select , step by step easy way to use Orderelect() function to count trades - page 2

To add comments, please log in or register
Alain Verleyen
Moderator
31167
Alain Verleyen 2014.03.04 00:39  
Thirteen:


... Also, I believe there is a logic error inside the FOR loop...what happens after OrderSelect() returns false (assuming for the moment it does) and the error message is printed to the log? The very next statement is an IF statement which uses OrderSymbol() and OrderMagicNumber(), but those functions may not return the correct information because the OrderSelect() failed...

Good catch, I missed it.
Ubzen
5394
Ubzen 2014.03.04 00:48  
angevoyageur: Good catch...
But of course. Thirteen is one of those guys who help and manages to avoid all the drama.
Daniel Petrovai
440
Daniel Petrovai 2014.03.04 01:04  
Thirteen:


I mean no disrespect, but I disagree. The statement:

is inefficient coding. The FOR loop works without it, so why use that code? Also, I believe there is a logic error inside the FOR loop...what happens after OrderSelect() returns false (assuming for the moment it does) and the error message is printed to the log? The very next statement is an IF statement which uses OrderSymbol() and OrderMagicNumber(), but those functions may not return the correct information because the OrderSelect() failed. You may be able to correct that logic error by adding the Continue operator after printing the error message to the log or by rewriting the contents of the FOR loop without the logical negation NOT. For example:

.


Wow, you do want to help !

Thanks. That is indeed more efficient (less words same output).

So here we are, first post is better than nothing, your example more efficient. I guess some people will find what we did useful, don't you?

Thanks.

GreenMoney
379
GreenMoney 2014.03.04 01:28  
thrdel:


Wow, you do want to help !

Thanks. That is indeed more efficient (less words same output).

So here we are, first post is better than nothing, your example more efficient. I guess some people will find what we did useful, don't you?

Thanks.


All of the people who have posted in this thread want to help and do so in many situations almost every day. I've learned allot on this forum just by listening to others, and I'm glad that I can contribute on occasion. :)
Daniel Petrovai
440
Daniel Petrovai 2014.03.04 02:17  
angevoyageur:

You are trying to address your code to newbies, right ? My opinion is that for a newbie in programming it's sufficient to learn how to use and check one log. As you know there two logs available when you are running a code attached to a live chart. So, as your code have some controls on what is output to Experts log and not to Journal log, it's more easy to use the Experts log, for verbose (description) output and for error number output.

Also, I suggest you to calm down, as most of your posts in this thread, seems too much aggressive or hostile. We are all trying to help and/or learn.


I can see your point about the logs. If by any chance you've taken the " Care to explain " as sarcasm, it wasn't intended that way, just asking to explain the point further.

Thanks for doing so.

About that "seems too much aggressive or hostile" thing, I don't really think I was attacking anyone out of the blue and if my views happen to match yours or Jimdandy for that matter isn't because I'm hostile . Are you ?

But that's a matter of opinion. I know you've been long enough on this forum to understand things and if people don't find a nice and friendly environment, they won't stay and won't come back.

Would you like this place to be better ? I would. Are you happy having people jumping on you for no reason ? I don't .

Do you like it when people, nice and polite, state their view, explain it and post code to help ? I do. So, no problem here mate, as calm as I can be.

You, as moderators have the power to make or break this forum. If you care about outsider's opinion, sometimes it doesn't look very friendly.

Somehow I get the feeling that there are people out there waiting for a new post to jump on it and ruin it . Maybe it's just me. And Jimdandy. And others.

Let me now when you finished reading this so I can delete it . This forum isn't for things like that.

Daniel Petrovai
440
Daniel Petrovai 2014.03.04 02:49  
Thirteen:

All of the people who have posted in this thread want to help and do so in many situations almost every day. I've learned allot on this forum just by listening to others, and I'm glad that I can contribute on occasion. :)


I had a quick look over some of your comments and I missed the unprovoked attacks. Can you please post a link ?

Just kidding !

Would you care to quickly look, whenever you've got a moment, at this sample here ?

I'm sure there's a lot that can be improved on it.

And it seems like quite a number of people are looking forward to learn about the new stuff .

And yeah, If you ask me, I agree whit what you said but I would put " almost " more like towards the front of the first sentence not the end of it, but that's just me. Just for accuracy's sake. ; )

euclid
37
euclid 2014.03.04 13:40  

Thirteen:

As an example, the following is my current trade count function (for build 509):

My function isn't perfect...but it works for me at the moment. It will be interesting to see how I can improve it when I rewrite it for build 600+.

That doesn't look right. Shouldn't it be.

count[0] = c_buy + c_sell // total trades

or

count[0] = c_buy + c_sell - c_pending; // total open trades
GreenMoney
379
GreenMoney 2014.03.04 14:44  
euclid:

That doesn't look right. Shouldn't it be.

. . .

count[0] = c_buy + c_sell; // total open trades

That code is correct because count[0] holds the total of all market/pending trades for currency pair. The EA, from where the code originated, doesn't need a count of only market orders (i.e., only OP_BUY and OP_SELL); rather, it needs (1) a count of total open (market and pending) trades, (2) a separate count of only buy trades and of only sell trades, and (3) a count of only pending trades. I use those counts in the EA to control various other functions--for example, to determine when the EA should place a trade and in which direction or to determine if the EA needs to delete all pending trades at a specific time or after a specific event.

In the event the EA did need to know the total number of open market orders, count[0] - count[1] would provide that value (which, due to the constraints designed into the EA and broker rules, would be either 0 or 1), so there is no need to include that in CountOpenTrades(). In this example, I'm using the variable name "count", but it would actually be the variable passed by reference to CountOpenTrades().

Hope that explanation helps.

12
To add comments, please log in or register