MQL5 에서 Custom Indicator 파일 생성하기.
기본 생성된 Indicator 파일의 골격 코드.
#property indicator_chart_window
int OnInit()
{
return(INIT_SUCCEEDED);
}
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[])
{
return(rates_total);
}
앞의 동영상 에서 MQL wizard 초기 OnCalculate(,,price)로 선택하면 아래처럼 OnCalcualte 의 인자가 단순한것으로 코드 자동 생성된다.
#property indicator_chart_window
int OnInit()
{
return(INIT_SUCCEEDED);
}
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
return(rates_total);
}
챠트에 표현하는 초간단 샘플 코드.
- 아래 코드는 챠트에 현재 가격을 그대로 다시 그리는 것을 구현한 예.
#property indicator_separate_window // 지표를 가격챠트아닌 개별창에 독립적으로 표현하려는 경우
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 Red
input int NumBars_PlotBegin = 3;
input int NumBars_PlotShift = 0; // shift plot. the number of bars to shift
double ExtLineBuffer[];
int OnInit()
{
SetIndexBuffer(0,ExtLineBuffer,INDICATOR_DATA);//
PlotIndexSetInteger(0,PLOT_SHIFT,NumBars_PlotShift); // plot shift
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,NumBars_PlotBegin); // plot begin
return(INIT_SUCCEEDED);
}
int OnCalculate(const int rates_total,const int prev_calculated, const int begin,const double &price[])
{
int bar=0;
for(bar=0;bar<rates_total; bar++)
{
ExtLineBuffer[bar] = price[bar];
}
return(rates_total);
}
실행결과.
본 글 포함된 상위 정리글
메타트레이더5체계정리 https://igotit.tistory.com/1775
|
첫등록 : 2019년 5월 9일
최종수정 : 2020.12.11
본 글 단축주소 : https://igotit.tistory.com/2155
'트레이딩 > 메타트레이더 코딩' 카테고리의 다른 글
메타트레이더 . 코딩 . function pointer . 콜백 함수 (0) | 2019.05.13 |
---|---|
MQL5. EventChartCustom (0) | 2019.05.11 |
MQL5. 소켓통신 (0) | 2019.05.09 |
MQL5. 수직선 그리기 (2) | 2019.04.29 |
MQL5. 캔들 변경 지점 검출 (0) | 2019.04.29 |
댓글