I want to help to solve a simple problem

Back to topics list To post a new topic, please log in or register
avatar
39
ayoub 2015.06.12 16:37
 

hi my friend

i have two expert (expert send and other recieved ) the expert send is true but recieved is Can not read array because he read a lot of array At the same time and read first to last

Which brings error array out of range . for this i want read every last array and show this at comment

this is expert





avatar
39
ayoub 2015.06.12 16:40 #
 
expert send is
//+------------------------------------------------------------------+
//|                                                         send.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//--- input parameters
input string InpFileName="m";
input string InpDirectoryName="Som";
//+------------------------------------------------------------------+
//| Structure for storing price data                                 |
//+------------------------------------------------------------------+
struct prices
  {
   datetime          date; // date
   double            bid;  // bid price
   double            ask;  // ask price
  };
//--- global variables
int    count=0;
int    size=20;
string path=InpDirectoryName+"//"+InpFileName;
prices arr[];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- allocate memory for the array
   ArrayResize(arr,size);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- write the remaining count strings if count<n
   WriteData(count);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- save data to array
   arr[count].date=TimeCurrent();
   arr[count].bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
   arr[count].ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
//--- show current data
   Print("Date = ",arr[count].date," Bid = ",arr[count].bid," Ask = ",arr[count].ask);
//--- increase the counter
   count++;
//--- if the array is filled, write data to the file and zero it out
   if(count==size)
     {
      WriteData(size);
      count=0;
     }
  }
//+------------------------------------------------------------------+
//| Write n elements of the array to file                            |
//+------------------------------------------------------------------+
void WriteData(const int n)
  {
//--- open the file
   ResetLastError();
   int handle=FileOpen(path,FILE_READ|FILE_WRITE|FILE_BIN|FILE_TXT );
   if(handle!=INVALID_HANDLE)
     {
      //--- write array data to the end of the file
      FileSeek(handle,0,SEEK_END);
      FileWriteArray(handle,arr,0,n);
      //--- close the file
      FileClose(handle);
     }
   else
      Print("Failed to open the file, error ",GetLastError());
  }

expert recieved is

//+------------------------------------------------------------------+
//|                                                      receved.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

//--- input parameters
input string InpFileName="b";
input string InpDirectoryName="b";
//+------------------------------------------------------------------+
//| Structure for storing price data                                 |
//+------------------------------------------------------------------+
struct prices
  {
   datetime          date; // date
   double            bid;  // bid price
   double            ask;  // ask price
  };
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- structure array
   prices arr[];
//--- file path
   string path=InpDirectoryName+"//"+InpFileName;
//--- open the file
   ResetLastError();
   int file_handle=FileOpen(path,FILE_READ|FILE_BIN|FILE_TXT);
   if(file_handle!=INVALID_HANDLE)
     {
      //--- read all data from the file to the array
      FileReadArray(file_handle,arr);
      //--- receive the array size
      int size=ArraySize(arr);
      //--- print data from the array
      for(int i=0;i<size;i++)
         Print("Date = ",arr[i].date," Bid = ",arr[i].bid," Ask = ",arr[i].ask);
      Print("Total data = ",size);
      //--- close the file
      FileClose(file_handle);
     }
   else
 
      Print("File open failed, error ",GetLastError());
    
    
Comment("bid" + arr[i].bid);
  
}
avatar
12995
WHRoeder 2015.06.12 17:21 #
 
   prices arr[];
   if(file_handle!=INVALID_HANDLE)
     {
      for(int i=0;i<size;i++)
         :
     }                           // at this point i==size and there is no arr[i]
   else
      Print("File open failed,   // at this point i is unknown and arr has no size.
    
    
Comment("bid" + arr[i].bid);     // this must error on either path.

avatar
39
ayoub 2015.06.12 18:53 #
 

can you help me . please

I want to read a last array

can you give the Correction expert please

avatar
39
ayoub 2015.06.12 20:24 #
 

the expert recieved is read print correct , but he read first array to last,

i want read a just every last array

please

thank you

avatar
12995
WHRoeder 2015.06.12 23:46 #
 
What is the index of the last array element?
avatar
39
ayoub 2015.06.13 16:46 #
 
I do not know

Series are on this form

0       19:25:13.249    a EURUSD,H1: Date = 2015.06.12 21:24:54 Bid = 1.1279 Ask = 1.1283
0       19:25:14.780    a EURUSD,H1: Date = 2015.06.12 21:24:57 Bid = 1.1279 Ask = 1.1281
0       19:25:18.967    a EURUSD,H1: Date = 2015.06.12 21:25:23 Bid = 1.1277 Ask = 1.1280
0       19:25:23.936    a EURUSD,H1: Date = 2015.06.12 21:25:27 Bid = 1.1277 Ask = 1.1279
0       19:25:25.530    a EURUSD,H1: Date = 2015.06.12 21:25:29 Bid = 1.1277 Ask = 1.1280
0       19:25:29.124    a EURUSD,H1: Date = 2015.06.12 21:25:31 Bid = 1.1277 Ask = 1.1278
0       19:25:44.624    a EURUSD,H1: Date = 2015.06.12 21:25:36 Bid = 1.1277 Ask = 1.1279
0       19:25:47.671    a EURUSD,H1: Date = 2015.06.12 21:25:42 Bid = 1.1277 Ask = 1.1278
0       19:25:50.014    a EURUSD,H1: uninit reason 3

I think that last array is the last Date

avatar
12995
WHRoeder 2015.06.13 18:30 #
 
ayoub: I do not know
      for(int i=0;i<size;i++)
         Print("Date = ",arr[i].date," Bid = ",arr[i].bid," Ask = ",arr[i].ask);
Yes you do. What is the value of i when you print the last one?
avatar
39
ayoub 2015.06.13 22:32 #
 
I have an idea
Can all arrays numbering

And read the largest value in the numbering to get last array

What is the best strategy Is it time or numbers ?

If you have another plan to read last give it to me,please
As for your question the Expert RECIEVED and I've put readable text above.



avatar
39
ayoub 2015.06.16 10:41 #
 

hi

i want just read last array in txt

help me please

avatar
39
ayoub 2015.06.16 11:03 #
 

I found two reference

FileIsEnding
FileIsLineEnding

how can i do this if outher way help me

it get a totale data=0

and error 5004

why
Back to topics list  

To add comments, please log in or register