簡體   English   中英

MQL4存儲指標值

[英]MQL4 storing indicator value

有誰知道是否可以存儲例如超過一年的指標值系列,或在EA中計算的布爾函數的系列值?

我想存儲一個特定函數的值,該函數是根據我定義為EA的兩個不同EMA之間的差計算得出的。

我需要存儲在我的EA中幾年(例如從2015年到2017年)中計算出的double函數的值,並將其打印在某些輸出文件(.txt或其他格式)中

    int s15_60;
double B_M15_H1(int i) {

                          if (i>=0  && i<4  ) s15_60=0;
                     else if (i>=4  && i<8  ) s15_60=1;
                     else if (i>=8  && i<12 ) s15_60=2;
                     else if (i>=12 && i<16 ) s15_60=3;
                     else if (i>=16 && i<20 ) s15_60=4;

                     return NormalizeDouble(MathAbs(M15(i) - H1(s15_60)),Digits);

其中M15是在M15時間范圍內計算的簡單EMA,H1是在H1時間范圍內計算的同一EMA,並且double函數是這兩個指標之間的距離,以M15時間步長計算。

我的目標是將該值存儲在輸出文件中,以便對該功能進行一些統計研究。

編輯:

這段代碼適用於我的目的:

#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//--- show the window of input parameters when launching the script
#property script_show_inputs
//--- parameters for writing data to file
input string             InpFileName="BOX.csv";      // File name
input string             InpDirectoryName="Data";     // Folder name
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+



double H1  (int shift) {double val = iCustom(NULL,PERIOD_H1, "my_funct",100,2.0,30.0,2.0,2.0,0,1,0,shift); return(val);}
double H4  (int shift) {double val = iCustom(NULL,PERIOD_H4, "my_funct",100,2.0,30.0,2.0,2.0,0,1,0,shift); return(val);}


int s60_240;
double B_H1_H4(int i) {

                          if (i>=0  &&  i<4  ) s60_240=0;
                     else if (i>=4  &&  i<8  ) s60_240=1;
                     else if (i>=8  &&  i<12 ) s60_240=2;
                     else if (i>=12 &&  i<16 ) s60_240=3;
                     else if (i>=16 &&  i<20 ) s60_240=4;

                     return NormalizeDouble( 10000*MathAbs( H1(i) - H4(s60_240) ) , Digits);

                     } 


void OnStart()
  {

   double   box_buff[]; // array of indicator values
   datetime date_buff[]; // array of indicator dates
//--- copying the time from last 1000 bars
   int copied=CopyTime(NULL,PERIOD_H1,0,1000,date_buff);
   ArraySetAsSeries(date_buff,true);
//--- prepare box_buff array
   ArrayResize(box_buff,copied);


//--- copy the values of main line of the iCustom indicator
   for(int i=0;i<copied;i++)
     {
      box_buff[i]=B_H1_H4(i);
     }


//--- open the file for writing the indicator values (if the file is absent, it will be created automatically)
   ResetLastError();
   int 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));
      //--- first, write the number of signals
      FileWrite(file_handle,copied);
      //--- write the time and values of signals to the file
      for(int i=0;i<copied;i++)
         FileWrite(file_handle,date_buff[i],box_buff[i]);
      //--- close the file
      FileClose(file_handle);
      PrintFormat("Data is written, %s file is closed",InpFileName);
     }
   else
      PrintFormat("Failed to open %s file, Error code = %d",InpFileName,GetLastError());
  }

請提供您的MCVE代碼以查看所需內容。 您想如何存儲數據以及為什么需要它? 指標數據已經存儲在緩沖區中,因此只需使用iCustom()即可調用它。 如果要優化EA和指標,則需要花費大量時間來加載和計算緩沖區-是的,可以一次計算指標緩沖區,然后將其寫入文件或DB中並在新的優化開始之前獲取指標,在這種情況下,請使用CArrayObj or CArrayDouble作為用於存儲大型數組的動態數組

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM