HELP - What to delete in script to only export close price?

 

i don't get it, all my attempts failed. i have this script that exports history of multiple pairs, i need it to only export time and close price, and they have to remain in the same row, 2nd and 7th.

is it this part? can't figure out what to delete or modify, always stops working :(

iDigits=MarketInfo(Symbol(),MODE_DIGITS);
 dSymOpen = (iOpen(dSymbol,Period(),i));
 dSymHigh = (iHigh(dSymbol,Period(),i));
 dSymHigh_D1 = (iHigh(dSymbol,Period(),i));
 dSymLow = (iLow(dSymbol,Period(),i));
 dSymClose = (iClose(dSymbol,Period(),i));
 dSymVolume = (iVolume(dSymbol,Period(),i));
 WriteString(DoubleToStr(dSymOpen, iDigits)+",");
 WriteString(DoubleToStr(dSymHigh, iDigits)+",");
 WriteString(DoubleToStr(dSymLow, iDigits)+",");
 WriteString(DoubleToStr(dSymClose, iDigits)+",");
 WriteString("\n");



here the entire script

//--------------------------------
//----
 int handle;
 
 //number of bars to export per Symbol
 int maxBars = 501;
 //test first on several pairs
string Currencies[] = {"AUDCAD", "AUDCHF", "AUDJPY", "AUDNZD", "AUDUSD", "CADCHF", "CADJPY", "CHFJPY", "EURAUD", "EURCAD", "EURCHF", "EURGBP", "EURJPY", "EURNZD", "EURUSD", "GBPAUD", "GBPCAD", "GBPCHF", "GBPJPY", "GBPNZD", "GBPUSD", "NZDCAD", "NZDCHF", "NZDJPY", "NZDUSD", "USDCAD", "USDCHF", "USDJPY"};
 
 
 // then add more in the same format
// string Currencies[] = {"AUDUSD","EURUSD","GBPJPY","GBPUSD","EURJPY","EURGBP","USDCHF","USDJPY","AUDJPY","CHFJPY","CADJPY","GBPCAD","EURAUD","USDCAD","EURCAD","NZDUSD","NZDJPY"};
string dSymbol;

