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
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)
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
Conflicting request - make up your mind what you want.
- 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();
- 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(... :
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
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.
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
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)
Mm ok, what would be the max period without ticks in your opinion? My pairs are eurusd usdchf eurcad on m15

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.