Another example: could be that the 15:00 hr bar has an entry at 15:10 hr and the exit occours in the 16:00 hr bar. Let say 16.30 hr. The EA will not produce another entry until the 17.00 hr bar appears.
static datetime Time.open;
for(int pos = OrdersTotal() - 1; pos >= 0; pos--) { // Find my open order,
if( OrderSelect(pos, SELECT_BY_POS) // with my magic
&& OrderMagicNumber() == MagicNumber // number, in my chart.
&& OrderSymbol() == Symbol() ) {
Time.open =Time[0]; // Current open trade, no trades this bar
}
if (Time.open < Time[0]) {
// I can trade this bar}
If you want to not trade for a full hour after a trade closes, not just until the next bar, use:
Time.open=Time[0]+Period()*60; // No trades until 1 hr after close
Have a variable that holds the next allowed trading hour then make the trade conditional upon being >= trading hour. Once the trade has been taken out set trading hour to current +1 then a trade won't happen until the hour changes. You will have to think about what happens with the rollover at 24:00 though.
Thank you for your reply and info. This is a great puzzle to figure out. Some day it will turn profitable.
I will check further down the path that you pointed out.
Cheers Huckleberry
Assuming you are running on the one hour chart:
static datetime Time.open;
for(int pos = OrdersTotal() - 1; pos >= 0; pos--) { // Find my open order,
if( OrderSelect(pos, SELECT_BY_POS) // with my magic
&& OrderMagicNumber() == MagicNumber // number, in my chart.
&& OrderSymbol() == Symbol() ) {
Time.open =Time[0]; // Current open trade, no trades this bar
}
if (Time.open < Time[0]) {
// I can trade this bar}
If you want to not trade for a full hour after a trade closes, not just until the next bar, use:
Time.open=Time[0]+Period()*60; // No trades until 1 hr after close
Hi WHRoeder,
Thank you for taking the time to code this out. I will work this function into the code that I have been working on. This above code you wrote, is a function, not part of the algorithm? Just trying to understand the structure of an EA.
Cheers Huckleberry
I think this is better for you
int ban; for(int pos = OrdersTotal() - 1; pos >= 0; pos--) { // Find my open order, if( OrderSelect(pos, SELECT_BY_POS) // with my magic && OrderMagicNumber() == MagicNumber // number, in my chart. && OrderSymbol() == Symbol() && TimeCurrent()-OrderCloseTime()<3600) { ban++; break; } if(ban>0)//no trade
Thank you Roger,
I will look to incorporate one or the other codes. Do not know how to thank you all. This site is a great place with all the help that is provided.
Now of to my regular 9 to 5 for the time being.
Cheers
Huckleberry

- 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 to all,
Thanks to all also for the help with my other questions. Eventually I will learn this MQL and I will be able to help others as well.
In the mean time, I have another question.
I am running a one hour EA. After I get a 'winning' trade, I wish not for the EA to produce another trade until the next bar. Or another way to express, not to produce another entry until the next bar appears.
Example: The 14.00 hr bar is in effect. An entry occurs at 14.10 hr. The trade is exited as a winner at 14.20 hr. From this point, the EA is waiting for the 15.00 hr bar to appear, before another entry can be made.
Another example: could be that the 15:00 hr bar has an entry at 15:10 hr and the exit occours in the 16:00 hr bar. Let say 16.30 hr. The EA will not produce another entry until the 17.00 hr bar appears.
Possible or not?
Thaks in advance,
Huckleberry