Download MetaTrader 5

Record Market Watch

To add comments, please log in or register
GrumpyDuckMan
590
GrumpyDuckMan  

Hello everyone,

I have had this on the back burners for some time now.

I have removed some parts of the code so that it is hopefully easier to read. (note: Full code isn't functioning)

void Market_Watch()
  {
   CurrentSymbol = SymbolName(Next_Symbol,TRUE);
   CurrAsk       = MarketInfo(CurrentSymbol,MODE_ASK);
   CurrBid       = MarketInfo(CurrentSymbol,MODE_BID);
   Spread        = MarketInfo(CurrentSymbol,MODE_SPREAD);
   Next_Symbol++;
   WriteToFile();
  }
//------------------------------------------------------------------+  
void WriteToFile()
  {
   FileHandle=FileOpen(subfolder+"\\Test.txt",FILE_READ|FILE_WRITE|FILE_TXT);
   if(FileHandle!=INVALID_HANDLE)
     {
      new_str="  ";
      FileWrite(FileHandle,new_str);
     }
   else
      Print("Operation File Open failed,error ",GetLastError());
   FileClose(FileHandle);
  }  
//------------------------------------------------------------------+

I would like to import to a Excel spread sheet for further analysis.

How do I make the file available?

(Note: I am not deleting previous entries)

Carl Schreiber
Moderator
7955
Carl Schreiber  
Have you googled: "mt4 read csv file"?
whroeder1
17092
whroeder1  

GrumpyDuckMan:

I would like to import to a Excel spread sheet for further analysis. How do I make the file available?

(Note: I am not deleting previous entries)

  1. Makes no sense. Open it in Excel, It's available like any other file. It's in <Data Folder>\files since 17.02.2014
              Data Structure in MetaTrader 4 Build 600 and Higher - MQL4 Articles 17.02.2014
  2. You are writing one string. If you make it a CSV (not TXT) then you can write multiple items per line with the appropriate separator, (see below.)
  3. You are overwriting each time because you never seek to the end.
       int         APPEND   = FILE_CSV|FILE_WRITE|FILE_READ;
       string      nameOPT  = WindowExpertName() + ".OPT";
       int      handleOPT   = FileOpen(nameOPT, APPEND, '~');   if(handleOPT < 1){...}
       FileSeek(handleOPT, 0, SEEK_END);
    


GrumpyDuckMan
590
GrumpyDuckMan  

Hello whroeder1,

It works.  Thank you

void Market_Watch()
  {
   CurrentSymbol = SymbolName(Next_Symbol,TRUE); // 23 pairs in watch window
   CurrAsk       = MarketInfo(CurrentSymbol,MODE_ASK);
   CurrBid       = MarketInfo(CurrentSymbol,MODE_BID);
   Spread        = MarketInfo(CurrentSymbol,MODE_SPREAD);
   READplus      = iADX(NULL,TIMEFRAME,14,PRICE_CLOSE,MODE_PLUSDI,SHIFT);
   READminus     = iADX(NULL,TIMEFRAME,14,PRICE_CLOSE,MODE_MINUSDI,SHIFT);
   CurrentADX    = iADX(NULL,TIMEFRAME,14,PRICE_CLOSE,MODE_MAIN,SHIFT);
   StochMain     = iStochastic(CurrentSymbol,TIMEFRAME,14,3,3,MODE_SMMA,0,MODE_MAIN,SHIFT);
   StochSignal   = iStochastic(CurrentSymbol,TIMEFRAME,14,3,3,MODE_SMMA,0,MODE_SIGNAL,SHIFT);
   Preiod_IMA    = iMA(CurrentSymbol,TIMEFRAME,14,1,MODE_SMMA,PRICE_CLOSE,SHIFT);
   RSI_14        = iRSI(CurrentSymbol,TIMEFRAME,14,PRICE_CLOSE,SHIFT);
   MoneyFlow     = iMFI(CurrentSymbol,TIMEFRAME,30,SHIFT);

   if(Next_Symbol==0)
     {
      Next_Symbol=23;
     }
   WriteToFile();
  }
//------------------------------------------------------------------+  
void WriteToFile()
  {
   FileHandle=FileOpen(subfolder+"\\RunTest.csv",Append,',');
   if(FileHandle!=INVALID_HANDLE)
     {
      FileSeek(FileHandle,0, SEEK_END);
      string  DataName = CurrentSymbol;
      FileWrite(FileHandle,CurrentSymbol,CurrAsk,CurrBid,Spread,CurrentADX,
      READplus,READminus,StochMain,StochSignal,Preiod_IMA,RSI_14,MoneyFlow);
      
     }
   else
      Print(Error,GetLastError());
   FileClose(FileHandle);
   Next_Symbol--;
   Market_Watch();
  }
//+-----------------------------------------------------------------+ 
GrumpyDuckMan
590
GrumpyDuckMan  

Hello again,

Just a quick one.

Is FileSeek Offset used only in "Filename.txt"?

FileSeek(FileHandle,255, SEEK_END);

I can't see any difference changing its value with "Filename.CSV"

Mohammad Hossein Sadeghi
2059
Mohammad Hossein Sadeghi  
GrumpyDuckMan:

Hello again,

Just a quick one.

Is FileSeek Offset used only in "Filename.txt"?

I can't see any difference changing its value with "Filename.CSV"

FileSeek works on any file type.  It move the file pointer of the provided handle to a file.
GrumpyDuckMan
590
GrumpyDuckMan  

Hello Hohammad,

Excuse me if my current newbie understanding in incorrect.

      FileSeek(FileHandle,0, SEEK_END);
      string  DataName = CurrentSymbol;
      FileWrite(FileHandle,CurrentSymbol,CurrAsk,CurrBid,Spread,CurrentADX,
      READplus,READminus,StochMain,StochSignal,Preiod_IMA,RSI_14,MoneyFlow);

Code above:

FileSeek is looking for the handle to finish. The pointer counts until end of line. It restarts and processes for the next line, after the pointer index is incremented next.

whroeder1
17092
whroeder1  
You need the one seek after opening to append, other wise you will overwrite existing lines.
GrumpyDuckMan
590
GrumpyDuckMan  

Hello again,

After trying to graph my results today with 25 pairs for 12 hours with a 1 hour timeframe proved information. My test was not really any sort of success, just very messing graphs. 

I will try again with 1 pair over 12 hours.

To add comments, please log in or register