모든 거래의 테이블. MQL5를 통한 액세스

 

거래 테이블 영수증을 구성하는 방법은 무엇입니까? 현재로서는 지표나 Expert Advisor에서 중요하지 않습니다. 주기적으로(OnTimer() 또는 OnTick()에서) 틱 기록이 CopyTicks를 통해 수신되면 MqlTick 배열에 추가됩니다.

그러나 1밀리초에 여러 트랜잭션이 있을 수 있기 때문에 틱 시간을 비교하는 것이 항상 정확한 것은 아니기 때문에 이 배열에 대한 간단한 분석은 새 트랜잭션이 있었는지 여부에 대한 답을 제공하지 않습니다.

티키

 
Karputov Vladimir :

거래 테이블 영수증을 구성하는 방법은 무엇입니까? 현재로서는 지표나 Expert Advisor에서 중요하지 않습니다. 주기적으로(OnTimer() 또는 OnTick()에서) 틱 기록이 CopyTicks를 통해 수신되면 MqlTick 배열에 추가됩니다.

그러나 1밀리초에 여러 트랜잭션이 있을 수 있기 때문에 틱 시간을 비교하는 것이 항상 정확한 것은 아니기 때문에 이 배열에 대한 간단한 분석은 새 트랜잭션이 있었는지 여부에 대한 답을 제공하지 않습니다.

onBookEvent() 이벤트를 사용하면 주문서가 변경될 때마다 발생합니다.

 
Karputov Vladimir :

거래 테이블 영수증을 구성하는 방법은 무엇입니까? 지표 또는 고문에서 아직 중요하지 않습니다. 주기적으로(OnTimer() 또는 OnTick()에서) 틱 기록이 CopyTicks를 통해 수신되면 MqlTick 배열에 추가됩니다.

그러나 1밀리초에 여러 트랜잭션이 있을 수 있기 때문에 틱 시간을 비교하는 것이 항상 정확한 것은 아니기 때문에 이 배열에 대한 간단한 분석은 새 트랜잭션이 있었는지 여부에 대한 답을 제공하지 않습니다.

초를 사용합니다. 예를 들어, MqlTick 또는 OnEvent에서도 마지막 1초 동안 수신된 새 틱을 배열에 복사합니다. 이전에 저장된 값과 현재 배열 크기의 차이는 새 틱 수를 나타냅니다.
 
prostotrader :

onBookEvent() 이벤트를 사용하면 주문서가 변경될 때마다 발생합니다.

오더북은 대략적으로 "틱 차트의 요동"입니다. 이것이 반드시 모든 거래 테이블의 변경 사항은 아닙니다.

바실리 소콜로프 :
초를 사용합니다. 예를 들어, MqlTick 또는 OnEvent에서도 마지막 1초 동안 수신된 새 틱을 배열에 복사합니다. 이전에 저장된 값과 현재 배열 크기의 차이는 새 틱 수를 나타냅니다.
마스크와 같은 작업을 수행합니다. 0-1-0-1, 마스크가 약 5~10줄에서 안정적이면 일치가 보장된다는 의미인가요?
 
Karputov Vladimir :

오더북은 대략적으로 "틱 차트의 요동"입니다. 이것이 반드시 모든 거래 테이블의 변경 사항은 아닙니다.


조금만 생각하면 분명히 모든 거래가 있을 것입니다.

다음은 "모든 거래의 테이프" 표시기의 간단한 예입니다.

 //+------------------------------------------------------------------+
//|                                                    DealsLent.mq5 |
//|                                     Copyright 2016, prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, prostotrader"
#property link        "https://www.mql5.com"
#property version    "1.00"
input int   Ticks     = 100 ; //Тики 

#property indicator_separate_window

#property indicator_buffers 2
#property indicator_plots    2

