본문 바로가기
트레이딩/메타트레이더 코딩

MQL5. Custom Indicator

by i.got.it 2019. 5. 10.

 

 

 

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

 


 

댓글



 

비트코인




암호화폐       외환/나스닥/골드       암호화폐/외환/나스닥/골드 암호화폐/외환/나스닥/골드   암호화폐/외환/나스닥/골드
     
현물 |선물 인버스 |선물 USDT       전략매니저(카피트레이딩)     롤오버 이자 없는 스왑프리계좌
( 스왑프리 암호화폐도 거래 가능 )    
MT4, MT5 , cTrader 모두 지원     FTMO 계좌 매매운용. MT4,MT5