Exchange_history_and_indicator_data_retrieval

Author: Notta
Indicators Used
FractalsCommodity channel indexBill Williams Accelerator/Decelerator oscillatorIndicator of the average true range
Miscellaneous
It writes information to file
1 Views
0 Downloads
0 Favorites
Exchange_history_and_indicator_data_retrieval
ÿþ//+---------------------------------------------------------------------------------------------+

//|                                           Exchange_history_and_indicator_data_retrieval.mq5 |

//|                                                    https://www.mql5.com/ja/code/mt5/scripts |

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

#property copyright "Notta"

#property link      "https://www.mql5.com/ja/code/mt5/scripts"

#property version   "1.01"

//--- ¹0¯0ê0×0È0n0wÕRBfk0eQ›RÑ0é0á0ü0¿0n0¦0£0ó0É0¦0’0hˆ:yY0‹0

#property script_show_inputs

//--- ïz+gK0‰0Ç0ü0¿0’0×SQ0ÖS‹0Ñ0é0á0ü0¿0

input string             InpSymbolName="EURUSD";             // ¨ŒÚ0¢0

input ENUM_TIMEFRAMES   InpSymbolPeriod=PERIOD_H1;           // Bf“•øŽ

input int               InpUPPER_LINE=0;                     // Fractals_UPPER_LINE

input int               InpLOWER_LINE=1;                     // Fractals_LOWER_LINE

input int               InpSignalPeriod=14;                  // CCI_cjŠ—{n0s^GWg“•

input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE;        // CCI_¡O<hn0.z^˜

input int                InpSignalPeriod_1=14;               // ATR_cjŠ—{n0s^GWg“•



input datetime           InpDateStart=D'2018.01.01 00:00'; // Ç0ü0¿0³0Ô0ü0‹•ËYåe

input datetime           InpDateStart_End=D'2022.01.01 00:00'; // Ç0ü0¿0³0Ô0ü0B}†Nåe



//--- Õ0¡0¤0ë0k0Ç0ü0¿0’0øfM0¼€0_00n0Ñ0é0á0ü0¿0

input string             InpFileName="Fr_CCI_AC_ATR_OHLC.csv";           // Õ0¡0¤0ë0
T

input string             InpDirectoryName="Data";         // Ç0£0ì0¯0È0ê0
T

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

//| ¹0¯0ê0×0È0×0í0°0é0à0’0‹•ËYY0‹0¢•pe                                          |

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

