量化软件:赫兹量化系统多周期指标缓冲区

今天,我将继续工作,编排创建指标缓冲区和访问其数据的方法。 我打算根据缓冲区对象中设置的 period 属性(数据时间帧)实现当前品种/周期图表对应的缓冲区数值的显示。 如果缓冲区设置的时间帧与当前图表不对应,则所有缓冲区数据均会正确地显示在图表上。 例如,如果当前图表的数据周期为 M15,而缓冲区对象图表设置为 H1,则缓冲区数据会显示在当前 M15 图表的每根柱线上,其时间落在 H1 图表柱线内的时间。 在本示例中,当前图表的四根柱线填充的是相同数值,所请求的数值来自图表周期为 H1 的柱线。赫兹量化国联期货极速版

这些改进令我们能够舒服地创建多周期指标,因为我们只需要为缓冲区对象设置时间帧即可。 其余的由函数库负责。 此外,我打算逐步完善指标缓冲区的创建。 它会被精简为单一的代码字符串,并在其中创建带有请求属性的所需指标缓冲区对象。 任何特定图形类型的指标缓冲区都将按索引进行访问。

“缓冲区索引”的概念如下:如果第一行先创建箭头缓冲区,然后再次创建箭头缓冲区,则缓冲区对象索引按创建对象的顺序排列。 每种绘图样式都有其自己的索引序列。 在所提供的示例里,索引如下:创建的第一个箭头缓冲区的索引为 0,第二个箭头缓冲区的索引为 1,而紧接在第一个箭头缓冲区之后创建的线条缓冲区的索引为 0,因为它是第一个具有“线条”绘制样式的缓冲区,尽管它依序是第二个创建的。

改进在多周期模式下操控指标缓冲区的类

从版本 2430 开始,赫兹量化国联期货极速版 可在市场观察窗口中列出的品种名称得以极大提升。 现在是 5000,取代了构建 2430 之前的 1000。 为了操控品种列表,我们在 Defines.mqh 文件中引入新的宏替换:

 
 

//+------------------------------------------------------------------+ //| Macro substitutions | //+------------------------------------------------------------------+ //--- Describe the function with the error line number .... //--- Symbol parameters #define CLR_DEFAULT (0xFF000000) // Default symbol background color in the navigator #ifdef __MQL5__ #define SYMBOLS_COMMON_TOTAL (TerminalInfoInteger(TERMINAL_BUILD)<2430 ? 1000 : 5000) // Total number of MQL5 working symbols #else #define SYMBOLS_COMMON_TOTAL (1000) // Total number of MQL4 working symbols #endif //--- Pending request type IDs #define PENDING_REQUEST_ID_TYPE_ERR (1) // Type of a pending request created based on the server return code #define PENDING_REQUEST_ID_TYPE_REQ (2) // Type of a pending request created by request //--- Timeseries parameters #define SERIES_DEFAULT_BARS_COUNT (1000) // Required default amount of timeseries data #define PAUSE_FOR_SYNC_ATTEMPTS (16) // Amount of pause milliseconds between synchronization attempts #define ATTEMPTS_FOR_SYNC (5) // Number of attempts to receive synchronization with the server //+------------------------------------------------------------------+ //| Enumerations | //+------------------------------------------------------------------+

在 \MQL5\Include\DoEasy\Collections\SymbolsCollection.mqh 里,为已用品种列表进行设置的方法中,将预留的品种数组大小从 1000 替换为新的宏替换数值:

 
 

//+------------------------------------------------------------------+ //| Set the list of used symbols | //+------------------------------------------------------------------+ bool CSymbolsCollection::SetUsedSymbols(const string &symbol_used_array[]) { ::ArrayResize(this.m_array_symbols,0,SYMBOLS_COMMON_TOTAL); ::ArrayCopy(this.m_array_symbols,symbol_used_array);

在创建品种列表的方法里,于索引循环当中,将参考数值 1000 替换为新的宏替换:

 
 

//+------------------------------------------------------------------+ //| Creating the symbol list (Market Watch or the complete list) | //+------------------------------------------------------------------+ bool CSymbolsCollection::CreateSymbolsList(const bool flag) { bool res=true; int total=::SymbolsTotal(flag); for(int i=0;i<total && i<SYMBOLS_COMMON_TOTAL;i++) {

以相同的方式,将所有用到的品种和时间帧写入 \MQL5\Include\DoEasy\Engine.mqh 里的方法当中,将 1000 替换为宏替换:

 
 

//+------------------------------------------------------------------+ //| Write all used symbols and timeframes | //| to the ArrayUsedSymbols and ArrayUsedTimeframes arrays | //+------------------------------------------------------------------+ void CEngine::WriteSymbolsPeriodsToArrays(void) { //--- Get the list of all created timeseries (created by the number of used symbols) CArrayObj *list_timeseries=this.GetListTimeSeries(); if(list_timeseries==NULL) return; //--- Get the total number of created timeseries int total_timeseries=list_timeseries.Total(); if(total_timeseries==0) return; //--- Set the size of the array of used symbols equal to the number of created timeseries, while //--- the size of the array of used timeframes is set equal to the maximum possible number of timeframes in the terminal if(::ArrayResize(ArrayUsedSymbols,total_timeseries,SYMBOLS_COMMON_TOTAL)!=total_timeseries || ::ArrayResize(ArrayUsedTimeframes,21,21)!=21) return; //--- Set both arrays to zero ::ZeroMemory(ArrayUsedSymbols); ::ZeroMemory(ArrayUsedTimeframes); //--- Reset the number of added symbols and timeframes to zero and, //--- in a loop by the total number of timeseries, int num_symbols=0,num_periods=0; for(int i=0;i<total_timeseries;i++) { //--- get the next object of all timeseries of a single symbol CTimeSeriesDE *timeseries=list_timeseries.At(i); if(timeseries==NULL || this.IsExistSymbol(timeseries.Symbol())) continue; //--- increase the number of used symbols and (num_symbols variable), and //--- write the timeseries symbol name to the array of used symbols by the num_symbols-1 index num_symbols++; ArrayUsedSymbols[num_symbols-1]=timeseries.Symbol(); //--- Get the list of all its timeseries from the object of all symbol timeseries CArrayObj *list_series=timeseries.GetListSeries(); if(list_series==NULL) continue; //--- In the loop by the total number of symbol timeseries, int total_series=list_series.Total(); for(int j=0;j<total_series;j++) { //--- get the next timeseries object CSeriesDE *series=list_series.At(j); if(series==NULL || this.IsExistTimeframe(series.Timeframe())) continue; //--- increase the number of used timeframes and (num_periods variable), and //--- write the timeseries timeframe value to the array of used timeframes by num_periods-1 index num_periods++; ArrayUsedTimeframes[num_periods-1]=series.Timeframe(); } } //--- Upon the loop completion, change the size of both arrays to match the exact number of added symbols and timeframes ::ArrayResize(ArrayUsedSymbols,num_symbols,SYMBOLS_COMMON_TOTAL); ::ArrayResize(ArrayUsedTimeframes,num_periods,21); } //+------------------------------------------------------------------+

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值