Dukascopy
 
 
Wiki JStore Search Login

Unable to write to a file.
 Post subject: Unable to write to a file. Post rating: 0   Post Posted: Mon 28 Jan, 2013, 02:08 
User avatar

User rating: 0
Joined: Mon 28 Jan, 2013, 01:58
Posts: 7
Location: CanadaCanada
Hi,

I've currently converted most of my original system utilizing the MQL converter in Jforex. The program compiles under JForex with no problem.

However, part of the program where it is supposed to write to a text file - doesn't work - although it still compiles. The program isn't able to create/write the file, this program
otherwise works fine under MetaTrader.

The purpose of writing to file is the strategy self-optimizes and passes data to MatLab via the CSV/text file for read/writing.

I don't request exact coding instructions, just a guide-line as to what/why it is occurring and what to do (or whether this file i/o feature is not supported).

Thanks,

xtremeforex


 
 Post subject: Re: Unable to write to a file. Post rating: 0   Post Posted: Mon 28 Jan, 2013, 20:18 
User avatar

User rating: 0
Joined: Mon 28 Jan, 2013, 01:58
Posts: 7
Location: CanadaCanada
Just to be clear, my automated system DOES work and is operating under JForex with no other problems.

However, the FILE I/O part doesn't. It just gives the error and resumes what it is doing.

I am using another scheme (i.e. the DDE server) to pass information to Matlab right now (as opposed to FILE I/O), but this solution is far from optimal.

I need FileWrite from MQL to work in Jforex.


 
 Post subject: Re: Unable to write to a file. Post rating: 0   Post Posted: Fri 01 Feb, 2013, 15:37 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please provide a code sample that would reproduce the problem.


 
 Post subject: Re: Unable to write to a file. Post rating: 0   Post Posted: Mon 04 Feb, 2013, 05:37 
User avatar

User rating: 0
Joined: Mon 28 Jan, 2013, 01:58
Posts: 7
Location: CanadaCanada
Hi,

extern int length = 100;   // The amount of bars sent to be processed
double ExtMap[];           // Chart buffer
string nameData;
int init()
{
    nameData = Symbol()+".txt";         // name of the data file to be sent
   // nameData = "C:\Users\sunny\Downloads\z.txt";         // name of the data file to be sent

   return(0);
}
int start()
{
   static int old_bars = 0;   // remember the amount of bars already known   
   if (old_bars != Bars)      // if a new bar is received
   {
      write_data();                             // write the data file                             
   }     
   old_bars = Bars;              // remember how many bars are known
   return(0);
}
//+------------------------------------------------------------------+
void write_data()
{
  int handle;
  handle = FileOpen(nameData, FILE_CSV|FILE_WRITE,';');
  if(handle < 1)
  {
    Comment("Creation of "+nameData+" failed. Error #", GetLastError());
    return(0);
  }
  FileWrite(handle, ServerAddress(), Symbol(), Period());                  // heading
  FileWrite(handle, "DATE","TIME","HIGH","LOW","CLOSE","OPEN","VOLUME");   // heading
  int i;
  for (i=length-1; i>=0; i--)
  {
    FileWrite(handle, TimeToStr(Time[i], TIME_DATE), TimeToStr(Time[i], TIME_SECONDS),
                      High[i], Low[i], Close[i], Open[i], Volume[i]);
  }
  FileClose(handle);
  Comment("File "+nameData+" has been created. "+TimeToStr(TimeCurrent(), TIME_SECONDS) );
  return(0);
}


The program should write the DATE, TIME, HIGH, LOW, CLOSE, OPEN, VOLUME for every 100 bars in a simple text file.

This same program works fine in MT4. It compiles under JFOREX but when it runs, it gives an error description when ran in the historical tester.

Thanks,

xtremforex


 
 Post subject: Re: Unable to write to a file. Post rating: 0   Post Posted: Mon 04 Feb, 2013, 10:32 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Hi,

I am not sure if you want to write to a file from your strategy, as you haven`t said that, but by default, your strategy is only allowed to write to one particular location. If you want to write somewhere else, you should use the @RequiresFullAccess option in your strategy.
Take a look at https://dukascopy.com/wiki/#Write_in_File.

Maybe this helps.


 
 Post subject: Re: Unable to write to a file. Post rating: 0   Post Posted: Mon 04 Feb, 2013, 23:12 
User avatar

User rating: 0
Joined: Mon 28 Jan, 2013, 01:58
Posts: 7
Location: CanadaCanada
Hi tcsabina,

Yes, I am trying to write out bar information to a text file. Such as Date, Open, High, Close etc..

At this point, I don't care where it writes the file, as long as it can write to a file!! (for now)

But yes, I am aware of what you've mentioned because in MT4, files can only be written in particular directories. I'm aware of the @RequiresFullAccess syntax in JForex. However, note that my program is originally written in MQL so there's really no way to put this @RequiresFullAccess syntax into the code (because it belongs to Java not MQL) - unless I have access to the .JAVA source code that is created when the Converter converts from MQL -> JAVA -> JFX.

Dukascopy should really allow us to have access to this middle step (java source code) in the conversion process, it may even significantly speed up the learning curve for those transitioning from MQL to JForex as we can quickly see what are the 'equivalent statements' that will produce the desired result.

The code that I have attached above, will compile and run in the historical tester to demonstrate the error I get.

xtremeforex


 
 Post subject: Re: Unable to write to a file. Post rating: 0   Post Posted: Tue 05 Feb, 2013, 14:47 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please see changed code in the attachment.

Symbol() in JForex currently returns instrument name in format "EUR/USD". It will be changed to "EURUSD" in the next DEMO version.
Also, note that file handle may be 0.


Attachments:
FileTest.mq4 [1.98 KiB]
Downloaded 379 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Unable to write to a file. Post rating: 0   Post Posted: Wed 06 Feb, 2013, 00:21 
User avatar

User rating: 0
Joined: Mon 28 Jan, 2013, 01:58
Posts: 7
Location: CanadaCanada
Thank you API support!

Works perfect! :)


 

Jump to:  

cron
  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com