거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

Trade Classes from MT5 for MT4 - MetaTrader 4용 라이브러리

조회수:
7237
평가:
(35)
게시됨:
2022.04.27 11:54
업데이트됨:
2022.05.06 08:20
\MQL4\Include\Trade\
OrderInfo.mqh (43.87 KB) 조회
SymbolInfo.mqh (71.44 KB) 조회
Trade.mqh (163.76 KB) 조회
MQL5 프리랜스 이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

In the process of developing a program for copying positions between accounts, it was necessary to develop essentially the same code for MT5 and MT4. The differences were only in the functions of performing trading operations. Therefore, several classes from the MT5 standard library were rewritten to work in MT4.

When using this library, it will ideally be possible to compile a program from MT5 with a compiler in MT4 so that it can work in MT4.

But there are two important limitations:

  • The program must not use any classes and libraries from MT5 that are not in MT4. For example, if CHashMap is used, then you will either have to abandon it, or also transfer it to MT4
  • All trading operations must be performed only through the CTrade class, all operations for obtaining market information - through the CPositionInfo, COrderInfo, CSymbolInfo classes

In this version, there may be some class methods that could not be found   when testing as in need of correction.

The file TradeLibraryMT5Example.mq4 is an example of a simple EA that compiles and runs on both MT5 and MT4.

The following code is used to open pending orders:

CTrade m_trade;

...

res = m_trade.OrderOpen(m_symbol, ORDER_TYPE_BUY_LIMIT , m_lot, lowPrice, lowPrice, 0 , 0 , ORDER_TIME_GTC , 0 );
res = m_trade.OrderOpen(m_symbol, ORDER_TYPE_SELL_LIMIT , m_lot, highPrice, highPrice, 0 , 0 , ORDER_TIME_GTC , 0 );

The function of calculating the total profit of all open market positions can be implemented as follows:

//+------------------------------------------------------------------+
//| Calculate total profit for all market orders                     |
//+------------------------------------------------------------------+
double GetProfit() {
   int total = PositionsTotal();
   double profit = 0;

   CPositionInfo p;

   for(int i = total - 1; i >= 0; i--) {
       if(p.SelectByIndex(i)) {
         ulong magic = p.Magic();
         string symbol = p. Symbol();
         if(magic != m_magicN || symbol != m_symbol) {
             continue ;
         }

         profit += p.Profit() + p.Commission() + p.Swap();
      }
   }

   return profit;
}

The function of closing all open positions and pending orders can be implemented as follows:

//+------------------------------------------------------------------+
//| Attempt to close all pending and market orders                   |
//+------------------------------------------------------------------+
bool TryCloseAll() {
   bool res = true ;
   
   int total;
   double profit = 0;
   ulong ticket;
   ulong magic;
   string symbol;
   
   total = OrdersTotal();

   COrderInfo o;

   for(int i = total - 1; i >= 0; i--) {
       if(o.SelectByIndex(i)) {
         magic = o.Magic();
         symbol = o.Symbol();
         if(magic != m_magicN || symbol != m_symbol) {
             continue ;
         }
         ticket = o.Ticket();

         res &= m_trade.OrderDelete(o.Ticket());
      }
   }

   total = PositionsTotal();
   
   CPositionInfo p;

   for(int i = total - 1; i >= 0; i--) {
       if(p.SelectByIndex(i)) {
         magic = p.Magic();
         symbol = p. Symbol();
         if (magic != m_magicN || symbol != m_symbol) {
             continue ;
         }
         ticket = p.Ticket();

         res &= m_trade.PositionClose(ticket) ;
      }
   }

   return res;
}


SmoothStep (generalized) SmoothStep (generalized)

SmoothStep (generalized) - metatrader 4 version

SmoothStep SmoothStep

SmoothStep (metatrader 4 version)

High Volume Bars High Volume Bars

Colors bars when their volume has exceeded more than a standard deviation, or a multiple of it. Volume is commonly used as confirmation for a break of a significant level.

Constant Range Channel Constant Range Channel

A simple indicator plotting a channel with a constant range