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

메타트레이더 5. MQL5. 이벤트 및 핸들러.

by i.got.it 2019. 4. 17.




 

개요

 

MQL5 코드내에서 활용가능한 이벤트 들. 


이벤트 전체 리스트. 

이벤트소스

 이벤트핸들러

 

 

 Init

 OnInit()

 

 

 Deinit

 OnDeinit()

 

 

 Start

 OnStart()

 

 

 NewTick

 OnTick()

 

 

 Calculate

 OnCalculate()

 

 

 Timer

 OnTimer()

 

 

 Trade

 OnTrade()

 주문 관련 이벤트.

 

 TradeTransaction

 OnTradeTransaction()

 계좌(account) 관련 이벤트.

 

 Tester

 OnTester()

 

 

 TesterInit OnTesterInit()  
 TesterPass OnTesterPass()  
 TesterDeinit OnTesterDeinit()  
 ChartEvent OnChartEvent()  
 BookEvent

 OnBookEvent()

 DOM(Depth of Market) 변경 이벤트. 

 
    



 


 



 

Trade

 

trade 서버측에서 아래와 같은 처리가 완료된 시점에 발생.


- 주문 진입(sending), 수정(modifying), 취소(removing) 완료. 
- 지정가 주문의 취소(cancel) 완료. 취소사유 : 주문낼 돈 부족, 혹은 expiration. 
- 지정가 주문의 활성화(activation). 
- 포지션 opening, adding, closing. 
- 오픈 포지션의 수정 (예 : stop가격 수정)

OnTrade

 void OnTrade();





개념이해.

 
 


 

 

TradeTransaction

 


계좌(account) 에서 아래와 같은 상황.



- MQL5 코드에 의한 주문함수 OrderSend, OrderSendAsync 에 의한 주문요청 있는 경우 . 

- GUI 를 통한 주문 요청 있는 경우. (즉 사람이 수동 주문 한걸 의미함)

- 서버에서 지정가 주문이 활성화(activation) 된 경우 


OnTrdaeTransaction

 

void  OnTradeTransaction(
   const MqlTradeTransaction   trans,        // trade transaction structure
   const MqlTradeRequest&        request,      // request structure
   const MqlTradeResult&         result        // result structure
   );



인자. 


    • trans - this parameter gets MqlTradeTransaction structure describing a trade transaction applied to a trade account;
    • request - this parameter gets MqlTradeRequest structure describing a trade request;
    • result - this parameter gets MqlTradeResult structure describing a trade request execution result


 


 


 

ChartEvent

 

 챠트에서 아래와 같은 상황에서 발생. 

- 키보드 누름.
- graphical object 의 생성과 제거.
- graphical object 를 마우스 클릭할때. 
- graphical object 를 마우스로 이동할때.
- LabelEdit 의 문자 편집 끝냈을때.

OnChartEvent  

 void OnChartEvent(const int id,         // Event ID
                  const long& lparam,   // Parameter of type long event
                  const double& dparam, // Parameter of type double event
                  const string& sparam  // Parameter of type string events
  );


인자. 


id. lparam, dparam, sparam


  • CHARTEVENT_KEYDOWN — event of a keystroke, when the chart window is focused; 

  • CHARTEVENT_MOUSE_MOVE — mouse move events and mouse click events (if CHART_EVENT_MOUSE_MOVE=true is set for the chart);

  • CHARTEVENT_OBJECT_CHANGE — event of change of an object property via the properties dialog;

  • CHARTEVENT_CLICK — event of a mouse click on the chart;

  • CHARTEVENT_OBJECT_CLICK — event of a mouse click in a graphical object belonging to the chart;

  • CHARTEVENT_OBJECT_DRAG — event of a graphical object move using the mouse;
  • CHARTEVENT_OBJECT_ENDEDIT — event of the finished text editing in the entry box of the LabelEdit graphical object;

  • CHARTEVENT_CHART_CHANGE  — event of chart changes;

  • CHARTEVENT_CUSTOM+n — ID of the user event, where n is in the range from 0 to 65535.
  • CHARTEVENT_CUSTOM_LAST — the last acceptable ID of a custom event (CHARTEVENT_CUSTOM +65535).



OnChartEvent 코드예

코드예 OnChartEvent 마우스, 키 처리 : http://igotit.tistory.com/1818  



 


 




 

BookEvent

 


DOM(Depth of Market) 변화시 발생하는 이벤트. 


본 이벤트 발생시키려면 함수 MarketBookAdd 호출해야 한다. 

본 이벤트 해제할려면 함수 MarketBookRelease 호출해야 한다. 


 

 


 


 

NewTick 

 

어떤 Symbol 의 신규 tick 발생시. 

- EA 에서만 활용가능. 


OnTick 활용들. 

1. Multicurrency OnTick  https://www.mql5.com/en/code/280


 
 


 





 

본 글 포함된 상위 정리글. 

메타트레이더 5 체계정리. 활용법/지식 :  http://igotit.tistory.com/1775






첫등록 : 2018년 8월 13일 

최종수정 : 2019년 4월 17일 


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







댓글



 

비트코인




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