Help with MQL code - not open a new trade until spesific number of seconds from last trade is reached
-
How To Ask Questions The Smart Way. 2004
Prune pointless queries. -
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
No free help 2017.04.21Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum 2018.05.12 - No need to read from history. On a tick, if there is an open order, remember the current time. If you want to open, compare current time to the remembered one.
- Note that what you asked, is different from not opening in the same H1 candle.
-
How To Ask Questions The Smart Way. 2004
Prune pointless queries. -
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
No free help 2017.04.21Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum 2018.05.12 - No need to read from history. On a tick, if there is an open order, remember the current time. If you want to open, compare current time to the remembered one.
- Note that what you asked, is different from not opening in the same H1 candle.
Hi William,
Sorry for bad description of what I was looking for. By searching the forum I could find a scenario code which will give me the result I was looking for, now Im trying to understand the difference between the two loops defined below (LOOP V1 and LOOP V2). I was looking for the last OrderCloseTime from MODE_HISTORY having a spesific Magic Number. This code gives me that, but while changing to LOOP V1 the Print(lastclosedtime); at the end of the code, will print close time for all orders with my magic number but LOOP V2 will only print for the last order. Im trying to understand what is the difference between these loops. LoopV1 starts counter on 0 and will increment by 1 up on til OrdersHistoryTotal()-1 . LoopV2 will do the same, only in reverse way. I guess there is something I am missing.
datetime lastclosedtime =0; int lastclosedticket; //for(int i=0;i<=OrdersHistoryTotal()-1;i++) //LOOP V1 for(int i=OrdersHistoryTotal()-1;i>=0;i--) //LOOP V2 { OrderSelect(i, SELECT_BY_POS,MODE_HISTORY); if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICNUMBER) { if(OrderCloseTime() > lastclosedtime) { lastclosedtime = OrderCloseTime(); lastclosedticket = OrderTicket(); Print(lastclosedtime()); } } }
datetime lastclosedtime =0; int lastclosedticket; //for(int i=0;i<=OrdersHistoryTotal()-1;i++) //LOOP V1 for(int i=OrdersHistoryTotal()-1;i>=0;i--) //LOOP V2 { OrderSelect(i, SELECT_BY_POS,MODE_HISTORY); if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICNUMBER) { if(OrderCloseTime() > lastclosedtime) { lastclosedtime = OrderCloseTime(); lastclosedticket = OrderTicket(); //Print(lastclosedtime()); Move this outside loop } } } Print(lastclosedtime());
I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
Thanks! Noted about the section misplacement.
Appreciate all help!
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- 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,
anyone can help with this?
I wish to select datetime from the last closed order from history with my magic number and compare its closetime with currenttime and not allow ea to open a new trade until the seconds between them reaches for example 3600 seconds.
appreciate any help!
thanks