CustomRatesUpdate

누락된 막대를 사용자 지정 심볼 내역에 추가하고 기존 데이터를 MqlRates 유형 배열의 데이터로 바꿉니다.

int  CustomRatesUpdate(
   const string     symbol,             // 사용자 지정 심볼 이름
   const MqlRates&  rates[],            // 사용자 지정 심볼에 적용할 데이터의 배열
   uint             count=WHOLE_ARRAY   // 사용할 rates[] 배열 요소의 수
   );

매개변수

심볼

[in]  사용자 지정 심볼 이름.

rates[]

[in]  M1에 대한 MqlRates 유형 내역 데이터의 배열입니다.

count=WHOLE_ARRAY

[in]  업데이트에 사용할 rates[] 배열 요소의 수. WHOLE_ARRAY는 모든 rates[] 배열 요소를 사용해야 함을 의미합니다.

값 반환

오류가 발생한 경우 업데이트된 수 또는 -1.

주의

현재 사용자 지정 심볼 내역에 rates[] 배열에 막대가 없으면 추가됩니다. 이러한 막대가 이미 있는 경우 대체됩니다. 현재 가격 내역의 다른 모든 막대는 변경되지 않습니다. rates[] 배열 데이터는 OHLC 가격에 대해 정확해야 하며 막대 오프닝 시간은 M1 시간 프레임에 해당되어야 합니다.

 

Example:

//+------------------------------------------------------------------+
//|                                            CustomRatesUpdate.mq5 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#define   CUSTOM_SYMBOL_NAME     Symbol()+".C"     // custom symbol name
#define   CUSTOM_SYMBOL_PATH     "Forex"           // name of the group, in which a symbol is to be created
#define   CUSTOM_SYMBOL_ORIGIN   Symbol()          // name of a symbol a custom one is to be based on
 
#define   DATARATES_COUNT        4                 // number of bars sent to the journal
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- get the error code when creating a custom symbol
   int create=CreateCustomSymbol(CUSTOM_SYMBOL_NAMECUSTOM_SYMBOL_PATHCUSTOM_SYMBOL_ORIGIN);
   
//--- if the error code is not 0 (successful symbol creation) and not 5304 (symbol has already been created) - leave
   if(create!=0 && create!=5304)
      return;
 
//--- get and print in the journal the number of standard symbol bars
   int bars_origin=Bars(CUSTOM_SYMBOL_ORIGINPERIOD_M1);
   PrintFormat("The symbol '%s' from which the custom '%s' was created has %d bars of minute history."CUSTOM_SYMBOL_ORIGINCUSTOM_SYMBOL_NAMEbars_origin);
      
//--- get and print in the journal the number of custom symbol bars
   int bars_custom=Bars(CUSTOM_SYMBOL_NAMEPERIOD_M1);
   PrintFormat("Custom symbol '%s' created from symbol '%s' has %d bars of minute history"CUSTOM_SYMBOL_NAMECUSTOM_SYMBOL_ORIGINbars_custom);
      
//--- get the data of all bars of the standard symbol minute timeframe into the MqlRates array
   MqlRates rates[]={};
   ResetLastError();
   if(CopyRates(CUSTOM_SYMBOL_ORIGINPERIOD_M10bars_originrates)!=bars_origin)
     {
      PrintFormat("CopyRates(%s, PERIOD_M1, 0, %d) failed. Error %d"CUSTOM_SYMBOL_ORIGINbars_originGetLastError());
      return;
     }
 
//--- set the copied data to the minute history of the custom symbol
   ResetLastError();
   int updated=CustomRatesUpdate(CUSTOM_SYMBOL_NAMErates);
   if(updated<0)
     {
      PrintFormat("CustomRatesUpdate(%s) failed. Error %d"CUSTOM_SYMBOL_NAMEGetLastError());
      return;
     }
 
//--- get and print in the journal the number of custom symbol bars after adding history
   bars_custom=Bars(CUSTOM_SYMBOL_NAMEPERIOD_M1);
   PrintFormat("\nAfter CustomRatesUpdate(), the custom symbol '%s' has %d bars of minute history"CUSTOM_SYMBOL_NAMEbars_custom);
 
//--- get the data of all bars of the custom symbol minute timeframe into the MqlRates array
   ResetLastError();
   if(CopyRates(CUSTOM_SYMBOL_NAMEPERIOD_M10bars_customrates)!=bars_custom)
     {
      PrintFormat("CopyRates(%s, PERIOD_M1, 0, %d) failed. Error %d"CUSTOM_SYMBOL_NAMEbars_customGetLastError());
      return;
     }
 
//--- print the last four bars of the custom symbol minute history in the journal
   int digits=(int)SymbolInfoInteger(CUSTOM_SYMBOL_NAMESYMBOL_DIGITS);
   PrintFormat("Last %d bars of the custom symbol's minute history:"DATARATES_COUNT);
   ArrayPrint(ratesdigitsNULLbars_custom-DATARATES_COUNTDATARATES_COUNT);
   
//--- replace the data in the MqlRates array with the one calculated using the equation 1.0 / SymbolName
   for(int i=0i<bars_customi++)
     {
      rates[i].open  =(rates[i].open !=0  ? 1.0 / rates[i].open  : rates[i].open);
      rates[i].high  =(rates[i].high !=0  ? 1.0 / rates[i].high  : rates[i].high);
      rates[i].low   =(rates[i].low  !=0  ? 1.0 / rates[i].low   : rates[i].low);
      rates[i].close =(rates[i].close!=0  ? 1.0 / rates[i].close : rates[i].close);
     }
 
