mql5语言的特点、微妙之处以及技巧 - 页 103

 
尼古拉-森科

只是想说,也许使用user32.dll而不是kernel32.dll在使用WinAPI链接两个终端时可能会更快,因为我看到的所有实现都使用kernel32.dll。

好吧,我看不出有什么理由,从一个库中导入比从另一个库中导入更快。

也许,这与当前的MQL版本无关,但就我对旧的MQL4的记忆而言,这些成本是相当可观的,有时甚至可以与函数的执行速度相媲美。

 
fxsaber:

是的。

啊......好吧,就当是我的心血来潮吧。

我只是喜欢速度,因为谁的速度快就先谁,而且CPU上的负载也少,这意味着有更多的资源和时间来做决定。

 
fxsaber
快速的多符号OnTick实现

当使用间谍对50个符号运行一个空的专家顾问时,日志中的信息开始堆积。

2018.10.09 22:49:24.730 Spy (AUDNZD,W1) indicator is too slow, 4281 ms. rewrite the indicator, please

如果我在指标中添加一个过滤器,用于发送500ms的castum事件的频率,错误变得不那么频繁,但它们并没有消失。

只有我吗?


EA代码。

#define  ForEach(index,array)   for(int index=0, max_##index=ArraySize(array);  index<max_##index;  index++)

string Symbols[];

int OnInit()
{
   ArrayResize( Symbols, SymbolsTotal(true) );

   ForEach( i, Symbols )
   {
      Symbols[i] = SymbolName(i,true);

      if( Symbols[i] != _Symbol )
         iCustom( Symbols[i], PERIOD_W1, "Spy.ex5", ChartID(), i );
   }
   return(INIT_SUCCEEDED);
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
   if( id == CHARTEVENT_CUSTOM )
      OnTickMS( Symbols[ (int)lparam ] );
}

void OnTick()
{
   CheckSignal( _Symbol );
}

void OnTickMS(const string &Symb)
{
   CheckSignal( Symb );
}

void CheckSignal(const string symbol)
{
   //Comment( symbol, ": ",
   //                   DoubleToString( SymbolInfoDouble( symbol, SYMBOL_BID ), 5 ), " / ",
   //                   DoubleToString( SymbolInfoDouble( symbol, SYMBOL_ASK ), 5 ) );
   return;
}


Profiler 显示95%的iCustom时间,OnChartEvent几乎不需要。处理器(i5-3570)的负载为75%。

 
Andrey Khatimlianskii:

当使用50个工具的间谍运行一个空的EA时,信息开始涌入日志。

只有我吗?

我在一开始就发现了其中的几个错误。我没有进一步了解他们。

剖析器 显示95%的iCustom时间,OnChartEvent几乎不需要。CPU(i5-3570)负载为75%。

在释放版中,CPU是~3%。

 
fxsaber:

一开始就抓住了其中的几个错误。没有进一步的崩溃。

释放版有CPU ~3%。

我用 "优化=1 "建立了指标和专家顾问,仍然出现错误。

 

为指标增加了一秒钟的停顿。

int OnCalculate( const int rates_total, const int prev_calculated, const int, const double &[] )
{
   static datetime prev = 0;
   if ( TimeCurrent() <= prev ) return(rates_total);
   prev = TimeCurrent();

错误仍然存在。

 

指标

#property indicator_chart_window
#property indicator_plots 0

input long Chart = 0; // идентификатор графика-получателя события
input int  Index = 0;

ulong timer = GetMicrosecondCount();
//===================================================================
//| 
//+------------------------------------------------------------------
int OnCalculate( const int rates_total, const int prev_calculated, const int, const double &[] )
{
   if( GetMicrosecondCount() - timer < 1 e6 ) return( rates_total );
   
   timer = GetMicrosecondCount();
   
   if( prev_calculated )
   {
      ResetLastError();
      
      if( EventChartCustom( Chart, 0, Index, 0, NULL ))
         Print( GetMicrosecondCount() - timer );
      else
         Print( (string)_LastError +" "+ (string)(GetMicrosecondCount() - timer) );
   }
   
   return( rates_total );
}
//+------------------------------------------------------------------

EA

#property strict
//+------------------------------------------------------------------
#define  ForEach(index,array)               for(int index=0, max_##index=ArraySize(array);  index<max_##index;  index++)
//+------------------------------------------------------------------
string Symbols[];

//===================================================================
//| Expert initialization function
//+------------------------------------------------------------------
int OnInit()
{
   ArrayResize( Symbols, SymbolsTotal(true) );
   
   ForEach( i, Symbols )
   {
      Symbols[i] = SymbolName(i,true);
      
      if( Symbols[i] != _Symbol )
         iCustom( Symbols[i], PERIOD_W1, "Spy.ex5", ChartID(), i ); // MQL5\Indicators\Spy.ex5
   }
   
   return(INIT_SUCCEEDED);
}
//===================================================================
//| Expert deinitialization function
//+------------------------------------------------------------------
void OnDeinit(const int reason)
{
   ArrayFree( Symbols );
}
//===================================================================
//| ChartEvent function
//+------------------------------------------------------------------
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
}
//===================================================================
//| Expert tick function
//+------------------------------------------------------------------
void OnTick()
{
}
//+------------------------------------------------------------------


增加暂停时间并没有什么帮助。它甚至在3秒内就开始崩溃了。

由于未知的原因,在某一时刻,EventChartCustom 停止工作。停顿约3秒,并产生错误4001。

附加的文件:
20181010.log  276 kb
 
奥列克西-切普尔尼

指标

EA


增加暂停时间并没有什么帮助。甚至在3秒时就开始崩溃了。

由于一些未知的原因,在某一时刻,EventChartCustom停止工作。停顿了大约3秒钟,并给出了错误4001。

是的,这似乎是问题所在。

还有人在播放吗?

 
安德烈-哈蒂姆连斯基

它还在播放吗?

不是的。

#define  ForEach(index,array)   for(int index=0, max_##index=ArraySize(array);  index<max_##index;  index++)

string Symbols[];
int Counter[];

int OnInit()
{
   ArrayResize(Counter, ArrayResize( Symbols, SymbolsTotal(true) ));   
   ArrayInitialize(Counter, 0);

   ForEach( i, Symbols )
   {
      Symbols[i] = SymbolName(i,true);

      if( Symbols[i] != _Symbol )
         if (iCustom( Symbols[i], PERIOD_W1, "Spy.ex5", ChartID(), i ) == INVALID_HANDLE)
          Alert(Symbols[i]);
   }
   return(INIT_SUCCEEDED);
}

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
   static int Count = 0;
   
   if( id == CHARTEVENT_CUSTOM )
   {
     Counter[(int)lparam]++;
     
     string Str = (string)Count++ + "\nMarketWatch:";
     
     for (int i = 0; i < ArraySize(Counter); i++)
      Str += "\n" + (string)i + ": " + Symbols[i] + " " + (string)Counter[i];
      
     Comment(Str);
   }
}


一个小时的工作--飞行是正常的。

 
fxsaber:

没有回放


一个小时的工作--飞行正常。

在市场审查中,有多少文书?