How to set program to save chart's data? - page 2

 
oem7110:


I think it is the wrong place to ask question, to justify what right and wrong is user (me).

It's not about telling you if you are wrong or right . . . . it's about trying to help you . . . but you don't want help. OK.
 
Why don't you just send Ctrl + S to the keyboard buffer, sleep 0.25s, send enter, sleep 0.25s, send Y . . .
 
Of course you will need to let MT4 keep focus . . . otherwise the the commands will go to the wrong application. There are probably much better ways of doing what you need to do but you won't tell us what you need to do . . .
 

I agree with you RaptorUK - another interprtation would be that they wish to save each new 15M Bar info to a CSV. I have code that will saves all the bar info that interests me and then quits the chart - its an easy write but doubt it will help the User

//+------------------------------------------------------------------+
//|                                                      Barinfo.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#include <WinUser32.mqh> //add if using comitsuicide


//---- input parameters
extern string    ToFileName="Bar-info.csv";
extern bool MonthGap=false ;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   int handle ;
   double HiMinusLo=0 ;
   double count=0 ;
   Print("Test 1") ;
   handle=FileOpen(ToFileName,FILE_CSV|FILE_WRITE,",");
   int LineCount = 0 ; 
   if ( handle>0 )
     {
      FileWrite(handle, "Day","Date","Time","OPEN","CLOSE","HIGH","LOW","H-O","O-L","C-O",Bars);
      for(int i=0;i<Bars;i++)
       {
       //double iADX( string symbol, int timeframe, int period, int applied_price, int mode, int shift) 
       // MyADX=iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,i) ;
       // MyADXPlus=iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,i) ;
       // MyADXMinus=iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,i) ;
       // MyCCI=iCCI(NULL,0,14,PRICE_CLOSE,i) ;
        FileWrite(handle, MyDay(Time[i]),Date2String(Time[i]),Date2Time(Time[i]),Open[i],Close[i],High[i], Low[i],High[i]-Low[i]);
        HiMinusLo=+HiMinusLo+High[i]-Low[i] ;
        count=count+1 ;
       }//for
     }//if
     FileWrite(handle,"Average = ",DoubleToStr(HiMinusLo/count,5) );
     FileClose(handle);
     Alert("FileWrite Done") ; 
     commitSuicide() ;  

//----
   return(0);
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
/////////////////////////    
void commitSuicide() //Don't forget to use #include <WinUser32.mqh> for this function
{
  int h = WindowHandle(Symbol(), Period());
  if (h != 0) PostMessageA(h, WM_COMMAND, 33050, 0);
}
///////////
string MyDay(datetime MyTime )
{
int TheDay = TimeDayOfWeek( MyTime ) ;
  switch (TheDay)
  {
   case 0 : return("Sun") ; 
   case 1 : return("Mon") ;
   case 2 : return("Tue") ;
   case 3 : return("Wed") ;
   case 4 : return("Thr") ;
   case 5 : return("Fri") ;
   case 6 : return("Sat") ; 
  }
}
///////////////
string Date2String( datetime MyTime)
{
int TheDay = TimeDay( MyTime ) ;
int TheMonth = TimeMonth( MyTime ) ;
int TheYear = TimeYear( MyTime ) ;

return( TheDay+"/"+TheMonth+"/"+TheYear ) ;
} 
///////////////
string Date2Time( datetime MyTime)
{
int TheHour = TimeHour( MyTime ) ;
int TheMinute = TimeMinute( MyTime ) ;
int TheSeconds = TimeSeconds( MyTime ) ;

return( TheHour+":"+TheMinute+":"+TheSeconds ) ;
} 
 
Ickyrus:

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
int handle ;
double count=0 ;
handle=FileOpen(ToFileName,FILE_CSV|FILE_WRITE,",");
int LineCount = 0 ;
if ( handle>0 )
{
FileWrite(handle, "Date","Time","OPEN","HIGH","LOW","CLOSE",Bars);
for(int i=0;i<Bars;i++)
{
FileWrite(handle, Date2String(Time[i]),Date2Time(Time[i]),Open[i],High[i], Low[i],Close[i]);
count=count+1 // Do I need this? For loop uses "i" for counting
}//for
}//if
FileClose(handle);
Alert("FileWrite Done") ;

//----
return(0);
}

string Date2String( datetime MyTime)
{
int TheDay = TimeDay( MyTime ) ;
int TheMonth = TimeMonth( MyTime ) ;
int TheYear = TimeYear( MyTime ) ;

return( TheDay+"/"+TheMonth+"/"+TheYear ) ;
}
///////////////
string Date2Time( datetime MyTime)
{
int TheHour = TimeHour( MyTime ) ;
int TheMinute = TimeMinute( MyTime ) ;
int TheSeconds = TimeSeconds( MyTime ) ;

return( TheHour+":"+TheMinute+":"+TheSeconds ) ;
}

I show my requirement from above coding. I open 4 charts at the same time, and "AUDUSD,M30" is the chart I want to save data in csv format on every 15 minutes, and MT4 may not focus in the front application, because I may work with another application at the same time, but get no idea on set to run it every 15 minutes automatically.

Does anyone have any suggestions?

Thanks everyone very much for any suggestions

 
oem7110:

Does anyone have any suggestions?

I have already given a suggestion that will work . . . did you try it ?
 
RaptorUK:
I have already given a suggestion that will work . . . did you try it ?


I want to save data in csv format on every 15 minutes, and MT4 may not focus in the front application, because I may work with another application at the same time.

But your suggestions require that MT4 keep focus . . . otherwise the the commands will go to the wrong application, on the other hands, can you show your suggestions in coding please?

Thanks everyone very much for any suggestions

 
oem7110:

can you show your suggestions in coding please?


No. DIY.
 
RaptorUK:
No. DIY.

So what is your intention on replying this post? Looking for business ?
 
oem7110:

So what is your intention on replying this post? Looking for business ?
Nope, I'm not in the coding for cash business . . . . I spend my time here trying to help. You spend your time her asking the same question over and over . . . and refusing to provide information that would help those that try to help you.
Reason: