MQL4实时时钟(逐秒)。 - 页 3

 
brewmanz:

A) 不要把MT4当做实时时钟使用。这有点像让狗用后腿走路--看到它的动作很有趣,但实际上没有什么效果。

B) 为什么对每一秒钟的处理如此关键?如果滴答声没有发生什么,那么价格也不会发生什么。

(每个评论值1美分)


A) 我们为什么不应该!只是PC或服务器时间
;我想我们可以准确地获得信息。

B)为什么它是关键的......让我看看-- 高频交易--不是基于异步的信息,而逐点的信息是!这应该是一个有效的理由,我想。

我仍然在等待我的2分钱。

 
Ais:

MQL4参考 :https://docs.mql4.com/runtime/start: "脚本和专家在他们自己的线程中工作。自定义指标在主界面线程中工作。"


因此,你的指标在GUI的用户界面上显示时间? 实时/逐秒。
 

为了 "一秒一秒 "地工作,我们使用 "Sleep() "函数。

要做到这一点,我们要测量主程序的运行时间。

例如,让运行时间存储在变量 "int Runtime; "中,并让 "RunTime < 1000"。

然后我们调用 "Sleep (1000 - RunTime); "以确保下一次运行将在1000毫秒内发生,当然是在给定的精度下。

但是。

MQL4参考:https://docs.mql4.com/common/Sleep:"不能从自定义指标中调用Sleep()函数,因为它们在接口线程中进行计算,可能不会减速。"

 

简单的解决方案。

在你的EA中包括计算,你就可以了。

优点。

不需要调用icustom

没有指标

缺点。

没有指标。但对于高频率的交易,你*必须*使用EA,因为人类太慢了。

 

"高频 "和 "低延时 "略有不同。

而且,可视化通常用于分析或监测,而不仅仅是用于交易。

 
Ais:

"高频 "和 "低延时 "略有不同。

而且,可视化通常用于分析或监测,而不仅仅是用于交易。

如果你真的需要监控,你可以用线条重建指标行为。当然,高性能是不同的东西。

 

如果我们想在时间间隔的基础上分析和监测事件呢?
例如,每1秒。

 
Ais:

如果我们想在时间间隔的基础上分析和监测事件呢?
例如,每1秒。

只要你一说到tick-by-tick,你 ,就是指超高频....。

使用高级傅里叶变换分析超高频金融数据》(2009年)《金融研究通讯》第6卷,第47-53页(与I.Giampaoli和W.L.Ng合作)

在预定的时间间隔内取样可以定义为高频取样,其中T<t

 
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_color5 Red
#property indicator_color6 Red
#property indicator_color7 Red
#property indicator_color8 Red
//---- buffers
double open[];
double close[];
double high[];
double low[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
 
extern int MaxHistory=200;
extern int TimeInSeconds=5;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
double a.open[];
double a.close[];
double a.high[];
double a.low[];
 
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,high);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,low);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,5);
   SetIndexBuffer(2,open);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,5);
   SetIndexBuffer(3,close);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexStyle(7,DRAW_LINE);
   SetIndexBuffer(7,ExtMapBuffer8);
   ArrayResize(a.high,MaxHistory);
   ArrayResize(a.low,MaxHistory);
   ArrayResize(a.open,MaxHistory);
   ArrayResize(a.close,MaxHistory);      
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void redraw(){
   for(int i=200;i>=0;i--){
      if(i==200){
      open[i]=0;
      close[i]=0;
      high[i]=0;
      low[i]=0;
      }else{
      open[i]=a.open[i];
      close[i]=a.close[i];
      high[i]=a.high[i];
      low[i]=a.low[i];      
      }
   }
}
 
void shift(){
   for(int i=200;i>0;i--){
      a.open[i]=a.open[i-1];
      a.close[i]=a.close[i-1];
      a.high[i]=a.high[i-1];
      a.low[i]=a.low[i-1];
   }
}
 
extern int sleep=100;
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   bool running=true;
   static double price=0;
   static int t=0;
   static datetime t.r=0; 
   static bool updates=false;
   //t=TimeCurrent();
   //while(running){
      updates=false;
      if(TimeCurrent()>(t+TimeInSeconds)){
 
         shift();
         if(a.open[1]==EMPTY || a.open[1]==EMPTY_VALUE || a.open[1]==0){
            a.open[0]=Bid;
            a.close[0]=Bid;
            a.high[0]=Bid;
            a.low[0]=Bid;
         }else{
         a.open[0]=a.close[1];
         a.high[0]=a.close[1];
         a.low[0]=a.close[1];
         a.close[0]=a.close[1];
         }
         Print("shift "+a.open[0]+" - "+a.open[1]);
         updates=true;
         t=TimeCurrent();
      }
      if(price!=Bid){
            price=Bid;
            a.close[0]=price;
            a.high[0]=MathMax(price,a.high[0]);
            a.low[0]=MathMin(price,a.low[0]);
            updates=true;
      }       
      if(Time[0]!=t.r){
         t.r=Time[0];
         redraw();
      }else{
         if(updates){
            redraw();
         }
      }
      if(IsStopped()) running=false;
   //   Sleep(sleep);
   //}
//----
   return(0);
  }
很容易对EA重新编码,以使用适当的睡眠功能。已经这样做了。
 
zzuegg:
很容易重新编码到EA中,以使用适当的睡眠函数。已经这样做了。


很好的程序。TimeCurrent()是我们需要的逐点价格,以获得计算机价格!

也许我们可以根据实例建立一个合成时钟。

if(Time[0]! =t.r){
t.r=Time[0];
redraw()。

给我们一个提示!Zzuegg :)