거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
조회수:
4340
평가:
(20)
게시됨:
2017.11.03 12:25
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

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 
   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_type         =-1;
      long     deal_entry        =-1;
      double   deal_volume       =0.0;
      string   deal_symbol       ="";
      if(HistoryDealSelect(trans.deal))
        {
         deal_type         =HistoryDealGetInteger(trans.deal,DEAL_TYPE);
         deal_entry        =HistoryDealGetInteger(trans.deal,DEAL_ENTRY);
         deal_volume       =HistoryDealGetDouble(trans.deal,DEAL_VOLUME);
         deal_symbol       =HistoryDealGetString(trans.deal,DEAL_SYMBOL);
        }
      else
         return;
      if(deal_entry==DEAL_ENTRY_OUT)
        {
         switch((int)deal_type)
           {
            case  DEAL_TYPE_BUY:
               m_trade.Buy(deal_volume,deal_symbol);
               break;
            case  DEAL_TYPE_SELL:
               m_trade.Sell(deal_volume,deal_symbol);
               break;
            default:
               break;
           }
        }
     }
  }

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.

MetaQuotes Ltd에서 러시아어로 번역함.
원본 코드: https://www.mql5.com/ru/code/18904

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 http://www.investing.com/economic-calendar, and forms a CSV file with the list of news.

Psychological Psychological

A classic oscillator imported from the FXAccuCharts platform.