Discussion of article "Step-by-Step Guide to Writing an Expert Advisor in MQL5 for Beginners" - page 11

 
Grenjohn:

Can you tell me more please! Is it possible to open and close positions in Expert Advisors, clearly by time in seconds, regardless of ticks, like a regular timer. That is, if the clock is 12:52:25, then the position would be opened, not waiting for a new tick, the same with closing?

Start a timer with the required frequency and check the occurrence of the required time in it.

Or calculate how long it needs to trigger (12:52:25 - start time) and set the exact interval.

Just don't run into a trade ban, the timer will trigger even when the market is closed.

 
And how to start the timer or how to set the exact interval, it should be written in the code of the Expert Advisor?
 
Grenjohn:
And how to start the timer or how to set the exact interval, it should be written in the EA code?
First of all, use the search.
 
Well, found it in the search I'll look into it thanks!
 

Can I ask you if it is possible to program an Expert Advisor to open an Expert Advisor on a specific day of the week, so that it opens and closes positions on a specific day of the week?

[Deleted]  
Grenjohn:

Can I ask you if it is possible to program an Expert Advisor to open an Expert Advisor on a specific day of the week, so that it opens and closes positions on a specific day of the week?

It is possible
 
Grenjohn:

Can I ask you if it is possible to program an Expert Advisor to open an Expert Advisor on a specific day of the week, so that it opens and closes positions on a specific day of the week?

You can.
[Deleted]  
Dima_S:
We can.
Synchronously)))))
 

Thank you, but I understood that when such and such an event occurs (the time I specified), the function should work, but for some reason it doesn't work.

The position does not open!!!?

extern int tp = 1000;

extern int sl = 1000;

extern double Lots = 0.2;

int ticket;

void OnStart()

{

datetime date1=D'2014.10.28.13.22.13';

if(OrdersTotal()==0)

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Bid-sl*Point,Bid+tp*Point,"",123,0,Red);

}

if (OrdersTotal( )==1 && Hour( )==13 && Minute( )==23 && Seconds ( )>=00)

{

bool select1=OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);

bool close1=OrderClose(ticket,Lots,Bid,20,Green);

}

return(0);

}

Let me explain that I need that every week (once a week), on such and such a day, at such and such an hour, at such and such a second, a position is opened and then closed a few seconds later.

[Deleted]  
Grenjohn:
Let us respect each other. Insert the code correctly so that it can be read. You have already been shown how to do this.