Question regarding OnTrade Event

KjLNi  

Hello,

after a number of self-developed Expert advisors I find my way around using the "OnTick" function together with a number of self-programmed functions.

I keep coming across the other events, like for example "on trade" or others.

Even after quite some research, it is not clear for me how I could potentially use them.

But I am hoping that they can make my live easier.

Please can you point me to a place where this is well explained?

and sorry - I have tried the standard documentation but unfortunately it is still not clear.

Thanks a lot in advance!!!

Tobias Johannes Zimmer  
KjLNi:

Hello,

after a number of self-developed Expert advisors I find my way around using the "OnTick" function together with a number of self-programmed functions.

I keep coming across the other events, like for example "on trade" or others.

Even after quite some research, it is not clear for me how I could potentially use them.

But I am hoping that they can make my live easier.

Please can you point me to a place where this is well explained?

and sorry - I have tried the standard documentation but unfortunately it is still not clear.

Thanks a lot in advance!!!

It is called each time a position is opened or closed. For example if you want to check the profit of each closed position right after it got closed and have your EA pause trading as a result of a condition. Or reverse a position.
This event function is called on each trade and it is a good idea to learn about the definitions of order, deal, trade and position.
KjLNi  
pennyhunter #:
It is called each time a position is opened or closed. For example if you want to check the profit of each closed position right after it got closed and have your EA pause trading as a result of a condition. Or reverse a position.
This event function is called on each trade and it is a good idea to learn about the definitions of order, deal, trade and position.

Hello there,

thanks a lot.

With regards to position/deal/order, yes, thanks, this one is ok for me. It also has taken some time ...

Thanks for the answer, so I understand I can use the OnTrade Event to check what happened right now in a trade.

Are there specific commands to be used at this point in time?

I mean, any other than the History? 

Is there any structure which is filled automatically so that I can refer to it in order to find out about this particular trade?

For example, lets assume that a deal was closed because of Stop Loss.

What would be the best way to inquire the information about it, in the moment of "on trade"?

What I have done until today is to do "HistorySelect" using the time, when a particular deal was opened, until the current time,

and then loop through the deals.

But maybe using the "OnTrade" event there is an easier way to do it?


Thanks a lot in advance!

Tobias Johannes Zimmer  
KjLNi #:

Hello there,

thanks a lot.

With regards to position/deal/order, yes, thanks, this one is ok for me. It also has taken some time ...

Thanks for the answer, so I understand I can use the OnTrade Event to check what happened right now in a trade.

Are there specific commands to be used at this point in time?

I mean, any other than the History? 

Is there any structure which is filled automatically so that I can refer to it in order to find out about this particular trade?

For example, lets assume that a deal was closed because of Stop Loss.

What would be the best way to inquire the information about it, in the moment of "on trade"?

What I have done until today is to do "HistorySelect" using the time, when a particular deal was opened, until the current time,

and then loop through the deals.

But maybe using the "OnTrade" event there is an easier way to do it?


Thanks a lot in advance!

I don't think that you have much of a choice, you can either use the functions from functions list or if you look into Trade classes there is this TradeInfo.SomeFunction() or stuff like that but it is basically the same. The data structure where it is all stored IS the History.
But you can write reusable functions for yourself which check for this kind of information at OnTrade. It will take some time to gwt it up and running but then you can include it like from an mqh and always reuse it if you are smart.
If you are lucky it has been built before because these are very common programs for beginners to intermediate to find out how all this works. Maybe you find something similar in a tutorial. But nevertheless writing these little solutions yourself is one of the most important steps of becoming a better programmer.



KjLNi  
pennyhunter #:
I don't think that you have much of a choice, you can either use the functions from functions list or if you look into Trade classes there is this TradeInfo.SomeFunction() or stuff like that but it is basically the same. The data structure where it is all stored IS the History.
But you can write reusable functions for yourself which check for this kind of information at OnTrade. It will take some time to gwt it up and running but then you can include it like from an mqh and always reuse it if you are smart.
If you are lucky it has been built before because these are very common programs for beginners to intermediate to find out how all this works. Maybe you find something similar in a tutorial. But nevertheless writing these little solutions yourself is one of the most important steps of becoming a better programmer.



Hello and thanks a lot.

In fact I am now able to use the "on trade" event. It already helps me in the sense that I do not have to run my check for every tick, but only when there is a trade, so this is exactly what I wanted.

I have also found a good programming example on how to check last order number from the standard documentation.

So I am happy, question fully answered, thanks a lot.

Reason: