Author of the idea: John Smith, author of the MQL5 code: barabashkakvn.
The Expert Advisor (EA) is set up to trade USDJPY on the H1 timeframe.
This EA utilizes two Moving Averages, along with MACD and CCI indicators. It employs the OnTradeTransaction function to monitor position opening times.
All indicator values are pulled from the bar with index 1.
//--- Indicator Setup CAMELHIGHP1=iMAGet(handle_iMA_PRICE_HIGH,1); CAMELLOWP1=iMAGet(handle_iMA_PRICE_LOW,1); // MACDSP1=iMACDGet(SIGNAL_LINE,1); MACDSP2=iMACDGet(SIGNAL_LINE,2); // MACDHP1=iMACDGet(MAIN_LINE,1); MACDHP2=iMACDGet(MAIN_LINE,2); // CCIP1=iCCIGet(1);
The EA performs checks to see if a position is already open on the current bar, preventing unnecessary checks on all positions (especially useful if you have multiple EAs running on the same account).
Position opening times are monitored through the OnTradeTransaction function. If a position is closed, the open time will be reset:
//+------------------------------------------------------------------+ //| 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_entry =0; long deal_time =0; string deal_symbol =""; long deal_magic =0; if(HistoryDealSelect(trans.deal)) { deal_entry=HistoryDealGetInteger(trans.deal,DEAL_ENTRY); deal_time=HistoryDealGetInteger(trans.deal,DEAL_TIME); deal_symbol=HistoryDealGetString(trans.deal,DEAL_SYMBOL); deal_magic=HistoryDealGetInteger(trans.deal,DEAL_MAGIC); } else return; if(deal_symbol==m_symbol.Name() && deal_magic==m_magic) { if(deal_entry==DEAL_ENTRY_OUT) { m_last_close_time=(datetime)deal_time; } else if(deal_entry!=DEAL_ENTRY_OUT) { m_last_close_time=0; } } }
Comments 0