//--- plot Label1
#property indicator_label1   "Sell"
#property indicator_type1   DRAW_LINE
#property indicator_color1   clrRed
#property indicator_style1   STYLE_SOLID
#property indicator_width1   1
//--- plot Label1
#property indicator_label2   "Buy"
#property indicator_type2   DRAW_LINE
#property indicator_color2   clrBlue
#property indicator_style2   STYLE_SOLID
#property indicator_width2   1
//--- indicator buffers
double SellBuffer[];
double BuyBuffer[];
double sell_deals;
double buy_deals;
long curr_time;
int event_cnt;
bool on_call;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
   curr_time= 0 ;
   if (! MarketBookAdd ( Symbol ()))
     {
       Print ( __FUNCTION__ , ": Стакан символа " + Symbol ()+ " не добавден!" );
       return ( INIT_FAILED );
     }
//--- Period 
   if ( Period ()!= PERIOD_M1 )
     {
       Print ( "Ошибка! Период графика должен быть 'M1'" );
       return ( INIT_FAILED );
     }
//---  
   IndicatorSetInteger ( INDICATOR_DIGITS , 0 );
   IndicatorSetString ( INDICATOR_SHORTNAME , "DealsLent" );
//---  
   SetIndexBuffer ( 0 ,SellBuffer, INDICATOR_DATA );
   PlotIndexSetDouble ( 0 , PLOT_EMPTY_VALUE , EMPTY_VALUE );
   ArraySetAsSeries (SellBuffer, true );
//---
   SetIndexBuffer ( 1 ,BuyBuffer, INDICATOR_DATA );
   PlotIndexSetDouble ( 1 , PLOT_EMPTY_VALUE , EMPTY_VALUE );
   ArraySetAsSeries (BuyBuffer, true );
