所有行业的表。通过MQL5访问

 

我怎样才能得到一个交易表?到目前为止,从指标或专家顾问来看,这并不重要。如果定期(在OnTimer()或OnTick()中)我们通过CopyTicks接收ticks的历史--它们将被添加到数组MqlTick中

但是,对这个数组的简单分析不会给出答案--是否有新的交易,因为滴答时间的比较并不总是正确的,因为在一毫秒内可能有几个交易。

Tiki

 
Karputov Vladimir:

我怎样才能得到一个交易表?到目前为止,从指标或专家顾问来看,这并不重要。如果定期(在OnTimer()或OnTick()中)我们通过CopyTicks接收ticks的历史--它们将被添加到数组MqlTick中

但是,对这个数组的简单分析不会给出答案--是否有新的交易,因为滴答时间的比较并不总是正确的,因为在一毫秒内可能有几个交易。

使用onBookEvent()事件--它在市场的每次变化中被触发。

 
Karputov Vladimir:

我怎样才能得到一个交易表?到目前为止,从指标或专家顾问来看,这并不重要。如果定期(在OnTimer()或OnTick()中)我们通过CopyTicks接收ticks的历史--它们将被添加到数组MqlTick中

但是,对这个数组的简单分析不会给出答案--是否有新的交易,因为滴答时间的比较并不总是正确的,因为在一毫秒内可能有几个交易。

使用二次截断。例如,在MqlTick或甚至在OnEvent中,将上一秒到达的新ticks复制到数组。前一个值与当前数组大小的差值将表示新刻度的数量。
 
prostotrader:

使用onBookEvent()事件,它将在每次改变汇率时被触发。

粗略地说,杯子是 "刻度图抽动"--它不一定是所有交易表的变化。

瓦西里-索科洛夫
使用第二种截断法。例如,在MqlTick中,甚至在OnEvent中,将上一秒收到的新ticks复制到数组中。前一个值与当前数组大小的差值将表示新刻度的数量。
做一个类似掩码的东西:0-1-0-1,如果掩码稳定在五行和十行左右,就可以保证匹配?
 
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:

如果你稍微想一想,一定会有所有的行业。

下面是一个简单的All Trades Ribbon指标的例子


运行失败。

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,如果掩码稳定,大约有五行和十行--这意味着保证匹配?
是的。
 

卡尔普托夫-弗拉基米尔

一个 全功能的 "所有行业饲料 "指标

//+------------------------------------------------------------------+
//|                                                    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
原因: