欢迎光临散文网 会员登陆 & 注册

量化软件下载:赫兹量化中技术指标和数字滤波器

2023-07-31 17:22 作者:大牛啊呢  | 我要投稿

"External Data"(外部数据)按钮允许使用来自 SAInpData 指标的数据。

原始数据包含代表滤波器内核的数组。我们将重制文件,以便其能够将任何图表指标传递至频谱分析程序。修改后的指标提供自动和手动模式。在自动模式中,使用找到的第一个图表指标。在手动模式中,用户可在列表中设置一个子窗口和指标索引。在这种情况下,应手动将脉冲指标添加至图表。此后,必要指标被应用以接收内核。

我们开始吧。我们应按照与脉冲相同的算法创建一个新的指标。添加输入参数:

input bool Automatic=true; // Autosearch input int  Window=0;       // Subwindow index input int  Indicator=0;    // Indicator index

如果 Automatic=true,使用自动模式,同时忽略其他输入参数。If Automatic=false,使用带子窗口和指标索引的手动模式。

接下来,我们应在全局层面添加用于存储句柄的整型变量。

int Impulse=0; // single impulse's handle int Handle=0;  // required indicator's handle int Kernel=0;  // filter kernel's handle

脉冲指标句柄存储在 Impulse 中。指标的句柄 - 我们希望在频谱分析程序中查看其内核 - 存储在 Handle 中。基于脉冲指标构建的目标指标的句柄,或换言之目标指标的内核,存储在 Kernel 中。


OnInit() 函数:

int OnInit()  { //--- indicator buffers mapping   SetIndexBuffer(0,DataBuffer,INDICATOR_DATA);   Impulse=iCustom(NULL,0,"SpecAnalyzer\\Impulse");//get the single impulse handle   if(Impulse==INVALID_HANDLE)     {      Alert("Impulse initialization failed");       return(INIT_FAILED);     } //---   return(0);  }

由于脉冲指标在程序操作期间没有发生变化,指标的句柄应在 OnInit() 函数中接收。还需要检查句柄接收错误。如果失败,"Impulse initialization failed"(脉冲初始化失败)消息显示,指标的操作通过 INIT_FAILED 键中断。

OnDeinit() 函数:

void OnDeinit(const int reason)  { //--- delete the indicators   IndicatorRelease(Impulse);   IndicatorRelease(Handle);   IndicatorRelease(Kernel);  }

用过的指标在 OnDeinit() 函数中删除。

OnCalculate() 函数:


static bool Flag=false;        //error flag if(Flag) return(rates_total); //exit in case of the flag

标记静态变量添加至函数的开头部分。如果在程序的执行期间发生错误,Flag 等于 true 且 OnCalculate() 函数的所有进一步迭代从开始处被中断。

下面是与手动模式相关的代码块:

  string Name;  //short name of the required indicator   if(!Automatic)//in case of the manual mode     {      if(ChartIndicatorsTotal(0,Window)>0)//if an indicator is present        {         Name=ChartIndicatorName(0,Window,Indicator);//search for its name         Handle=ChartIndicatorGet(0,Window,Name);//search for the handle        }      else//otherwise        {         Alert("No indicator");         Flag=true;         return(rates_total);        }      if(Handle==INVALID_HANDLE)//in case of a handle receiving error        {         Alert("No indicator");         Flag=true;         return(rates_total);        }      CopyBuffer(Handle,0,0,1024,DataBuffer);//display the kernel on the chart      return(rates_total);     }

如果 Automatic=false,手动模式启动。将检查指标是否存在。如果成功,我们开始搜索名称和句柄,检查句柄是否存在错误,并将数据复制到指标的缓冲区。如果失败,"No indicator"(无指标)消息显示,Flag 切换为 true,OnCalculate() 函数的执行被中断。

自动模式的代码块要有趣得多。它包含在图表上搜索指标和创建内核。

所以,我们来考虑搜索指标。其主要目标是接收句柄。

  if(ChartIndicatorsTotal(0,0)>0)//if the indicator is in the main window     {      Name=ChartIndicatorName(0,0,0);//search for its name      if(Name!="SpecAnalyzer")//if it is not SpecAnalyzer         Handle=ChartIndicatorGet(0,0,Name);//look for a handle      else        {         Alert("Indicator not found");         Flag=true;         return(rates_total);        }     }   else//otherwise   if(ChartIndicatorsTotal(0,1)>0)//if the indicator is in the first subwindow     {      Name=ChartIndicatorName(0,1,0);//search for its name      if(Name!="SAInpData")//if it is not SAInpData         Handle=ChartIndicatorGet(0,1,Name);//look for a handle      else//otherwise        {         Alert("Indicator not found");         Flag=true;         return(rates_total);        }     }   if(Handle==INVALID_HANDLE)//in case of a handle receiving error     {      Alert("No indicator");      Flag=true;      return(rates_total);     }

首先,我们在图表的主要子窗口中搜索指标,确保它不是 SpecAnalyzer。如果在主窗口中未找到指标,我们在下一个子窗口中继续搜索(考虑到此处有可能是 SAInpData)。所有其他操作与手动模式类似。

我们来创建一个指标。我们应接收获得指标的参数,并基于脉冲创建一个类似指标:

  ENUM_INDICATOR indicator_type;//obtained indicator's type   MqlParam parameters[];      //parameters   int parameters_cnt=0;      //number of parameters //--- receive the indicator's type, parameter values and amount   parameters_cnt=IndicatorParameters(Handle,indicator_type,parameters); //--- define that a single impulse is to be sent to the indicator's input   parameters[parameters_cnt-1].integer_value=Impulse; //--- receive the indicator's handle from the single impulse - filter's kernel   Kernel=IndicatorCreate(NULL,0,indicator_type,parameters_cnt,parameters);   if(Kernel==INVALID_HANDLE)//in case of a handle receiving error     {      Alert("Kernel initialization failed");      Flag=true;      return(rates_total);     }   CopyBuffer(Kernel,0,0,1024,DataBuffer);//display the kernel on the chart


量化软件下载:赫兹量化中技术指标和数字滤波器的评论 (共 条)

分享到微博请遵守国家法律