Il mio approccio. Il nucleo è il motore. - pagina 95

 
Реter Konow:

Ho già sistemato anche i sindacati.

Non l'ho capito fino in fondo.

Non è giusto:

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);

Giusto:

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));

E qual è la disattenzione nel codice? Hai strutture Char_Uint diverse per il destinatario e il mittente!

 
Vasiliy Sokolov:

Non è esattamente calcolato fino alla fine.

Non è giusto:

Giusto:

E qual è la disattenzione nel codice? Hai strutture Char_Uint diverse per il destinatario e il mittente!

Grazie, Vasily. Non sapevo che fosse necessario. Anche se ho provato anche la variante in cui le strutture sono identiche.

Comunque, il risultato dell'output non è quello che voglio. Ecco il codice:

//+------------------------------------------------------------------+
//|                                                    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()
  {
//---
   
  }
//+------------------------------------------------------------------+

E il destinatario:

//+------------------------------------------------------------------+
//|                                              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));
  }
//+------------------------------------------------------------------+

Risultato:

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

Ma almeno non cambia. Il valore è costante. (anche se dovrebbe cambiare quando cambia il valore dell'offerta).

 
Реter Konow:

Ma almeno non cambia. Il valore è costante. (anche se dovrebbe cambiare, come cambia il valore dell'offerta).

Questo è molto strano, perché il tuo esempio sul mio computer funziona correttamente. Provate entrambi a fare gli esperti e mettete semplicemente sui due grafici.

 
Vasiliy Sokolov:

Questo è molto strano, perché il tuo esempio sul mio computer funziona correttamente. Provate entrambi dagli esperti e posizionateli sui due grafici.

Ok.

 

Ecco il codice del secondo EA sul secondo grafico. Il risultato è lo stesso...

//+------------------------------------------------------------------+
//|                                                  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));
  }
//+------------------------------------------------------------------+

Non funziona come dovrebbe.

 
Qui ci sono le mie fonti, nel caso, controllatele:
File:
 
Vasiliy Sokolov:
Qui ci sono le mie fonti, nel caso, controllatele:

No, è la stessa cosa. Forse è a causa degli spazi nei nomi EA? Tu li hai scaricati senza spazi, ma io ho degli spazi. Lo rifarò.

 
Реter Konow:

No, è la stessa cosa. Forse è a causa degli spazi nei nomi EA? Tu li hai scaricati senza spazi, ma io ho degli spazi. Lo rifarò.

Provate. L'uso degli spazi è altamente indesiderabile. Liberatevi di questa cattiva abitudine.

 

Scrive:

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 -

ERRORE_QUALSIASI_FILE_ERRORE

 

Capito. Errore di lettura del file - ho solo dimenticato di aggiungere un trattino. L'ho aggiunto e sono tornato al risultato:

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