I have made a script to export historical quotes from current chart.
But currently I have to open the chart manually. How can I open and close a currency chart programmatically with mql 4 ?
I have made a script to export historical quotes from current chart.
But currently I have to open the chart manually. How can I open and close a currency chart programmatically with mql 4 ?
Now you really are getting just plain lazy…
Well, I know I’ve written scripts to open and close trades and attached them to “hotkeys”…(ie ALT S to sell, ALT B to buy), but don’t know about opening and closing charts. Maybe there’s something in this article that will tell you another way.
Weird that there seems to be nothing in their api. But thanks for this suggestion; with hotkey and win32 API it may be possible to simulate what I do by hand.
Whats the difference between dragging a script onto a chart, then telling the script what chart you want opened, and dragging a chart onto the workspace??
How would the former save time? In fact surely it would take longer?
I don’t know how it would save time but you can do it through profiles by adding “.CHR” files to the folder that contains the files.
If you wanted to open a lot of charts the files could be generated by a scripting language such as Perl or PHP.
Thanks good suggestion. Do you know how I can select a window chart programmatically afterwards because if I want to export all currencies on all timeframes it’s still a lot of clicks by hand
Are you trying to export quotes to a text file?
Yes with my script here (I’m very beginner at Mql4):
forexgenuine.com/blog/exporting-metatrader-quotes/
You will need to add a loop for both Symbols and Timeframes. Only one chart will need to be open.
What’s the function to open one chart I can’t find it when googling ?
Or at least activate another chart in a profile.
Thanks.
I am unable to get the Timeframe loop to work as I don’t have any more time but theres a fairly easy solution.
You will open 1 chart any symbol in 1 TF, then run the script, then switch TF and run again
//+--------------------------------------------------------------------------+
//| Export_Quotes.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| metaquotes.net |
//+---------------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "metaquotes.net"
//add as many symbols as you want in this format
string Currencies[]={"EURGBP","EURUSD"};
int TimeFrames[] = {60,240,1440};
int TimeFrame,TF;
string TimeFrameStr;
int handle;
int maxBars = 300;
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start(){
int count = ArraySize(Currencies);
int counttf = ArraySize(TimeFrames);
string dSymbol;
string TimeFrameStr;
//Symbols
for (int ii=0; ii<count; ii++){
dSymbol = Currencies[ii];
//TimeFrames
// for (int xe=0; xe<counttf; xe++){
// TF = TimeFrames[xe];
// GetPeriod(TF);
TF=Period();
handle = FileOpen("Hist_"+dSymbol+"_"+TF+".txt", FILE_BIN|FILE_WRITE);
// Alert(">>>>>Hist_"+dSymbol+"_"+TF+".txt");
if(handle < 1){
Print("Err ", GetLastError());
return(0);
}
WriteTABLEHeader();
for(int i = 0; i < maxBars - 1; i++){
WriteRow(i,dSymbol,TF);
}
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("Open|");
WriteString("High|");
WriteString("Low|");
WriteString("Close|");
WriteString("
");
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void WriteRow(int i, string thisSym, int thisTF){
//Print("thisTF:"+thisTF+" TimeFrameStr:"+TimeFrameStr);
double dSymTime, dSymOpen, dSymHigh, dSymLow, dSymClose;
dSymTime = (iTime(thisSym,thisTF,i));
WriteString(TimeToStr(dSymTime, TIME_DATE ));
WriteString("|");
WriteString(TimeToStr(Time[i], TIME_MINUTES)+"|");
dSymOpen = (iOpen(thisSym,thisTF,i));
dSymHigh = (iHigh(thisSym,thisTF,i));
dSymLow = (iLow(thisSym,thisTF,i));
dSymClose = (iClose(thisSym,thisTF,i));
//WriteString(thisSym+"|"+thisTF+"|");
WriteString(dSymOpen+"|");
WriteString(dSymHigh+"|");
WriteString(dSymLow+"|");
WriteString(dSymClose+"|");
WriteString("
");
}
//+----------------------------------------+
// |
//+----------------------------------------+
int GetPeriod(int dPeriod){
switch( dPeriod){
case 1 : TimeFrameStr="PERIOD_M1"; TimeFrame=1; break;
case 5 : TimeFrameStr="PERIOD_M5"; TimeFrame=5; break;
case 15 : TimeFrameStr="PERIOD_M15"; TimeFrame=15; break;
case 30 : TimeFrameStr="PERIOD_M30"; TimeFrame=30; break;
case 60 : TimeFrameStr="PERIOD_H1"; TimeFrame=60;break;
case 240 : TimeFrameStr="PERIOD_H4"; TimeFrame=240; break;
case 1440 : TimeFrameStr="PERIOD_D1"; TimeFrame=1440; break;
case 10080 : TimeFrameStr="PERIOD_W1"; TimeFrame=10080; break;
case 43200 : TimeFrameStr="PERIOD_MN1"; TimeFrame=43200; break;
default : TimeFrameStr="Current Timeframe";TimeFrame=240;
}
return(0);
}
Thanks a lot will look at it, will take some time for me as I am absolute beginner with Mql4