How to insert a time interval for opening orders in EA?

To add comments, please log in or register
Oreplay
243
Oreplay  

Hi all,

I would be very gratefull if someone could help me by advising how to implement a snippet of code in order to let my ea have an interval of a certain period between opening positions. So I want it to never open more tahn one position at a given time. Let's say 20 seconds

So now it operates like:

Open 1 order at 20:23:18

Open 1 order at 20:23:18

 

That should become 20:23:18 and 20:23:38.

ps. Closing may be at the same time.  


Can anybody tell me which code where to insert in the ea?

 Many thanks in advance fellow traders!


Grtz from Amsterdam. 

Simon Gniadkowski
17608
Simon Gniadkowski  
Dutchpips:

Hi all,

I would be very gratefull if someone could help me by advising how to implement a snippet of code in order to let my ea have an interval of a certain period between opening positions. So I want it to never open more tahn one position at a given time. Let's say 20 seconds

So now it operates like:

Open 1 order at 20:23:18

Open 1 order at 20:23:18

You cannot . . .  what if you have no ticks for 60 seconds ? what should happen then ?
Tjipke de Vries
6509
Tjipke de Vries  
Dutchpips:

Hi all,

I would be very gratefull if someone could help me by advising how to implement a snippet of code in order to let my ea have an interval of a certain period between opening positions. So I want it to never open more tahn one position at a given time. Let's say 20 seconds

So now it operates like:

Open 1 order at 20:23:18

Open 1 order at 20:23:18

 

That should become 20:23:18 and 20:23:38.

ps. Closing may be at the same time.  


Can anybody tell me which code where to insert in the ea?

 Many thanks in advance fellow traders!


Grtz from Amsterdam. 


What a short period not allowing new trades .....

 what you can do for such short time period is

make value datetime lastorderopend

moment new trade opend lastorderopend = TimeCurrent + interval

if TimeCurrent > lastorderopend ==>>  OrderSend allowed

....

Now code this...     (Zo moeilijk is dit niet)

and if you fail then show your attempt so I can see where you get wrong

(je krijgt niet elke seconde een nieuwe tick deze methode voorkomt dat je meerdere trades maakt in 20 seconden tijd) 

Oreplay
243
Oreplay  

Dankjewel beste de Vries!

 I think I can manage to code this and shall give it a try. But I just realised that it will not totaly solve my problem because this will work for 1 ea, but I run different ones based on 15m candles and it will not work for more than 1 ea, or is it when the magic nr is the same..?

mm shall think of something. thanks for helping me on track!

 Groet 

whroeder1
17926
whroeder1  
Dutchpips: I would be very gratefull if someone could help me by advising how to implement a snippet of code in order to let my ea have an interval of a certain period between opening positions. So I want it to never open more tahn one position at a given time. Let's say 20 seconds

Conflicting request - make up your mind what you want.

  1. Wait between openings
    datetime lastOpen;
    #define DELAY 20 // Seconds
    int start(){
       :
       datetime now = TimeCurrent();
       if(now > lastOpen + DELAY && isOpenCondition){
          int ticket = OrderSend(...)
          if(ticket > 0) lastOpen = now;
          else Alert("OS failed: " + GetLastError();

  2. Never open more than one position
    extern int magic.number = ..
    string market.pair;
    int init(){ market.pair = Symbol(); }
    bool     MySelect(int iWhat, int eSelect, int ePool=MODE_TRADES){
       if(!OrderSelect(iWhat, eSelect, ePool) )  return (false);
       if(OrderMagicNumber() != magic.number  )  return (false);
       if(OrderSymbol()      != market.pair   )  return (false);
       if(ePool != MODE_HISTORY               )  return (true);
       return(OrderType() <= OP_SELL);  // Avoid cr/bal https://www.mql5.com/en/forum/126192
                                        // https://www.mql5.com/en/forum/124726
                                        // Never select canceled orders.
    }
    int      MyOrdersTotal(int op=-1, int ePool=MODE_TRADES){   #define OP_ALL -1
        if(ePool == MODE_TRADES)     int    iPos = OrdersTotal()        - 1;
        else                                iPos = OrdersHistoryTotal() - 1;
        for(int nOrders=0; iPos >= 0; iPos--) if(
           MySelect(iPos, SELECT_BY_POS, ePool)) if(
           op == OP_ALL || op == OrderType()
        )  nOrders++;
       return(nOrders);
    }
    int start(){
       int openCount = MyOrdersTotal();
       if (openCount != 0) return; // Already one open
       int ticket = OrderSend(...
       :

Oreplay
243
Oreplay  

Dear WHRoeder,

 

Thanks a lot. I am sorry for the confusion. think its my lack in English. Anyway. I meant 1. So more trades can be open but they need to bee opened with an interval of min 20 sec. Thanks.

2 more questions.

 

1) I use 3 charts with 3 ea's. Does this code also work for more ea's? Basically the main problem is not that 1 pair opens more positions at once. But once a 15m candle is complete all three open at same time sometimes and I want them to wait 20 sec.

2) Where do i paste the snippet in the ea? Just above (first 2 lines) and below the start line?

 

thanks again 

Simon Gniadkowski
17608
Simon Gniadkowski  
Dutchpips:

Dear WHRoeder,

 

Thanks a lot. I am sorry for the confusion. think its my lack in English. Anyway. I meant 1. So more trades can be open but they need to bee opened with an interval of min 20 sec. Thanks.


Ah,  now it's a minimum of 20 seconds . . . you changed your requirement.
Oreplay
243
Oreplay  

Hi Raptor,

 

You are right. I assume you mean that exact would be difficukt because of the ticks. Everything between lets say 20 and 40 seconds would work for me.. (so min 20 and max 40 sec)

 

cheers 

Simon Gniadkowski
17608
Simon Gniadkowski  
Dutchpips:

Hi Raptor,

 You are right. I assume you mean that exact would be difficukt because of the ticks. Everything between lets say 20 and 40 seconds would work for me.. (so min 20 and max 40 sec)

Well if you have no tcks for 60 seconds then your max of 40 secs goes out the window . . . then what?
Oreplay
243
Oreplay  
Mm ok, what would be the max period without ticks in your opinion? My pairs are eurusd usdchf eurcad on m15
Simon Gniadkowski
17608
Simon Gniadkowski  
Dutchpips:
Mm ok, what would be the max period without ticks in your opinion? My pairs are eurusd usdchf eurcad on m15
I would estimate a few minutes . . .
123
To add comments, please log in or register