Delay between trades? (help please)

[Deleted]  
Hi everyone,

Sorry for my English, I am French, I hope you understand me.
I could not find a similar topic on the forums French, so I hope you can help me.

My EA is taking a new position on the same bar at each end of trade, and I would put a delay (in hours ou minutes) between trades.
Can you look at my code and correct it?
Then I wonder if it was possible to put a profit target per day?
For example: "if you win 100 euros, stop"?

I give you my code and hope you can help me.

thank you very much


int NumPos;

for (int i = 0; i < OrdersTotal (); i++) {
if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == False){
break;

return (0);


}

NumPos++;
}



// -- Signal Stop SELL --

if ( (Sell1_3 > Var3 && Sell1_2 > CloseSell1_3 )&& (Sell1_4 >=0 )) {
OrderClose (OrderTicket (), OrderLots (), Ask, 1, Red);


}




//-- Signal SELL --

if (!NumPos && Sell1_1 > Sell1_2 && Sell1_3 < Var3 && Sell1_4 < Var4){
OrderSend (Symbol (), OP_SELL, 0.1, Bid, 3, Bid + 500 * Point, Bid - 500 * Point, "Vente", 123456, 0, Red);

}
Simon Gniadkowski
17320
Simon Gniadkowski  

Your English is very good . . . .

I'm happy to try and help you but I won't code for you . . .

In an EA you can add a delay using Sleep https://docs.mql4.com/common/Sleep

To keep track of your daily profit/loss one way is to look through your orders placed and closed during the day (check the order open time and closed time) and sum the OrderProfit of all the trades, https://docs.mql4.com/trading/OrderProfit make sure you use the History pool ( https://docs.mql4.com/trading/OrderSelect MODE_HISTORY)

Also look here: http://crum.be/1e

[Deleted]  

Hi,


Thank you for trying to help me, I tried the function "Sleep ()" but it does not work = (

Simon Gniadkowski
17320
Simon Gniadkowski  
What value did you use in Sleep ? are you running this in the Strategy tester ? Sleep doesn't work in the Strategy tester see here: https://www.mql5.com/en/articles/1512
[Deleted]  
I used 10800000 millisecondes, and yes I use the Strategy tester =(
William Roeder
23772
William Roeder  
  1. Sleep doesn't work in the tester
  2. You can't trail stops if you sleep
  3. put a delay (in hours ou minutes) between trades
    static datetime nextTrade;
    if (nextTrade < TimeCurrent() /*or Time[0]*/){
       int ticket = OrderSend
       if (ticket < 0) Alert("OrderSend failed: ", GetLastError());
       else nextTrade = TimeCurrent() + 4*3600; // next trade in 4 hours.
    }
[Deleted]  
in fact, if I insert this code, it takes positions every 4 hours ^ ^
what I want is that when a trade is closed, it opens after 4 hours.
William Roeder
23772
William Roeder  
So find when the last order closed and don't open
    static datetime lastClose;  datetime lastClosePrev = lastClose;
    for(int pos=0; pos < OrdersHistoryTotal(); pos++) if (
        OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders w/
    &&  OrderCloseTime()    > lastClosePrev             // not yet processed,
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol()                 // and my pair.
    &&  OrderType()         <= OP_SELL){// Avoid cr/bal forum.mql4.com/32363#325360
        lastClose = OrderCloseTime();
    }
    if (Time[0] < lastClose + 4*3600) return;
[Deleted]  

THANK YOU VERY MUCH I LOVE U ! lol =)

[Deleted]  

I have another problem lol, I do not know why, but with this code, "OrderSend" and "OrderClose" does not work anymore, it no longer satisfies the conditions : /