Use Time[] and TimeCurrent() to check.
there. I didn't test it.
bool can_trade_new_bar() { //iterate through last ten trades. You can adjust this value above or below for(int i=OrdersHistoryTotal()-1; i>=OrdersHistoryTotal()-10;i--) { if(!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue; if( iBarShift(Symbol(),Period(),OrderCloseTime(),false)==0) //current bar should be zero shift. You can verify it. return(false); } return(true); }
int BarTraded = 0; bool NewBar() { static datetime lastbar; datetime curbar = Time[0]; if(lastbar != curbar){ BarTraded = 0; lastbar=curbar; return (true); } return(false); }Whenever you open an order, don't forget to do "BarTraded = 1;" if opening the order was successful. And always check to make sure that "BarTraded == 0" before opening an order.
.
Jon
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register