Cosmetic issue

 

Beginner's question:

I wrote single code to record and export price data (all recorded ticks) into Excel:

double Ticks[65530];   		 // respects Excel range
datetime Times[65530];  	 // respects Excel range






int deinit()
  {
    int handle;
    handle=FileOpen("Ticks.csv",FILE_WRITE|FILE_CSV, " ");
    FileWrite(handle, Symbol(), "ticks recorded...");
    for(int i=0; i<=65530; i++)
       FileWrite(handle, Ticks[i], " at ", TimeHour(Times[i]),":", TimeMinute(Times[i]));
    
    FileClose(handle);
    return;
  }


int i=-1;
int start()
  {
    i++;
    Ticks[i] = Bid;   		  // here I also tried NormalizeDouble(Bid,Digits) but did not help...
    Times[i] = Time;
    Comment("Ticks recorded: ", i);
    return;
  }

One thing that annoys me is the recorded data is not lined up (see below) and I cannot solve this!

It writes me 1.451 instead of 1.4510!

Also the time: If daily Hour / Minute is one digit only it writes 13:8 instead of 13:08!

I know it's silly cosmetic issue but I have spent so much time with that...

Pls, can somebody correct my code so that it does better job?

Thanks in advance...

 
You could try using DoubleToStr but that might not give you what you want in Excel . . . why don't you just fix it in Excel ?
 
RaptorUK:
You could try using DoubleToStr but that might not give you what you want in Excel . . . why don't you just fix it in Excel ?


Yes, I am doing it in Excel using Excel functions =RIGHT(), =LEFT().

I wanted to save some muda as I transfer data to Excel quite often.

I will try your suggestion with DoubleToStr! New function for me so I will try!

Maybe I will fix it by myself, that would be the best!

Thanks

 
  1. FileWrite(handle, Ticks[i], " at ", TimeHour(Times[i]),":", TimeMinute(Times[i]));
    Don't write extra info, let excel separate the price from the datetime
    FileWrite(handle, Ticks[i], TimeToStr(Times[i]));
    and then import it. You might want to use a comma as the separator.
  2. Easy to just select the price column and add a zero then remove the zero - all prices are now equal.
  3. Print the price with full precision
    DoubleToStr(ticks[i], Digits)

 
WHRoeder:
  1. Don't write extra info, let excel separate the price from the datetime and then import it. You might want to use a comma as the separator.
  2. Easy to just select the price column and add a zero then remove the zero - all prices are not equal.
  3. Print the price with full precision

Thank you WHRoeder!

This is excellent solution!