[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 176

 
eddy:
How do you define the last order? By time. Well, look in the code to see which order is the most recent by time


I've already figured it out on my own. But I still don't understand your last tip. Is it possible to pull all orders and see which one was the latest in time? So, you want to pull all orders and compare the closing times of all orders? Show me the code how to do this.

I have solved it this way:

int z;
int _bar;

int start()

{

z=OrdersHistoryTotal()-1;
OrderSelect(z,SELECT_BY_POS,MODE_HISTORY);
if(TimeCurrent() - OrderCloseTime() > 1& TimeCurrent() - OrderCloseTime() < 7)
{
if(OrderProfit()> 0)
PlaySound("profit.wav");
if(OrderProfit()== 0)
PlaySound("zero.wav");
if(OrderProfit()< 0)
PlaySound("loss.wav");
}

It turns out that if 1 is substituted for z, the earliest order will be selected, which is logically the latest one, so I took OrdersHistoryTotal() (it returns the number of orders in the history) and substituted it instead of the index. However, it turns out that OrdersHistoryTotal() returns 1 more than it actually is. My history has had 6 orders, but OrdersHistoryTotal() returns 7 orders. Therefore, I wrote z=OrdersHistoryTotal()-1;. But I didn't know before what to use in the index to select the last one. I had to figure it out myself because no one told me anything.

 
Reaktiv:

if(TimeCurrent() - OrderCloseTime() > 1& TimeCurrent() - OrderCloseTime() < 7)

This is fundamentally wrong and will not always work even in the tester.
 
sergeev:
is fundamentally wrong, and will not always work even in a tester.

So please show me how to do it right. You know, there are a lot of examples in the textbook that don't exist.
 
Reaktiv:

So please show me how to do it correctly, because you know the textbook does not contain many examples.

any solution depends on the goals set.

If you want to find the last order in the history is one thing, but if you want to determine how the last order of your EA closed, that's another thing.

 
sergeev:

any solution depends on the goals you set.

If you want to find the last order in the history that is one thing, but if you just give out how your EA's last order closed, that is another.


I want the music to start playing after the order is closed and depending on what the profit is, the music will play. In my example I wanted it to play if 1 to 7 seconds have passed since order was closed.
 

then the scheme should be as follows

1. At the time of a successful OrderSend you must remember the order ticket(GlobalVariableSet)

2. On each tick, check the ticket of this remembered order(GlobalVariableGet) for closing(OrderCloseTime)

If the order is closed, then give an appropriate sound for profit and delete the memorized Ticket(GlobalVariableDel)

4. If you still want to check for 1-7 seconds, then this check can be included in the analysis, but you must remember that the ticks may come with a delay of 10 seconds or more, and you will miss the signal.

 
sergeev:

then the scheme should be as follows

1. At the time of a successful OrderSend you must remember the order ticket(GlobalVariableSet)

2. On each tick, check the ticket of this remembered order(GlobalVariableGet) for closing(OrderCloseTime)

If the order is closed, then give an appropriate sound for profit and delete the memorized Ticket(GlobalVariableDel)

4. If you still want to check for 1-7 seconds, then this check can be included in the analysis, but you must remember that the ticks may come with a delay of 10 seconds or more, and you will miss the signal.



Does OrderSend have to be sent by the Expert Advisor or does it make no difference? The system is based on the fact that I open deals manually myself. The Expert Advisor modifies order after it is opened (puts stops) and then plays music when it closes a position. As for ticks that may be 10 seconds delayed, I understand it. I'm not going to use EA at such time as now. I use my EA on EUROBAX from 9 am till 18 pm where such delay is unlikely.
 
Reaktiv:

And the advisor itself modifies the order (puts stops) when the trade is opened

Then in your case this point will be the point where the order ticket is taken.
 
sergeev:
then in your case this is the point at which the order ticket is taken.

thanks
 
Reaktiv:
I wanted the music to play if 1 to 7 seconds have passed since the order was closed.
Why? You can just play music once the order has been closed
Reason: