#property 설명 "지표는 중심 극한 정리를 나타내며, 이것은 다음과 같습니다:"
#property 설명 "약하게 종속된 랜덤 변수의 수가 충분히 많은 총합, "
#property 설명 "대략적으로 같은 크기를 가지고 있음(어떤 덧수도 지배하지 않음,"
#property 설명 "또는 합계에 대한 결정적 기여를 함)에 정규 분포에 가까운 분포가 있음."
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
//--- 그래픽 구조의 특성
#property indicator_label1 "레이블"
#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("지표 값을 재설정했습니다. 다시 한 번 셀 채우기를 시작하겠습니다.");
ticks_counter=0;
}
//--- 0에서 7까지의 세 숫자의 합으로 랜덤 값의 표본을 가져옵니다.
for(int i=0;i<sample_number;i++)
{
//--- 셀의 지수 계산. 여기서 난수가 다른 세 개의 숫자의 합으로 됩니다.
int rand_index=0;
//--- 0에서 7까지 세 개의 난수를 구합니다.
for(int k=0;k<3;k++)
{
//--- 7까지 나눗셈에 남은 값은 0부터 6까지의 값을 반환합니다.
rand_index+=MathRand()%7;
}
//--- 셀 번호 rand_index의 값을 1만큼 늘립니다.
LabelBuffer[rand_index]++;
}
//--- OnCalculate() 핸들러 종료
return(rates_total);
}
|