void OnStart()

 {

  datetime date_finish; // Ç0ü0¿0³0Ô0ü0B}†Nåe

  double   sign_buff_00[]; // Fractals_UPPER_LINE·0°0Ê0ë0M‘Rÿpe$PÇ0ü0¿0	ÿ

  double   sign_buff_01[]; // Fractals_LOWER_LINE·0°0Ê0ë0M‘Rÿpe$PÇ0ü0¿0	ÿ

  double   sign_buff_10[]; // CCI_·0°0Ê0ë0M‘Rÿpe$PÇ0ü0¿0	ÿ

  double   sign_buff_20[]; // AC_·0°0Ê0ë0M‘Rÿpe$PÇ0ü0¿0	ÿ

  double   sign_buff_30[]; // ATR_·0°0Ê0ë0M‘Rÿpe$PÇ0ü0¿0	ÿ



  double   sign_buff_1[]; // Open·0°0Ê0ë0M‘Rÿpe$PÇ0ü0¿0	ÿ

  double   sign_buff_2[]; // High·0°0Ê0ë0M‘Rÿpe$PÇ0ü0¿0	ÿ

  double   sign_buff_3[]; // Low·0°0Ê0ë0M‘Rÿpe$PÇ0ü0¿0	ÿ

  double   sign_buff_4[]; // Close·0°0Ê0ë0M‘Rÿpe$PÇ0ü0¿0	ÿ

  long     sign_buff_5[]; // TickVolume·0°0Ê0ë0M‘Rÿpe$PÇ0ü0¿0	ÿ

  int      sign_buff_6[]; // Spread·0°0Ê0ë0M‘Rÿpe$PÇ0ü0¿0	ÿ



  MqlDateTime time_buff[]; // ·0°0Ê0ë00R@wBf(Time)n0M‘R

  int      sign_size=0; // ·0°0Ê0ë0M‘Rµ0¤0º0

  double   macd_buff_00[]; // Fractals_UPPER_LINEcj$Pn0M‘R

  double   macd_buff_01[]; // Fractals_LOWER_LINEcj$Pn0M‘R

  double   macd_buff_10[]; // CCI_cj$Pn0M‘R

  double   macd_buff_20[]; // AC_cj$Pn0M‘R

  double   macd_buff_30[]; // ATR_cj$Pn0M‘R



  datetime date_buff[]; // cjåeØNn0M‘R

  double   date_buff_1[]; // cjOpenpe$Pn0M‘R

  double   date_buff_2[]; // cjHighpe$Pn0M‘R

  double   date_buff_3[]; // cjLowpe$Pn0M‘R

  double   date_buff_4[]; // cjClosepe$Pn0M‘R

  long     date_buff_5[]; // cjTickVolumepe$Pn0M‘R

  int      date_buff_6[]; // cjSpreadpe$Pn0M‘R



  int      macd_size_0=0; // cjM‘Rn0µ0¤0º0



  int      macd_handle_0; //FractalscjÏ0ó0É0ë0

  int      macd_handle_1; //CCicjÏ0ó0É0ë0

  int      macd_handle_2; //ACcjÏ0ó0É0ë0

  int      macd_handle_3; //ATRcjÏ0ó0É0ë0



  int      file_handle; //Õ0¡0¤0ë0Ï0ó0É0ë0



//--- B}†NBf;Ro0ûNaåeBf

  date_finish=InpDateStart_End;

//--- Fractals cjÏ0ó0É0ë0’0×SQ0ÖS‹0

  ResetLastError();

  macd_handle_0=iFractals(InpSymbolName,InpSymbolPeriod);

  if(macd_handle_0==INVALID_HANDLE)

    {

    //--- cjÏ0ó0É0ë0n0×SQ0ÖSŠ0k01YWe

    PrintFormat("Error when receiving indicator handle. Error code = %d",GetLastError());

    return;

    }

//--- CCI cjÏ0ó0É0ë0’0×SQ0ÖS‹0

  ResetLastError();

  macd_handle_1=iCCI(InpSymbolName,InpSymbolPeriod,InpSignalPeriod,InpAppliedPrice);

  if(macd_handle_1==INVALID_HANDLE)

    {

    //--- cjÏ0ó0É0ë0n0×SQ0ÖSŠ0k01YWe

    PrintFormat("Error when receiving indicator handle. Error code = %d",GetLastError());

    return;

    }

//--- AC cjÏ0ó0É0ë0’0×SQ0ÖS‹0

  ResetLastError();

  macd_handle_2=iAC(InpSymbolName,InpSymbolPeriod);

  if(macd_handle_2==INVALID_HANDLE)

    {

    //--- cjÏ0ó0É0ë0n0×SQ0ÖSŠ0k01YWe

    PrintFormat("Error when receiving indicator handle. Error code = %d",GetLastError());

    return;

    }

//--- ATR cjÏ0ó0É0ë0’0×SQ0ÖS‹0

  ResetLastError();

  macd_handle_3=iATR(InpSymbolName,InpSymbolPeriod,InpSignalPeriod_1);

  if(macd_handle_3==INVALID_HANDLE)

    {

    //--- cjÏ0ó0É0ë0n0×SQ0ÖSŠ0k01YWe

    PrintFormat("Error when receiving indicator handle. Error code = %d",GetLastError());

    return;

    }



//--- hQf0n0cj$PL0Š—{U0Œ0‹0~0g0ë0ü0×0k0Yu~0‹0

  while(BarsCalculated(macd_handle_0)==-1)

    Sleep(10); // cjL0hQf0n0$P’0Š—{úQeg‹0ˆ0F0k0NBf\Pbk

  while(BarsCalculated(macd_handle_1)==-1)

    Sleep(10); // cjL0hQf0n0$P’0Š—{úQeg‹0ˆ0F0k0NBf\Pbk

  while(BarsCalculated(macd_handle_2)==-1)

    Sleep(10); // cjL0hQf0n0$P’0Š—{úQeg‹0ˆ0F0k0NBf\Pbk

  while(BarsCalculated(macd_handle_3)==-1)

    Sleep(10); // cjL0hQf0n0$P’0Š—{úQeg‹0ˆ0F0k0NBf\Pbk



//--- Fractals cj Nš[g“•n0cj$P’0‰ýˆY0‹0

  ResetLastError();

  if(CopyBuffer(macd_handle_0,InpUPPER_LINE,InpDateStart,date_finish,macd_buff_00)==-1)

    {

    PrintFormat("Failed to copy indicator values. Error code = %d",GetLastError());

    return;

    }

  ResetLastError();

  if(CopyBuffer(macd_handle_0,InpLOWER_LINE,InpDateStart,date_finish,macd_buff_01)==-1)

    {

    PrintFormat("Failed to copy indicator values. Error code = %d",GetLastError());

    return;

    }



//--- CCI cj Nš[g“•n0cj$P’0‰ýˆY0‹0

  ResetLastError();

  if(CopyBuffer(macd_handle_1,0,InpDateStart,date_finish,macd_buff_10)==-1)

    {

    PrintFormat("Failed to copy indicator values. Error code = %d",GetLastError());

    return;

    }



//--- AC cj Nš[g“•n0cj$P’0‰ýˆY0‹0

  ResetLastError();

  if(CopyBuffer(macd_handle_2,0,InpDateStart,date_finish,macd_buff_20)==-1)

    {

    PrintFormat("Failed to copy indicator values. Error code = %d",GetLastError());

    return;

    }



//--- ATR cj Nš[g“•n0cj$P’0‰ýˆY0‹0

  ResetLastError();

  if(CopyBuffer(macd_handle_3,0,InpDateStart,date_finish,macd_buff_30)==-1)

    {

    PrintFormat("Failed to copy indicator values. Error code = %d",GetLastError());

    return;

    }



//--- Opencj’0‰ýˆY0‹0

  ResetLastError();

  if(CopyOpen(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,date_buff_1)==-1)

    {

    PrintFormat("Failed to copy time values. Error code = %d",GetLastError());

    return;

    }



//--- Highcj’0‰ýˆY0‹0

  ResetLastError();

  if(CopyHigh(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,date_buff_2)==-1)

    {

    PrintFormat("Failed to copy time values. Error code = %d",GetLastError());

    return;

    }



//--- Lowcj’0‰ýˆY0‹0

  ResetLastError();

  if(CopyLow(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,date_buff_3)==-1)

    {

    PrintFormat("Failed to copy time values. Error code = %d",GetLastError());

    return;

    }



//--- Closecj’0‰ýˆY0‹0

  ResetLastError();

  if(CopyClose(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,date_buff_4)==-1)

    {

    PrintFormat("Failed to copy time values. Error code = %d",GetLastError());

    return;

    }



//--- TickVolumecj’0‰ýˆY0‹0

  ResetLastError();

  if(CopyTickVolume(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,date_buff_5)==-1)

    {

    PrintFormat("Failed to copy time values. Error code = %d",GetLastError());

    return;

    }



//--- Spreadcj’0‰ýˆY0‹0

  ResetLastError();

  if(CopySpread(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,date_buff_6)==-1)

    {

    PrintFormat("Failed to copy time values. Error code = %d",GetLastError());

    return;

    }



//--- cj$Pk0iRj0Bf“•’0‰ýˆY0‹0

  ResetLastError();

  if(CopyTime(InpSymbolName,InpSymbolPeriod,InpDateStart,date_finish,date_buff)==-1)

    {

    PrintFormat("Failed to copy time values. Error code = %d",GetLastError());

    return;

    }

//--- Fractals_CCI_AC_ATR_Alligatorcjg0O(uU0Œ0_0á0â0ê0’0ã‰>eY0‹0

  IndicatorRelease(macd_handle_0);

  IndicatorRelease(macd_handle_1);

  IndicatorRelease(macd_handle_2);

  IndicatorRelease(macd_handle_3);



//--- Fractalscjn0Ð0Ã0Õ0¡0µ0¤0º0’0×SQ0ÖS‹0

  macd_size_0=ArraySize(macd_buff_00);



//--- Ç0ü0¿0’0RgW0hQcj·0°0Ê0ë0’0M‘Rk0ÝOX[Y0‹0

  ArrayResize(sign_buff_00,macd_size_0-1);//Fractals_UPPER_LINE

  ArrayResize(sign_buff_01,macd_size_0-1);//Fractals_LOWER_LINE

  ArrayResize(sign_buff_10,macd_size_0-1);//CCI

  ArrayResize(sign_buff_20,macd_size_0-1);//AC

  ArrayResize(sign_buff_30,macd_size_0-1);//ATR



  ArrayResize(sign_buff_1,macd_size_0-1);//Open

  ArrayResize(sign_buff_2,macd_size_0-1);//High

  ArrayResize(sign_buff_3,macd_size_0-1);//Low

  ArrayResize(sign_buff_4,macd_size_0-1);//Close

  ArrayResize(sign_buff_5,macd_size_0-1);//TickVolume

  ArrayResize(sign_buff_6,macd_size_0-1);//Spread

  ArrayResize(time_buff,macd_size_0-1);//Time

  for(int i=1;i<macd_size_0;i++)

    {

     sign_buff_00[sign_size]=(macd_buff_00[i]==EMPTY_VALUE)?0:macd_buff_00[i];

     sign_buff_01[sign_size]=(macd_buff_01[i]==EMPTY_VALUE)?0:macd_buff_01[i];

     sign_buff_10[sign_size]=macd_buff_10[i];

     sign_buff_20[sign_size]=macd_buff_20[i];

     sign_buff_30[sign_size]=macd_buff_30[i];



     sign_buff_1[sign_size]=date_buff_1[i];

     sign_buff_2[sign_size]=date_buff_2[i];

     sign_buff_3[sign_size]=date_buff_3[i];

     sign_buff_4[sign_size]=date_buff_4[i];

     sign_buff_5[sign_size]=date_buff_5[i];

     sign_buff_6[sign_size]=date_buff_6[i];

     TimeToStruct(date_buff[i],time_buff[sign_size]);

     sign_size++;

    }

//--- hQcj$P’0øfM0¼€0_00k0Õ0¡0¤0ë0’0‹•O0ÿÕ0¡0¤0ë0L0X[(WW0j0D04XTo0êÕR„vk0\ObU0Œ0‹0	ÿ

  ResetLastError();

  file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV);

  if(file_handle!=INVALID_HANDLE)

    {

    PrintFormat("%s file is available for writing",InpFileName);

    PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));

    //--- R0k0·0°0Ê0ë0pe’0øfO0

    FileWrite(file_handle,"number of signals",sign_size);

    FileWrite(file_handle,"year","mon","day","hour","min","sec","Fractals_UPPER","Fractals_LOWER","CCI","AC","ATR","Open","High","Low","Close","TickVolume","Spread");

    //--- ·0°0Ê0ë0n0Bf“•h0$P’0Õ0¡0¤0ë0k0øfO0

    for(int i=0;i<sign_size;i++)

        FileWrite(file_handle,time_buff[i].year,time_buff[i].mon,time_buff[i].day,time_buff[i].hour,time_buff[i].min,time_buff[i].sec,

                  sign_buff_00[i],sign_buff_01[i],sign_buff_10[i],sign_buff_20[i],sign_buff_30[i],sign_buff_1[i],sign_buff_2[i],sign_buff_3[i],sign_buff_4[i],sign_buff_5[i],sign_buff_6[i]);

    //--- Õ0¡0¤0ë0’0‰•X0‹0

    FileClose(file_handle);

    PrintFormat("Data is written, %s file is closed",InpFileName);

    }

  else

    PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError());

 }

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

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 ---