In order to have only one position on one bar, it is necessary to remember the time of opening the bar when a position appears. For example, a pending order worked -> a position appeared -> you need to remember the time the bar opened.
Then compare this time (from memory) with the opening time of the current bar.
This is how the code will look.
//+------------------------------------------------------------------+ //| TradeTransaction function | //+------------------------------------------------------------------+ void OnTradeTransaction(const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result) { //--- get transaction type as enumeration value ENUM_TRADE_TRANSACTION_TYPE type=trans.type; //--- if transaction is result of addition of the transaction in history if(type==TRADE_TRANSACTION_DEAL_ADD) { long deal_ticket =0; long deal_order =0; long deal_time =0; long deal_time_msc =0; long deal_type =-1; long deal_entry =-1; long deal_magic =0; long deal_reason =-1; long deal_position_id =0; double deal_volume =0.0; double deal_price =0.0; double deal_commission =0.0; double deal_swap =0.0; double deal_profit =0.0; string deal_symbol =""; string deal_comment =""; string deal_external_id =""; if(HistoryDealSelect(trans.deal)) { deal_ticket =HistoryDealGetInteger(trans.deal,DEAL_TICKET); deal_order =HistoryDealGetInteger(trans.deal,DEAL_ORDER); deal_time =HistoryDealGetInteger(trans.deal,DEAL_TIME); deal_time_msc =HistoryDealGetInteger(trans.deal,DEAL_TIME_MSC); deal_type =HistoryDealGetInteger(trans.deal,DEAL_TYPE); deal_entry =HistoryDealGetInteger(trans.deal,DEAL_ENTRY); deal_magic =HistoryDealGetInteger(trans.deal,DEAL_MAGIC); deal_reason =HistoryDealGetInteger(trans.deal,DEAL_REASON); deal_position_id =HistoryDealGetInteger(trans.deal,DEAL_POSITION_ID); deal_volume =HistoryDealGetDouble(trans.deal,DEAL_VOLUME); deal_price =HistoryDealGetDouble(trans.deal,DEAL_PRICE); deal_commission =HistoryDealGetDouble(trans.deal,DEAL_COMMISSION); deal_swap =HistoryDealGetDouble(trans.deal,DEAL_SWAP); deal_profit =HistoryDealGetDouble(trans.deal,DEAL_PROFIT); deal_symbol =HistoryDealGetString(trans.deal,DEAL_SYMBOL); deal_comment =HistoryDealGetString(trans.deal,DEAL_COMMENT); deal_external_id =HistoryDealGetString(trans.deal,DEAL_EXTERNAL_ID); } else return; ENUM_DEAL_ENTRY enum_deal_entry=(ENUM_DEAL_ENTRY)deal_entry; if(deal_symbol==m_symbol.Name() && deal_magic==InpMagic) { if(deal_type==DEAL_TYPE_BUY || deal_type==DEAL_TYPE_SELL) { if(deal_entry==DEAL_ENTRY_IN) { m_time_last_IN=iTime(m_symbol.Name(),Period(),0); } } } } }
and filter:
//--- if(Profit>=InpProfitClose) // close all { m_bln_close_all=true; return; } //--- if(m_time_last_IN==iTime(m_symbol.Name(),Period(),0)) return; //--- if(CalculateAllPendingOrders()!=0) return; //--- if(!RefreshRates()) return;
In order to have only one position on one bar, it is necessary to remember the time of opening the bar when a position appears. For example, a pending order worked -> a position appeared -> you need to remember the time the bar opened.
Then compare this time (from memory) with the opening time of the current bar.
This is how the code will look.
and filter:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, greetings to everyone.
I'm new to metatrader 5 and been testing/programming some EA's. My last EA is based on Buy Limit Orders, scrapped from other EA's in the Code Base. I've been struggling with things like this and I would really appreciate if someone could shed some light on this to me: I would like to limit one order to each bar or put some kind of timer between each of them.
Here is the code if you wanna test for yourself:
Anyway, thanks in advance.