sAll_Instruments_download_bars(,)

Author: Copyright 2019, MetaQuotes Software Corp.
Price Data Components
Series array that contains open prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each barSeries array that contains tick volumes of each bar
Miscellaneous
Uses files from the file system
0 Views
0 Downloads
0 Favorites
sAll_Instruments_download_bars(,)
ÿþ#property copyright "Copyright 2019, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

{

   string FolderName = "Bars";          // 8<O ?0?:8 4;O A>E@0=5=8O 10@>2

   

   

   int Symbols_Total = SymbolsTotal(false);        // :>;-2> A8<2>;>2 (true   B>;L:> A8<2>;K 2 MarketWatch, false - 2>72@0I05BAO >1I55 :>;8G5AB2> 2A5E A8<2>;>2)

   Print("--> Symbols_Total = ", Symbols_Total);   // ?5G0BL 2 :>=A>;L

   

   

   // 703@C7:0 8AB>@88

   ResetLastError();

   for(int i=0; i<Symbols_Total; i++)              // ?5@51>@ 2A5E 8=AB@C<5=B>2

   {

      MqlRates rates[];

      string Symbol_Name = SymbolName(i, false);   // 8<O A8<2>;0

      CopyRates( Symbol_Name, PERIOD_MN1, 0, iBars(Symbol_Name, PERIOD_MN1), rates );

      CopyRates( Symbol_Name, PERIOD_W1, 0, iBars(Symbol_Name, PERIOD_W1), rates );

      CopyRates( Symbol_Name, PERIOD_D1, 0, iBars(Symbol_Name, PERIOD_D1), rates );

      if( _LastError == ERR_HISTORY_WILL_UPDATED )

      {

         i=i-1;

         //Print("--> 6840=85 8AB>@88 (ERR_HISTORY_WILL_UPDATED):   Symbol - ", Symbol_Name );

         ResetLastError();

      }

   }

   

   // A>740=85 D09;>2 4;O 2A5 8=AB@C<5=B>2

   for(int i=0; i<Symbols_Total; i++)              // ?5@51>@ 2A5E 8=AB@C<5=B>2

   {

      string Symbol_Name = SymbolName(i, false);   // 8<O A8<2>;0

      string FileName;                             // 8<O D09;0

      int filehandle;                              // E5=45; D09;0

      

      if( _LastError == ERR_HISTORY_WILL_UPDATED)  Print("--> 6840=85 8AB>@88 - ERR_HISTORY_WILL_UPDATED" );

      

   // 5AOF =========================================================================================

      ResetLastError();

      

      FileName = FolderName+"\\MN1\\"+Symbol_Name+".csv";      // 8<O D09;0, 2 :>B>@K9 1C45< ?8A0BL

      filehandle = FileOpen(FileName, FILE_WRITE|FILE_CSV);    // >B:@K205< D09;

      

      if(filehandle != INVALID_HANDLE) 

      { 

         FileWrite(filehandle,                     // =0720=8O AB>;1F>2

               "!",

               "Time",

               "Open",

               "High",

               "Low",

               "Close",

               "Volume");

               

         for(int j=0; j<iBars(Symbol_Name, PERIOD_MN1); j++)   // ?5@51>@ 2A5E 102@>2 5AOF1

         {

            FileWrite(filehandle,                  // ?8H5< ?0@0<5B@K 10@0 2 D09;

               j,

               iTime(Symbol_Name, PERIOD_MN1, j),

               ReplacePoint(iOpen(Symbol_Name, PERIOD_MN1, j)),

               ReplacePoint(iHigh(Symbol_Name, PERIOD_MN1, j)),

               ReplacePoint(iLow(Symbol_Name, PERIOD_MN1, j)),

               ReplacePoint(iClose(Symbol_Name, PERIOD_MN1, j)),

               ReplacePoint(iVolume(Symbol_Name, PERIOD_MN1, j)) );

         }



         FileClose(filehandle);                    // 70:@K205< D09;

         //Print("--> ", FileName, " - OK"); 

      } 

      else Print("--> ?5@0F8O FileOpen(", FileName, ") =5C40G=0, >H81:0 - ", _LastError); 

      

      

      

   // 545;O =========================================================================================

      ResetLastError();

      

      FileName = FolderName+"\\W1\\"+Symbol_Name+".csv";       // 8<O D09;0, 2 :>B>@K9 1C45< ?8A0BL

      filehandle = FileOpen(FileName, FILE_WRITE|FILE_CSV);    // >B:@K205< D09;

      

      if(filehandle != INVALID_HANDLE) 

      { 

         FileWrite(filehandle,                     // =0720=8O AB>;1F>2

               "!",

               "Time",

               "Open",

               "High",

               "Low",

               "Close",

               "Volume");

               

         for(int j=0; j<iBars(Symbol_Name, PERIOD_W1); j++)   // ?5@51>@ 2A5E 102@>2 545;O1

         {

            FileWrite(filehandle,                  // ?8H5< ?0@0<5B@K 10@0 2 D09;

               j,

               iTime(Symbol_Name, PERIOD_W1, j),

               ReplacePoint(iOpen(Symbol_Name, PERIOD_W1, j)),

               ReplacePoint(iHigh(Symbol_Name, PERIOD_W1, j)),

               ReplacePoint(iLow(Symbol_Name, PERIOD_W1, j)),

               ReplacePoint(iClose(Symbol_Name, PERIOD_W1, j)),

               ReplacePoint(iVolume(Symbol_Name, PERIOD_W1, j)) );

         }



         FileClose(filehandle);                    // 70:@K205< D09;

         //Print("--> ", FileName, " - OK"); 

      } 

      else Print("--> ?5@0F8O FileOpen(", FileName, ") =5C40G=0, >H81:0 - ", _LastError); 

      

      

      

   // 5=L =========================================================================================

      ResetLastError();

      

      FileName = FolderName+"\\D1\\"+Symbol_Name+".csv";       // 8<O D09;0, 2 :>B>@K9 1C45< ?8A0BL

      filehandle = FileOpen(FileName, FILE_WRITE|FILE_CSV);    // >B:@K205< D09;

      

      if(filehandle != INVALID_HANDLE) 

      { 

         FileWrite(filehandle,                     // =0720=8O AB>;1F>2

               "!",

               "Time",

               "Open",

               "High",

               "Low",

               "Close",

               "Volume");

               

         for(int j=0; j<iBars(Symbol_Name, PERIOD_D1); j++)   // ?5@51>@ 2A5E 102@>2 5=L1

         {

            FileWrite(filehandle,                  // ?8H5< ?0@0<5B@K 10@0 2 D09;

               j,

               iTime(Symbol_Name, PERIOD_D1, j),

               ReplacePoint(iOpen(Symbol_Name, PERIOD_D1, j)),

               ReplacePoint(iHigh(Symbol_Name, PERIOD_D1, j)),

               ReplacePoint(iLow(Symbol_Name, PERIOD_D1, j)),

               ReplacePoint(iClose(Symbol_Name, PERIOD_D1, j)),

               ReplacePoint(iVolume(Symbol_Name, PERIOD_D1, j)) );

         }

         

         FileClose(filehandle);                    // 70:@K205< D09;

         //Print("--> ", FileName, " - OK"); 

      } 

      else Print("--> ?5@0F8O FileOpen(", FileName, ") =5C40G=0, >H81:0 - ", _LastError);

       

   }

   ResetLastError();

   Print("--> !:@8?B - ");

}

//+------------------------------------------------------------------+







string ReplacePoint( double in )

{

   string s = DoubleToString(in);

   StringReplace( s, ".", ",");

   return s;

}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---