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

MQL5. 캔들 중 최고가 구하고 라인표현

by i.got.it 2019. 4. 27.

개요

아래 메타트레이더 5의 챠트에 현재 이전 지정된 캔들 수량(예 100개) 중 최고가를 찾고 이를 화면상에서 수평선 표현하는 코드 소스 정리.

 

 

 

아래 코드의 함수 get_Highest(int num_candle) 는 인자로 전달된 현재시점기준 과거 num_candle 수량중에서 최고가를 반환하는 함수. 이를 OnTick 에서 호출하여 print 하는 예. 

 

void OnTick()
{
   
   Print(Get_Highest(100)); 

}

double Get_Highest(int num_candle)
{
   int idx_highest_candle; 
   
   double arr_high[]; 
   
   ArraySetAsSeries(arr_high, true); //
   
   CopyHigh(_Symbol,_Period,0,num_candle, arr_high);  //0means current candle, 100 candle's H copy to High[] 
   
   idx_highest_candle = ArrayMaximum(arr_high,0,num_candle); // search for highest candle.

   return arr_high[idx_highest_candle];
}

시각적으로 해당 고가를 챠트에 표현하는 기능 추가하면 아래코드. 

int OnInit()
{

   Init_myLine(); 
   
   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{


}

void OnTick()
{

   ObjectMove(_Symbol, "Line1",0,0,Get_Highest(100)); // draw line 

}

double Get_Highest(int num_candle)
{
   int idx_highest_candle; 
   
   double arr_high[]; 
   
   ArraySetAsSeries(arr_high, true); //
   
   CopyHigh(_Symbol,_Period,0,num_candle, arr_high);  //0means current candle, 100 candle's H copy to High[] 
   
   idx_highest_candle = ArrayMaximum(arr_high,0,num_candle); // search for highest candle.

   return arr_high[idx_highest_candle];
}



void Init_myLine()
{

   ObjectCreate(
            _Symbol, 
            "Line1",  
            OBJ_HLINE,  
            0, //int sub_window
            0, //datetime time1 
            0 // y value on chart
   ); 
   
   ObjectSetInteger(
            0, // long chart_id
            "Line1",
            OBJPROP_COLOR, //int properti_modifier
            clrRed       // long value
   );
   
   ObjectSetInteger(0,"Line1",OBJPROP_WIDTH, 1); // line width. 
}

 

작동동영상. 

 

 

 

 

 본 글 포함된 상위 정리글

 

 메타트레이더5체계정리 : https://igotit.tistory.com/1775

 

 


첫등록 :  2019년 4월 27일.

최종수정 : 

 

본 글 단축주소 : https://igotit.tistory.com/2142

 


 

'트레이딩 > 메타트레이더 코딩' 카테고리의 다른 글

MQL5. 클래스 만들기  (0) 2019.04.29
MQL5. ATR ( Average True Range )  (3) 2019.04.28
MQL5. 수평선 그리기  (0) 2019.04.27
MQL5. Data Collections.  (0) 2019.04.24
MQL5. 포지션 함수, 클래스.  (0) 2019.04.23

댓글



 

비트코인




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