#property indicator_chart_window
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_buffers 4
//新しくBufBuy,BufSellを定義
double BufFast[];
double BufSlow[];
double BufBuy[];
double BufSell[];
extern int FastPeriod = 9;
extern int SlowPeriod = 21;
//初期化関数
int init()
{
//指標バッファの割り当て
SetIndexBuffer(0,BufFast);
SetIndexBuffer(1,BufSlow);
SetIndexBuffer(2,BufBuy);
SetIndexBuffer(3,BufSell);
//指標2と3を矢印で表示
SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,1,Blue);
SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,1,Red);
//指標2と3の矢印を定義
SetIndexArrow(2,233);
SetIndexArrow(3,234);
}
int start()
{
int counted_bars = IndicatorCounted();
int limit = Bars - counted_bars;
if(counted_bars == 0) limit -= SlowPeriod-1;
for(int i=limit-1; i>=0; i--)
{
//移動平均の計算@
BufFast[i]=0;
for(int j=0; j<=FastPeriod-1; j++)
{
BufFast[i] += Close[i+j];
}
BufFast[i] /= FastPeriod;
//移動平均の計算A
BufSlow[i]=0;
for(j=0; j<=SlowPeriod-1; j++)
{
BufSlow[i] += Close[i+j];
}
BufSlow[i] /= SlowPeriod;
//買いシグナルの表示
BufBuy[i]=EMPTY_VALUE;
if(BufFast[i+2]<=BufSlow[i+2] && BufFast[i+1]>=BufSlow[i+1]) BufBuy[i]=Open[i];
//売りシグナルの表示
BufSell[i]=EMPTY_VALUE;
if(BufFast[i+2]>=BufSlow[i+2] && BufFast[i+1]>=BufSlow[i+1]) BufSell[i]=Open[i];
}
return(0);
}
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_buffers 4
//新しくBufBuy,BufSellを定義
double BufFast[];
double BufSlow[];
double BufBuy[];
double BufSell[];
extern int FastPeriod = 9;
extern int SlowPeriod = 21;
//初期化関数
int init()
{
//指標バッファの割り当て
SetIndexBuffer(0,BufFast);
SetIndexBuffer(1,BufSlow);
SetIndexBuffer(2,BufBuy);
SetIndexBuffer(3,BufSell);
//指標2と3を矢印で表示
SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,1,Blue);
SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,1,Red);
//指標2と3の矢印を定義
SetIndexArrow(2,233);
SetIndexArrow(3,234);
}
int start()
{
int counted_bars = IndicatorCounted();
int limit = Bars - counted_bars;
if(counted_bars == 0) limit -= SlowPeriod-1;
for(int i=limit-1; i>=0; i--)
{
//移動平均の計算@
BufFast[i]=0;
for(int j=0; j<=FastPeriod-1; j++)
{
BufFast[i] += Close[i+j];
}
BufFast[i] /= FastPeriod;
//移動平均の計算A
BufSlow[i]=0;
for(j=0; j<=SlowPeriod-1; j++)
{
BufSlow[i] += Close[i+j];
}
BufSlow[i] /= SlowPeriod;
//買いシグナルの表示
BufBuy[i]=EMPTY_VALUE;
if(BufFast[i+2]<=BufSlow[i+2] && BufFast[i+1]>=BufSlow[i+1]) BufBuy[i]=Open[i];
//売りシグナルの表示
BufSell[i]=EMPTY_VALUE;
if(BufFast[i+2]>=BufSlow[i+2] && BufFast[i+1]>=BufSlow[i+1]) BufSell[i]=Open[i];
}
return(0);
}
まず、BufBuy,BufSellという2つの指標バッファを定義。
それぞれ、2番目・3番目の指標として割り当てます。
同時に#propertyにてカラーも定義しておきます。
init()内の矢印についての記述は後回しにします。
移動平均の計算はこれまでと同じです。
買いシグナルの部分ですが、これは移動平均の交差(golden cross)が
確定したOpenの値をBufBuy[]に入れています。
EMPTY_VALUEというのは何も入っていないということを意味し、
if文の中身(つまりGC)を満たさない限り、その時のBufBuyには
何も入らないことになります。
売りシグナルはこの真逆です。
結果、BufBuyf,BufSellにはそれぞれGolden Cross, Dead Crossが確定した際のOpen値が入ることになりますが、これを矢印で表示してやるために
init()内で2と3の指標は矢印で表示するように定義するわけです。
【売買シグナルを表示させる@の最新記事】