//--- set the modified data to the minute history of the custom symbol
   ResetLastError();
   updated=CustomRatesUpdate(CUSTOM_SYMBOL_NAMErates);
   if(updated<0)
     {
      PrintFormat("CustomRatesUpdate(%s) failed. Error %d"CUSTOM_SYMBOL_NAMEGetLastError());
      return;
     }
 
//--- get the data of all bars of the custom symbol minute timeframe into the MqlRates array again
   ResetLastError();
   if(CopyRates(CUSTOM_SYMBOL_NAMEPERIOD_M10bars_customrates)!=bars_custom)
     {
      PrintFormat("CopyRates(%s, PERIOD_M1, 0, %d) failed. Error %d"CUSTOM_SYMBOL_NAMEbars_customGetLastError());
      return;
     }
 
//--- print the last four bars of the updated custom symbol minute history in the journal
   Print("\nLast %d bars after changing the custom symbol calculation formula:"DATARATES_COUNT);
   ArrayPrint(ratesdigitsNULLbars_custom-DATARATES_COUNTDATARATES_COUNT);
   
//--- display a hint about the script termination keys on the chart comment
   Comment(StringFormat("Press 'Esc' to exit or 'Del' to delete the '%s' symbol and exit"CUSTOM_SYMBOL_NAME));
//--- wait for pressing the Esc or Del keys to exit in an endless loop
   while(!IsStopped() && TerminalInfoInteger(TERMINAL_KEYSTATE_ESCAPE)==0)
     {
      Sleep(16);
      //--- when pressing Del, delete the created custom symbol and its data
      if(TerminalInfoInteger(TERMINAL_KEYSTATE_DELETE)<0)
        {
         //--- delete bar data
         int deleted=CustomRatesDelete(CUSTOM_SYMBOL_NAME0LONG_MAX);
         if(deleted>0)
            PrintFormat("%d history bars of the custom symbol '%s' were successfully deleted"deletedCUSTOM_SYMBOL_NAME);
         
         //--- delete tick data
         deleted=CustomTicksDelete(CUSTOM_SYMBOL_NAME0LONG_MAX);
         if(deleted>0)
            PrintFormat("%d history ticks of the custom symbol '%s' were successfully deleted"deletedCUSTOM_SYMBOL_NAME);
         
         //--- delete symbol
         if(DeleteCustomSymbol(CUSTOM_SYMBOL_NAME))
            PrintFormat("Custom symbol '%s' deleted successfully"CUSTOM_SYMBOL_NAME);
         break;
        }
     }
//--- clear the chart before exiting
   Comment("");
   /*
   result:
   The symbol 'EURUSDfrom which the custom 'EURUSD.Cwas created has 250488 bars of minute history.
   Custom symbol 'EURUSD.Ccreated from symbol 'EURUSDhas 0 bars of minute history
   
   After CustomRatesUpdate(), the custom symbol 'EURUSD.Chas 250488 bars of minute history
   Last 4 bars of the custom symbol's minute history:
                    [time]  [open]  [high]   [low] [close] [tick_volume] [spread] [real_volume]
   [02024.06.18 11:14:00 1.07235 1.07239 1.07232 1.07239            24        0             0
   [12024.06.18 11:15:00 1.07238 1.07239 1.07232 1.07235            44        0             0
   [22024.06.18 11:16:00 1.07234 1.07238 1.07227 1.07234            37        0             0
   [32024.06.18 11:17:00 1.07234 1.07234 1.07217 1.07225            41        0             0
   
   Last 4 bars after changing the custom symbol calculation formula:
                    [time]  [open]  [high]   [low] [close] [tick_volume] [spread] [real_volume]
   [02024.06.18 11:14:00 0.93253 0.93250 0.93256 0.93250            24        0             0
   [12024.06.18 11:15:00 0.93251 0.93250 0.93256 0.93253            44        0             0
   [22024.06.18 11:16:00 0.93254 0.93251 0.93260 0.93254            37        0             0
   [32024.06.18 11:17:00 0.93254 0.93254 0.93269 0.93262            41        0             0
   */
  }
//+------------------------------------------------------------------+
//| Create a custom symbol, return an error code                     |
//+------------------------------------------------------------------+
int CreateCustomSymbol(const string symbol_nameconst string symbol_pathconst string symbol_origin=NULL)
  {
//--- define the name of a symbol a custom one is to be based on
   string origin=(symbol_origin==NULL ? Symbol() : symbol_origin);
   
//--- if failed to create a custom symbol and this is not error 5304, report this in the journal
   ResetLastError();
   int error=0;
   if(!CustomSymbolCreate(symbol_namesymbol_pathorigin))
     {
      error=GetLastError();
      if(error!=5304)
         PrintFormat("CustomSymbolCreate(%s, %s, %s) failed. Error %d"symbol_namesymbol_pathoriginerror);
     }
//--- successful
   return(error);
  }
//+------------------------------------------------------------------+
//| Remove a custom symbol                                           |
//+------------------------------------------------------------------+
bool DeleteCustomSymbol(const string symbol_name)
  {
//--- hide the symbol from the Market Watch window
   ResetLastError();
   if(!SymbolSelect(symbol_namefalse))
     {
      PrintFormat("SymbolSelect(%s, false) failed. Error %d"GetLastError());
      return(false);
     }
      
//--- if failed to delete a custom symbol, report this in the journal and return 'false'
   ResetLastError();
   if(!CustomSymbolDelete(symbol_name))
     {
      PrintFormat("CustomSymbolDelete(%s) failed. Error %d"symbol_nameGetLastError());
      return(false);
     }
//--- successful
   return(true);
  }

 

추가 참조

CustomRatesReplace, CustomRatesDelete, CopyRates