//+------------------------------------------------------------------+
//|  start function                                    |
//+------------------------------------------------------------------+
int start(){
 int count = ArraySize(Currencies);
 for (int ii=0; ii<count; ii++){
 dSymbol = Currencies[ii];   
 handle = FileOpen("Hist_"+dSymbol+".csv", FILE_BIN|FILE_WRITE);

if(handle < 1){
 Print("Err ", GetLastError());
return(0);
}
 WriteTABLEHeader();

for(int i = 0; i < maxBars - 1; i++){
 WriteRow(i);
}
 FileClose(handle);
}
 Alert("Done."+TimeMonth(TimeLocal())+TimeDay(TimeLocal())+TimeYear(TimeLocal()) +"_"+TimeHour(TimeLocal())+TimeMinute(TimeLocal()));

  return(0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void WriteString(string txt){
   FileWriteString(handle, txt,StringLen(txt));
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void WriteTABLEHeader(){
 WriteString("Date,");
 WriteString("Time,");
 WriteString("DayOfWeek,");
 WriteString("Open,");
 WriteString("High,");
 WriteString("Low,");
 WriteString("Close,");
 WriteString("Volume,");
 WriteString("\n");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void WriteRow(int i){
 
 double  dSymTime, dSymOpen, dSymHigh, dSymLow, dSymClose, dSymVolume;
 double  dSymHigh_D1,dGap;
 int dDayofWk,iDigits;
 string bandDistance;
 double dClose, dOpen,Poin,dblPoints;
 dSymTime = (iTime(dSymbol,Period(),i));
 dDayofWk = (TimeDayOfWeek(dSymTime));
 WriteString(TimeToStr(dSymTime, TIME_DATE ));
 WriteString(",");
 if(Period() < PERIOD_H4){
 WriteString(TimeToStr(Time[i], TIME_MINUTES)+","+dDayofWk+",");
}
 iDigits=MarketInfo(Symbol(),MODE_DIGITS);
 dSymOpen = (iOpen(dSymbol,Period(),i));
 dSymHigh = (iHigh(dSymbol,Period(),i));
 dSymHigh_D1 = (iHigh(dSymbol,Period(),i));
 dSymLow = (iLow(dSymbol,Period(),i));
 dSymClose = (iClose(dSymbol,Period(),i));
 dSymVolume = (iVolume(dSymbol,Period(),i));
 WriteString(DoubleToStr(dSymOpen, iDigits)+",");
 WriteString(DoubleToStr(dSymHigh, iDigits)+",");
 WriteString(DoubleToStr(dSymLow, iDigits)+",");
 WriteString(DoubleToStr(dSymClose, iDigits)+",");
 WriteString("\n");
 }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string GetPeriodName(){

   switch(Period()){
     
       case PERIOD_D1:  return("Day");
       case PERIOD_H4:  return("4_Hour");
       case PERIOD_H1:  return("Hour");
       case PERIOD_M1:  return("Minute");
       case PERIOD_M15: return("15_Minute");
       case PERIOD_M30: return("30_Minute");
       case PERIOD_M5:  return("5_Minute");
       case PERIOD_MN1: return("Month");
       case PERIOD_W1:  return("Week");
     }
  }
 
bosslife:

i don't get it, all my attempts failed. i have this script that exports history of multiple pairs, i need it to only export time and close price, and they have to remain in the same row, 2nd and 7th.

is it this part? can't figure out what to delete or modify, always stops working :(

here the entire script

Try removing these highlighted parts:

//--------------------------------
//----
 int handle;
 
 //number of bars to export per Symbol
 int maxBars = 501;
 //test first on several pairs
string Currencies[] = {"AUDCAD", "AUDCHF", "AUDJPY", "AUDNZD", "AUDUSD", "CADCHF", "CADJPY", "CHFJPY", "EURAUD", "EURCAD", "EURCHF", "EURGBP", "EURJPY", "EURNZD", "EURUSD", "GBPAUD", "GBPCAD", "GBPCHF", "GBPJPY", "GBPNZD", "GBPUSD", "NZDCAD", "NZDCHF", "NZDJPY", "NZDUSD", "USDCAD", "USDCHF", "USDJPY"};
 
 
 // then add more in the same format
// string Currencies[] = {"AUDUSD","EURUSD","GBPJPY","GBPUSD","EURJPY","EURGBP","USDCHF","USDJPY","AUDJPY","CHFJPY","CADJPY","GBPCAD","EURAUD","USDCAD","EURCAD","NZDUSD","NZDJPY"};
string dSymbol;

//+------------------------------------------------------------------+
//|  start function                                    |
//+------------------------------------------------------------------+
int start(){
 int count = ArraySize(Currencies);
 for (int ii=0; ii<count; ii++){
 dSymbol = Currencies[ii];   
 handle = FileOpen("Hist_"+dSymbol+".csv", FILE_BIN|FILE_WRITE);

if(handle < 1){
 Print("Err ", GetLastError());
return(0);
}
 WriteTABLEHeader();

for(int i = 0; i < maxBars - 1; i++){
 WriteRow(i);
}
 FileClose(handle);
}
 Alert("Done."+TimeMonth(TimeLocal())+TimeDay(TimeLocal())+TimeYear(TimeLocal()) +"_"+TimeHour(TimeLocal())+TimeMinute(TimeLocal()));

  return(0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void WriteString(string txt){
   FileWriteString(handle, txt,StringLen(txt));
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void WriteTABLEHeader(){
 WriteString("Date,");
 WriteString("Time,");
 WriteString("DayOfWeek,");
 WriteString("Open,");
 WriteString("High,");
 WriteString("Low,");
 WriteString("Close,");
 WriteString("Volume,");
 WriteString("\n");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void WriteRow(int i){
 
 double  dSymTime, dSymOpen, dSymHigh, dSymLow, dSymClose, dSymVolume;
 double  dSymHigh_D1,dGap;
 int dDayofWk,iDigits;
 string bandDistance;
 double dClose, dOpen,Poin,dblPoints;
 dSymTime = (iTime(dSymbol,Period(),i));
 dDayofWk = (TimeDayOfWeek(dSymTime));
 WriteString(TimeToStr(dSymTime, TIME_DATE ));
 WriteString(",");
 if(Period() < PERIOD_H4){
 WriteString(TimeToStr(Time[i], TIME_MINUTES)+","+dDayofWk+",");
}
 iDigits=MarketInfo(Symbol(),MODE_DIGITS);
 dSymOpen = (iOpen(dSymbol,Period(),i));
 dSymHigh = (iHigh(dSymbol,Period(),i));
 dSymHigh_D1 = (iHigh(dSymbol,Period(),i));
 dSymLow = (iLow(dSymbol,Period(),i));
 dSymClose = (iClose(dSymbol,Period(),i));
 dSymVolume = (iVolume(dSymbol,Period(),i));
 WriteString(DoubleToStr(dSymOpen, iDigits)+",");
 WriteString(DoubleToStr(dSymHigh, iDigits)+",");
 WriteString(DoubleToStr(dSymLow, iDigits)+",");
 WriteString(DoubleToStr(dSymClose, iDigits)+",");
 WriteString("\n");
 }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string GetPeriodName(){

   switch(Period()){
     
       case PERIOD_D1:  return("Day");
       case PERIOD_H4:  return("4_Hour");
       case PERIOD_H1:  return("Hour");
       case PERIOD_M1:  return("Minute");
       case PERIOD_M15: return("15_Minute");
       case PERIOD_M30: return("30_Minute");
       case PERIOD_M5:  return("5_Minute");
       case PERIOD_MN1: return("Month");
       case PERIOD_W1:  return("Week");
     }
  }
 
bosslife: i need it to only export time and close price, and they have to remain in the same row, 2nd and 7th.
  1. You meant to say "they have to remain in the same column, 2nd and 7th."
  2. Impossible. If you delete columns, the remainder can not remain in the same column.
 
William Roeder:
  1. You meant to say "they have to remain in the same column, 2nd and 7th."
  2. Impossible. If you delete columns, the remainder can not remain in the same column.

there is for sure a way to put one comma before time, and 5 commas before close, which puts them in the 2nd and 7th column.

 
Seng Joo Thio:

Try removing these highlighted parts:

thanks a lot! how can i place one comma before time and five commas before close price to put them in the right column?

 
Seng Joo Thio: Try removing these highlighted parts:
 WriteString(DoubleToStr(dSymLow, iDigits)+",");

That will not work. Removing columns will not keep the remainder in the same columns.

Comment out the values the highlighted WriteStrings. e.g.

 WriteString(/*DoubleToStr(dSymLow, iDigits)+*/",");
 
William Roeder:

That will not work. Removing columns will not keep the remainder in the same columns.

Comment out the values the highlighted WriteStrings. e.g.

Yes, because I was "half-hearted" in giving him the "empty columns" solution initially, as I felt it was rather weird to retain empty columns... LOL

bosslife:

thanks a lot! how can i place one comma before time and five commas before close price to put them in the right column?

Right, if you really want to have empty columns, here's one way:

WriteString(",Time,,,,,"); // This is assuming you want empty header columns too, if not, don't remove the highlighted lines for the header.

and:

 WriteString(","+TimeToStr(Time[i], TIME_MINUTES)+","+dDayofWk+",,,,,");

Note that this part that writes the dDayofWk looks weird as it adds extra comma - you probably need to go through related lines again to determine what you really want.

 
Seng Joo Thio:

Yes, because I was "half-hearted" in giving him the "empty columns" solution initially, as I felt it was rather weird to retain empty columns... LOL

Right, if you really want to have empty columns, here's one way:

and:

Note that this part that writes the dDayofWk looks weird as it adds extra comma - you probably need to go through related lines again to determine what you really want.

cooooooooooool thank you so so much!!!!! 🙏🙏🙏🙏🙏🙏

i want to remain the columns so the connections in the excel file stay the same, importing them from the 28 csv files.

thanks a lot!!
 
Seng Joo Thio:

Yes, because I was "half-hearted" in giving him the "empty columns" solution initially, as I felt it was rather weird to retain empty columns... LOL

Right, if you really want to have empty columns, here's one way:

and:

Note that this part that writes the dDayofWk looks weird as it adds extra comma - you probably need to go through related lines again to determine what you really want.

does the column with day of week has to remain? when i remove it script stops working or time is gone :(

 
bosslife:

does the column with day of week has to remain? when i remove it script stops working or time is gone :(

depends on how you remove it... i'd just remove the highlighted part:

 WriteString(","+TimeToStr(Time[i], TIME_MINUTES)+","+dDayofWk+",,,,,,");
Reason: