我的方法。核心是引擎。 - 页 95

 
Реter Konow:

也已经整理好了工会。

我还没有完全想明白,一直到最后。

这是不对的。

Char_Uint u;
   uint width,height;
   string Message; 
   //-----------------------------
   if(!ResourceReadImage("\\Experts\\Tester EA.ex4::Resource",u.Uint,width,height))Print("Failed to read resource!  ",GetLastError());
   //-----------------------------
   Message = CharArrayToString(u.Char);
   //-----------------------------
   Print(Message);

对。

Char_Uint u;
   uint width,height;
   string Message; 
   //-----------------------------
   if(!ResourceReadImage("\\Experts\\Tester EA.ex4::Resource",u.Uint,width,height))Print("Failed to read resource!  ",GetLastError());
   //-----------------------------
   double bid = u.Double;
   //-----------------------------
   Print(DoubleToString(bid));

那么代码中的粗心是什么呢?你的收件人和发件人有不同的Char_Uint结构!

 
Vasiliy Sokolov:

一路走来,并没有完全想通。

这是不对的。

对。

那么代码中的粗心是什么呢?你的收件人和发件人有不同的Char_Uint结构!

谢谢你,瓦西里。我不知道这有什么必要。虽然我也试过结构相同的变体。

总之,输出的结果不是我想要的。以下是代码。

//+------------------------------------------------------------------+
//|                                                    Tester EA.mq4 |
//|                                                      Peter Konow |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Peter Konow"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
union Char_Uint
  {
   uchar   Char[8];
   uint    Uint[2];  
   double  Double; 
  };
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   //----------------------------------------------
   if(!ObjectCreate(0,"Resource",OBJ_BITMAP_LABEL,0,0,0))Print("Object is not created!  ",GetLastError());
   else Print("Object created!");
   //-------------------------------
   if(!ObjectSetString(0,"Resource",OBJPROP_BMPFILE,"::Resource"))Print("BMPFILE is not created!");
   else Print("BMPFILE created!");
   //----------------------------------------------
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   //---------------------------
   Char_Uint u;
   //---------------------------
   u.Double = Bid;
   //---------------------------
   if(!ResourceCreate("::Resource",u.Uint,2,1,0,0,0,COLOR_FORMAT_XRGB_NOALPHA))Print("Resource is not created!");
   //---------------------------   
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+

还有收件人。

//+------------------------------------------------------------------+
//|                                              Resource reader.mq4 |
//|                                                      Peter Konow |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Peter Konow"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
union Char_Uint
  {
   uchar   Char[8];
   uint    Uint[2];  
   double  Double; 
  };
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   EventSetMillisecondTimer(5250); 
   
   if(!ObjectSetString(0,"Resource",OBJPROP_BMPFILE,"\\Experts\\Tester EA.ex4::Resource"))Print("Resource is not connected!");
   else Print("Resource connected!");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
  Char_Uint u;
   uint width,height;
   string Message; 
   //-----------------------------
   if(!ResourceReadImage("\\Experts\\Tester EA.ex4::Resource",u.Uint,width,height))Print("Failed to read resource!  ",GetLastError());
   //-----------------------------
   double bid = u.Double;
   //-----------------------------
   Print(DoubleToString(bid,5));
  }
//+------------------------------------------------------------------+

结果。

2018.12.20 17:13:37.395 Resource reader GBPUSD,M5: 9223464270575144355.75808

但至少它不会改变。该值是恒定的。(虽然它应该随着Bid值的变化而变化)。

 
Реter Konow:

但至少它不会改变。该值是恒定的。(尽管它应该改变,因为出价值改变)。

这非常奇怪,因为你的例子在我的电脑上工作正常。试着既做专家,又简单地放在两个图表上。

 
Vasiliy Sokolov:

这非常奇怪,因为你的例子在我的电脑上工作正常。试着把这两张图做成专家,并把这两张图放在一起。

好的。

 

这里是第二个图表上的第二个EA的代码。其结果是一样的...

//+------------------------------------------------------------------+
//|                                                  Tester EA 2.mq4 |
//|                                                      Peter Konow |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Peter Konow"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
union Char_Uint
  {
   uchar   Char[8];
   uint    Uint[2];  
   double  Double; 
  };
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
   if(!ObjectSetString(0,"Resource",OBJPROP_BMPFILE,"\\Experts\\Tester EA.ex4::Resource"))Print("Resource is not connected!");
   else Print("Resource connected!");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTick()
  {
  Char_Uint u;
   uint width,height;
   //-----------------------------
   if(!ResourceReadImage("\\Experts\\Tester EA.ex4::Resource",u.Uint,width,height))Print("Failed to read resource!  ",GetLastError());
   //-----------------------------
   double bid = u.Double;
   //-----------------------------
   Print(DoubleToString(bid,5));
  }
//+------------------------------------------------------------------+

它不像它应该的那样工作。

 
这里是我的资料来源,以防万一,请查看。
附加的文件:
 
Vasiliy Sokolov:
这是我的资料来源,以备不时之需,请查收。

不,同样的事情。也许是因为EA名称中的空格?你下载时没有空格,但我有空格。我将重做它。

 
Реter Konow:

不,同样的事情。也许是因为EA名称中的空格?你下载时没有空格,但我有空格。我将重做它。

试试吧。使用空格是非常不可取的。摆脱这种坏习惯。

 

写道。

2018.12.20 17:46:26.798 Tester_EA_2 EURCHF,H1: 0.00000
2018.12.20 17:46:34.801 Tester_EA_2 EURCHF,H1: Failed to read resource!  4100
4100 -

错了!错了!错了!错了!错了!错了!错了!错了!错了!错了

 

明白了。文件读取错误 - 只是忘了加一个破折号。添加了它,又得到了结果。

2018.12.20 17:55:24.590 Tester_EA_2 EURCHF,H1: 9223464270575144355.75808