Download MetaTrader 5

Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal


Opposite trade - expert for MetaTrader 5

| English Русский 中文 Deutsch 日本語 Português

votes: 16
2017.11.03 12:25

Opening a position opposite to the closed one, with the same volume. It works for any symbol and any magic number.

For example, we have an open AUDUSD BUY 0.01 position. Once this position is closed (e.g. we close it manually) the Opposite trade Expert Advisor will immediately open a new AUDUSD positions, this now a SELL position.

The entire code is contained in the OnTradeTransaction function:

//| TradeTransaction function                                        |
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
//--- get transaction type as enumeration value 
//--- if transaction is result of addition of the transaction in history
      long     deal_type         =-1;
      long     deal_entry        =-1;
      double   deal_volume       =0.0;
      string   deal_symbol       ="";
         deal_type         =HistoryDealGetInteger(,DEAL_TYPE);
         deal_entry        =HistoryDealGetInteger(,DEAL_ENTRY);
         deal_volume       =HistoryDealGetDouble(,DEAL_VOLUME);
         deal_symbol       =HistoryDealGetString(,DEAL_SYMBOL);
            case  DEAL_TYPE_BUY:
            case  DEAL_TYPE_SELL:

Here we wait for the position closing deal (DEAL_ENTRY_OUT). Once this deal appears, we check the deal position (if we close a BUY, this will be a Sell deal, and vice versa) and we open a new position.

Translated from Russian by MetaQuotes Software Corp.
Original code:

up3x1 Investor up3x1 Investor

Candlestick size analysis. The idea of the trading system: candlestick parameters matter after news releases.

New Random New Random

Trading based on a random number generator or in one of the following sequences: BUY - SELL - BUY or SELL - BUY - SELL.

HTML file converter for the economic calendar HTML file converter for the economic calendar

HTML file converter for the economic calendar. The script parses a page downloaded from, and forms a CSV file with the list of news.

Psychological Psychological

A classic oscillator imported from the FXAccuCharts platform.