#property description "The indicator shows the central limit theorem, which states:"
#property description "The sum of a sufficiently large number of weakly dependent random variables, "
#property description "having approximately equal magnitude (none of the summands dominates,"
#property description "or makes a determining contribution to the sum), has a distribution close to normal."
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
//--- グラフィック構成のプロパティ
#property indicator_label1 "Label"
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 clrRoyalBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 5
//--- 入力変数
input int sample_number=10;
//--- 分布を描画するための指標バッファ
double LabelBuffer[];
//--- ティックカウンタ
double ticks_counter;
//+------------------------------------------------------------------+
//| カスタム指標を初期化する関数 |
//+------------------------------------------------------------------+
void OnInit()
{
//--- 配列と指標バッファを関連付ける
SetIndexBuffer(0,LabelBuffer,INDICATOR_DATA);
//--- 指標バッファを現在から過去に向ける
ArraySetAsSeries(LabelBuffer,true);
//--- 擬似乱数生成器を初期化する
MathSrand(GetTickCount());
//--- ティックカウンタを初期化する
ticks_counter=0;
}
//+------------------------------------------------------------------+
//| カスタム指標の反復関数 |
//+------------------------------------------------------------------+
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[])
{
//--- ゼロカウンタで指標バッファをリセットする
if(ticks_counter==0) ArrayInitialize(LabelBuffer,0);
//--- カウンタを増加
ticks_counter++;
//--- 定期的に配信を復活させるために、ティックカウンターをリセットする必要がある
if(ticks_counter>100)
{
Print("We've reset the indicator values, let's start filling the cells once again");
ticks_counter=0;
}
//--- 0〜7の3つの数の和としてランダムな値のサンプルを取得する
for(int i=0;i<sample_number;i++)
{
//--- 乱数が他の 3 つの数の和であるセルのインデックスの計算
int rand_index=0;
//--- 0〜7 の 3 つの乱数を取得
for(int k=0;k<3;k++)
{
//--- 7 による除算で余りは 0〜6 の値を返す
rand_index+=MathRand()%7;
}
//--- セル番号 rand_index の値を 1 で増やす
LabelBuffer[rand_index]++;
}
//--- OnCalculate() ハンドルを終了する
return(rates_total);
}
|