26.08.15
|
Neues Mitglied
|
|
Registriert seit: May 2015
Beiträge: 28
|
|
Array einspeichern und wieder aufrufen!
Hallo, wäre mal wieder sehr dankbar, wenn mir hier jmd. aushelfen kann.
Und zwar möchte ich meine Daten extern speichern mit der Funktion FileSaveArray und dann wieder öffnen.
mein einer expert "tester2" sollte einspeichern "tester3" entsprechend wieder öffnen und daten auslesen, ich bekomme zwar keine fehlermeldung, aber tester 3 kann die daten nicht öffnen/übertragen.
tester2:
Code:
input string InpFileName="data1.bin";
input string InpDirectoryName="Folder";
double Abstand4;
struct prices
{
double MA7M5Save1; //
double MA7M5Save2; //
double MA7M5Save3; //
};
string path=InpDirectoryName+"//"+InpFileName;
prices arr[];
int xM5=0;
int size1=2;
int OnInit()
{
ArrayResize(arr,size1);
return(INIT_SUCCEEDED);
}
void OnTick(){
Abstand4=1;
arr[xM5].MA7M5Save1=Abstand4;
arr[xM5].MA7M5Save2=Abstand4;
arr[xM5].MA7M5Save3=Abstand4;
FuenfMinutenVorbei=false;
xM5++;
if(xM5==size1)
{
WriteData(size1);
xM5=0;
}
}
void WriteData(const int n)
{
//--- open the file
ResetLastError();
int handle=FileOpen(path,FILE_READ|FILE_WRITE|FILE_BIN);
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());
}
tester3 -"FileOpen"
Code:
#include <mt4gui.mqh>
#include <stdlib.mqh>
#include <WinUser32.mqh>
input string InpFileName="data1.bin";
input string InpDirectoryName="Folder";
struct prices
{
double MA7M5Save1; //
double MA7M5Save2; //
double MA7M5Save3; //
};
int hwnd;
double test;
int panel2;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- structure array
prices arr[];
//--- file path
string path=InpDirectoryName+"//"+InpFileName;
//--- open the file
ResetLastError();
int file_handle=FileOpen(path,FILE_READ|FILE_BIN);
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++)
test=arr[i].MA7M5Save1;
//--- close the file
FileClose(file_handle);
}
else
Print("File open failed, error ",GetLastError());
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if (hwnd>0) { guiRemoveAll(hwnd); guiCleanup(hwnd ); }
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
BuildInterface2();
}
//+------------------------------------------------------------------+
void BuildInterface2(){
hwnd = WindowHandle(Symbol(),Period());
panel2 = guiAdd(hwnd,"label",0,0,260,230,"Move it baby");
guiSetBgColor(hwnd,panel2,Gray);
}
void M7Label(){
guiSetText(hwnd,panel2,"test "+ DoubleToStr(test,5) ,14,"Terminal");
}
Für eine schnelle Lösung biete ich als Anreiz zur Lösung 2 Euro via Paypal an.
Einfach paypal Mail an mich per Pn schichken.
Freundliche Grüße
Welling
|