Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

cheduecoglioni - MetaTrader 5 Expert | MT5 EA Download - MetaTrader 5 Resources

author EAcpu | 2 reads | 0 comments |

Author of the idea : EF91 (related discussion begins )

MQL5 code author : Vladimir Karputov .

The EA waits for TP or SL to trigger and then opens a position in the opposite direction. It checks if there are sufficient funds before sending a transaction request. OnTrade Trading.

For example, we have an open buy position. Once Take Profit or Stop Loss is triggered, a new sell position is opened. Then, after triggering TP or SL, open a new buy position.

Transaction ends in " Online Transaction ":

 //+------------------------------------------------------------------+
//| TradeTransaction function |
//+------------------------------------------------------------------+
Blank OnlineTrade ( const MqlTrade transaction & trans,
Constant Mql Transaction Requests & Requirements,
Constant Mql Transaction Result &Result)
  { //--- Get the transaction type as enumeration value ENUM_TRADE_TRANSACTION_TYPE type = trans.type; //--- If the transaction is the result of adding a historical transaction if (type == TRADE_TRANSACTION_DEAL_ADD )
    {
long deal_entry = 0 ;
long deal_type = 0 ;
string deal_symbol = ”” ;
long deal_magic = 0 ;
long deal_time = 0 ;
if ( Historical Transaction Select (Transaction))
        {
        Transaction Entry = Historical Transaction GetInteger (cross-transaction, DEAL_ENTRY );
        Transaction Type = Historical Transaction Get Integer (Cross Transaction, Transaction Type );
        Transaction symbol = historical transaction acquisition string (cross-transaction, DEAL_SYMBOL );
        Transaction Magic = Historical Transaction GetInteger (cross-transaction, DEAL_MAGIC );
        Transaction time = historical transaction acquisition integer (cross-transaction, DEAL_TIME );
        }
Return otherwise ; if (deal_symbol==m_symbol.Name() && deal_magic==m_magic)
        {
if (transaction entry == DEAL_ENTRY_OUT )
          {
if (TransactionType == DEAL_TYPE_BUY ||TransactionType == TransactionType_Sell )
              {
if (transaction type == DEAL_TYPE_BUY )
                  m_close_pos_type= POSITION_TYPE_SELL ;
Else if (transaction type == transaction type_sell )
                  m_close_pos_type= POSITION_TYPE_BUY ; Other returns ;
              m_is_trade= true ;
              }
          }
Else if (Transaction Entry == DEAL_ENTRY_IN )
          {
            m_is_trade= wrong ;
          }
        }
    }
  }

    Check the trading volume before sending an order (taking establishing a buy position as an example):


    Attachment download

    📎cheduecoglioni.mq5 (8.99 KB)

    Source: MQL5 #18294

    Verification code Refresh