元ネタは、こちら。
コード
//+------------------------------------------------------------------+
//| DWTHarr.mq5 |
//| Copyright 2010, bighope |
//| http://expertadviser-bighope.blogspot.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, bighope"
#property link "http://expertadviser-bighope.blogspot.com/"
#property version "1.00"
//#property indicator_separate_window//サブチャート
#property indicator_chart_window//メインチャート
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_color1 Red
input int N = 10;//対象データ数(2のN乗)
input int HBs = 4;//高周波カット位置
input int LBs = 10;//低周波カット位置
input int Shift = 0;//データのシフト数
int DWTPeriod;
//---------buffers
double IDWT[];
double g[];
double gs[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,IDWT,INDICATOR_DATA);
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
DWTPeriod =(int)MathPow(2,N);
ArrayResize(g,DWTPeriod);
ArrayResize(gs,DWTPeriod);
//---
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime& Time[],
const double& Open[],
const double& High[],
const double& Low[],
const double& Close[],
const long& Tick_volume[],
const long& Volume[],
const int& Spread[])
{
//---
int k;
int DWTf,z;
double sum,difference;
for(k=0;k<DWTPeriod;k++)g[k] = Open[rates_total-k-Shift-1];
DWTf = DWTPeriod/2;
//変換作業
for(z=1;z<=N;z++)
{
for(k=0;k<DWTf;k++)
{
sum =(g[k*2]+g[k*2+1])/2;
difference =(g[k*2]-g[k*2+1])/2;
gs[k] =sum;
//フィルタリング作業
if((LBs>=z)&&(z>=HBs)){gs[DWTf+k] = difference;}else{gs[DWTf+k] = 0;}
}
ArrayCopy(g,gs);
if(N>z) DWTf =DWTf/2;
}
//逆変換
for(z=1; z<=N ;z++)
{
for(k = 0; k < DWTf; k++)
{
sum = g[k]+g[k+DWTf];
difference = g[k]-g[k+DWTf];
gs[2*k] = sum;
gs[2*k+1] = difference;
}
ArrayCopy(g,gs);
if(N>z)DWTf =2*DWTf;
}
//プロット
for(k=0;k<DWTPeriod;k++){
IDWT[rates_total-DWTPeriod-Shift+k] = g[DWTPeriod-k-1];
}
return(rates_total);
}
//+------------------------------------------------------------------+
0 件のコメント :
コメントを投稿