//--- 
   event_cnt= 0 ;
   on_call= false ;
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+  
void OnDeinit ( const int reason)
  {
   MarketBookRelease ( Symbol ());
   if (reason== REASON_INITFAILED )
     {
       int window= ChartWindowFind ( ChartID (), "DealsLent" );
       ChartIndicatorDelete ( ChartID (),window, "DealsLent" );
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator On book event function                          |
//+------------------------------------------------------------------+
void OnBookEvent ( const string &symbol)
  {
   MqlTick ticks[];
   if (symbol== Symbol ())
     {
       if (curr_time== 0 )
        {
         if ( CopyTicks ( Symbol (),ticks, COPY_TICKS_ALL , 0 , 1 )== 1 )
           {
            curr_time=ticks[ 0 ].time_msc;
           }
        }
       else
        {
         sell_deals= 0 ;
         buy_deals = 0 ;
         if ( CopyTicks ( Symbol (),ticks, COPY_TICKS_ALL , 0 ,Ticks)==Ticks)
           {
             for ( int i= 0 ; i<Ticks; i++)
              {
               if (ticks[i].time_msc!=curr_time)
                 {
                   if (( ticks[i].flags  & TICK_FLAG_BUY )== TICK_FLAG_BUY )
                    {
                     buy_deals++;
                    }
                   else
                   if (( ticks[i].flags  & TICK_FLAG_SELL )== TICK_FLAG_SELL )
                    {
                     sell_deals++;
                    }
                 }
              }
           }
         curr_time=ticks[ 0 ].time_msc;
         double price[];
         on_call= true ;
         OnCalculate (event_cnt,event_cnt, 0 ,price);
        }
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate ( const int rates_total,
                 const int prev_calculated,
                 const int begin,
                 const double &price[])
  {
   if (prev_calculated== 0 )
     {
       ArrayInitialize (SellBuffer, EMPTY_VALUE );
       ArrayInitialize (BuyBuffer, EMPTY_VALUE );
     }
   else
     {
       if (rates_total==event_cnt)
        {
         if (on_call)
           {
            on_call= false ;
             //---        
             for ( int i=rates_total- 1 ; i> 0 ; i--)
              {
               SellBuffer[i]= SellBuffer[i- 1 ];
               BuyBuffer[i] = BuyBuffer[i- 1 ];
              }
            SellBuffer[ 0 ]= double (sell_deals);
            BuyBuffer[ 0 ] = double (buy_deals);
           }
        }
       else
        {
         if (on_call)
           {
            on_call= false ;
            SellBuffer[ 0 ]= double (sell_deals);
            BuyBuffer[ 0 ] = double (buy_deals);
           }
         else
           {
            SellBuffer[ 0 ]= SellBuffer[ 1 ];
            BuyBuffer[ 0 ] = BuyBuffer[ 1 ];
           }
        }
     }
   event_cnt=rates_total;
//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+------------------------------------------------------------------+


 
prostotrader :

조금만 생각하면 분명히 모든 거래가 있을 것입니다.

다음은 "모든 거래의 테이프" 표시기의 간단한 예입니다.


실행 실패:

2016.08.24 15:54:41.700 DealsLent (RTS-12.16,M1)        array out of range in 'DealsLent.mq5' (118,25)

실수

 
Karputov Vladimir :

실행 실패:

void OnBookEvent(const string &symbol)
  {
   MqlTick ticks[];
   if(symbol==Symbol())
     {
      if(curr_time==0)
        {
         if(CopyTicks(Symbol(),ticks,COPY_TICKS_ALL,0,1)==1)
           {
            curr_time=ticks[0].time_msc;
           }
        }
      else
        {
         sell_deals= 0;
         buy_deals = 0;
         if(CopyTicks(Symbol(),ticks,COPY_TICKS_ALL,0,Ticks)==Ticks)
           {
            for(int i=0; i<Ticks; i++)
              {
               if(ticks[i].time_msc!=curr_time)
                 {
                  if(( ticks[i].flags  &TICK_FLAG_BUY)==TICK_FLAG_BUY)
                    {
                     buy_deals++;
                    }
                  else
                  if(( ticks[i].flags  &TICK_FLAG_SELL)==TICK_FLAG_SELL)
                    {
                     sell_deals++;
                    }
                 }
              }
             curr_time=ticks[0].time_msc; 
             double price[];
             on_call=true;
             OnCalculate(event_cnt,event_cnt,0,price);
           }
        }
     }
  }
 
Karputov Vladimir :

오더북은 대략적으로 "틱 차트의 요동"입니다. 이것이 반드시 모든 거래 테이블의 변경 사항은 아닙니다.

마스크와 같은 작업을 수행합니다. 0-1-0-1, 마스크가 약 5~10줄에서 안정적이면 일치가 보장된다는 의미인가요?
네.
 

블라디미르 카르푸토프

모든 기능 갖춘 표시기 "모든 거래의 테이프"를 제공합니다.

 //+------------------------------------------------------------------+
//|                                                    DealsLent.mq5 |
//|                                     Copyright 2016, prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, prostotrader"
#property link        "https://www.mql5.com"
#property version    "1.00"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots    2
//--- plot Label1
#property indicator_label1   "Sell"
#property indicator_type1   DRAW_LINE
#property indicator_color1   clrRed
#property indicator_style1   STYLE_SOLID
#property indicator_width1   1
//--- plot Label1
#property indicator_label2   "Buy"
#property indicator_type2   DRAW_LINE
#property indicator_color2   clrBlue
#property indicator_style2   STYLE_SOLID
#property indicator_width2   1
//--- indicator buffers
double SellBuffer[];
double BuyBuffer[];
double sell_deals;
double buy_deals;
ulong start_time;
int event_cnt;
bool on_call;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
   start_time= 0 ;
   if (! MarketBookAdd ( Symbol ()))
     {
       Print ( __FUNCTION__ , ": Стакан символа " + Symbol ()+ " не добавден!" );
       return ( INIT_FAILED );
     }
//--- Bars
   int bars= Bars ( Symbol (), PERIOD_CURRENT );
   if (bars< 3 )
  {
     Print ( __FUNCTION__ , ": Не достаточно баров на текущем таймфрейме!" );
     return ( INIT_FAILED );
  }     
//---  
   IndicatorSetInteger ( INDICATOR_DIGITS , 0 );
   IndicatorSetString ( INDICATOR_SHORTNAME , "DealsLent" );
//---  
   SetIndexBuffer ( 0 ,SellBuffer, INDICATOR_DATA );
   PlotIndexSetDouble ( 0 , PLOT_EMPTY_VALUE , EMPTY_VALUE );
   ArraySetAsSeries (SellBuffer, true );
//---
   SetIndexBuffer ( 1 ,BuyBuffer, INDICATOR_DATA );
   PlotIndexSetDouble ( 1 , PLOT_EMPTY_VALUE , EMPTY_VALUE );
   ArraySetAsSeries (BuyBuffer, true );
//--- 
   event_cnt= 0 ;
   on_call= false ;
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+  
void OnDeinit ( const int reason)
  {
   MarketBookRelease ( Symbol ());
   if (reason== REASON_INITFAILED )
     {
       int window= ChartWindowFind ( ChartID (), "DealsLent" );
       ChartIndicatorDelete ( ChartID (),window, "DealsLent" );
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator On book event function                          |
//+------------------------------------------------------------------+
void OnBookEvent ( const string &symbol)
  {
   MqlTick ticks[];
   if (symbol== Symbol ())
     {
       if (start_time== 0 )
        {
         if ( CopyTicks ( Symbol (),ticks, COPY_TICKS_ALL , 0 , 1 )== 1 )
           {
            start_time= ulong (ticks[ 0 ].time_msc);
           }
        }
       else
        {
         sell_deals= 0 ;
         buy_deals = 0 ;
         int copied= CopyTicks ( Symbol (),ticks, COPY_TICKS_ALL ,start_time, 0 );
         if (copied> 0 )
           {
             for ( int i= 0 ; i<copied; i++)
              {
               if (( ticks[i].flags  & TICK_FLAG_BUY )== TICK_FLAG_BUY )
                 {
                  buy_deals++;
                 }
               else
               if (( ticks[i].flags  & TICK_FLAG_SELL )== TICK_FLAG_SELL )
                 {
                  sell_deals++;
                 }
              }
            start_time= ulong (ticks[copied - 1 ].time_msc);
             double price[];
            on_call= true ;
             OnCalculate (event_cnt,event_cnt, 0 ,price);
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate ( const int rates_total,
                 const int prev_calculated,
                 const int begin,
                 const double &price[])
  {
   if (prev_calculated== 0 )
     {
       ArrayInitialize (SellBuffer, EMPTY_VALUE );
       ArrayInitialize (BuyBuffer, EMPTY_VALUE );
     }
   else
     {
       if (rates_total==event_cnt)
        {
         if (on_call)
           {
            on_call= false ;
             //---        
             for ( int i=rates_total- 1 ; i> 0 ; i--)
              {
               SellBuffer[i]= SellBuffer[i- 1 ];
               BuyBuffer[i] = BuyBuffer[i- 1 ];
              }
            SellBuffer[ 0 ]= double (sell_deals);
            BuyBuffer[ 0 ] = double (buy_deals);
           }
        }
       else
        {
         if (on_call)
           {
            on_call= false ;
            SellBuffer[ 0 ]= double (sell_deals);
            BuyBuffer[ 0 ] = double (buy_deals);
           }
         else
           {
            SellBuffer[ 0 ]= SellBuffer[ 1 ];
            BuyBuffer[ 0 ] = BuyBuffer[ 1 ];
           }
        }
     }
   event_cnt=rates_total;
//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+------------------------------------------------------------------+
 
prostotrader :

카르푸토프 블라디미르

모든 기능 갖춘 표시기 "모든 거래의 테이프"를 제공합니다.

글쎄요, 감사합니다!! 요전날 내 머리 속에 맴도는 이 아이디어에 대해
 
오류를 찾아 작업을 최적화했습니다.
파일:
DealsLent.mq5  6 kb
사유: