
초보자를 위한 MQL5 : Expert Adviser의 기술 지표 사용 가이드
소개
코드에 표준 기술 지표를 사용하지 않는 Expert Advisor 또는 지표는 드뭅니다. 그들은 거래 전략의 초보자와 고급 개발자 모두에게 인기가 있습니다. 지표 생성의 세부 사항을 이해하는 것은 어렵지 않습니다. 이 글의 목적은 그 이해를 돕는 것입니다. 내장된 표준 기술 지표로 작업하기 위한 함수의 사용을 고려할 것입니다.
표준 기술 지표 기능 사용의 기초
호출될 때 기술 인디케이터의 각 함수는 지정된 입력 매개 변수를 사용하여 생성된 개체 (인디케이터 인스턴스)의 핸들을 만듭니다. 핸들의 목적은 이 개체와 함께 할당하는 것입니다. 인디케이터 버퍼에서 데이터를 가져 와서 자체 계산에 사용하는 것으로 충분합니다. 예를 들어 보겠습니다.
double MA[]; // array for the indicator iMA int MA_handle; // handle of the indicator iMA //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iMA MA_handle=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE); return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array MA[] with current values of iMA //--- Copying 100 elements CopyBuffer(MA_handle,0,0,100,MA); //--- set indexing of elements as series, as in MQL4 ArraySetAsSeries(MA,true); //--- here you can use the data of MA[] as you wish, for example: if(MA[0]>MA[1]) { //--- some operations } }
보시다시피 모든 것이 아주 간단합니다. 이 예는 트레이더들 사이에서 가장 인기있는 지표 iMA - 를 사용하는 방법을 보여줍니다.
인디케이터의 핸들은 OnInit() 함수 내에 생성되어야 합니다.
- "MQL4에서와 같이 요소의 인덱싱을 시리즈로 설정" - 이건 무슨 의미입니까? 이 예에서는 요소 색인을 timeseries로 사용했습니다. 즉, 아직 형성되지 않은 현재 바는 항상 색인 [0], 이전 (이미 형성된) 색인 [1] 등을 갖습니다.
- 인덱싱을 설정하는 이유는 무엇입니까? 알고리즘의 편의성과 최적의 구현을 위해 사용했습니다. MQL5 언어를 사용하면 프로그래머에게 편리한 인덱싱을 사용할 수 있습니다.
- OnInit() 함수 안에 인디케이터를 만드는 것이 더 좋은 이유는 무엇입니까? 물론 명시적인 금지가 없기 때문에 프로그램의 어느 곳에서나 만들 수 있습니다. 그러나 제안된 방식의 경우 호의적인 입장을 취하는 측에서의 강력한 논쟁의 여지가 있습니다. OnInit() 함수는 Expert Advisor 시작시 한 번 호출되며 실행 중에 매개 변수를 변경하지 않는 인디케이터 초기화를 수행하는 것으로 충분합니다. 입력 매개 변수를 변경하는 경우 다른 함수 (예 : OnTick())에서 다시 초기화 할 수 있습니다.
프로그래밍 클래스
거의 모든 Expert Advisor는 데모뿐만 아니라 실제 계정에서도 거래 작업을 수행하도록 설계되었습니다. 이게 거래를 진행할 때 조용히 자고 싶다면 거래의 가능한 모든 결과를 예측해야 합니다. 자동화된 거래 시스템의 우수한 개발자조차도 종종 성가신 실수를 합니다. 그리고 그러한 실수의 대가는 매우 클 수 있습니다!
예를 들어, 다음은 Automated Trading Championship 2008에서 일어난 이야기입니다. 참가자 중 한 명의 Expert Adviser이 예금을 일정 수준으로 늘리고 잤습니다. 여기서 그런 일이 발생하게 됩니다. 작가와 Expert Adviser의 작업을 보고 있던 모든 사람들은 깨어나서 다시 거래를 시작하여 번 돈을 잃고는 충격을 받습니다.
물론, 로봇이 통제를 벗어 났을 때 비슷한 실수를 하고 싶지는 않을 것입니다. 따라서 표준 기술 지표를 사용하는 동안 잡을 수 있는 "암초"를 고려해 보겠습니다.
- 개체 포인터는 초기화 블록에 생성됩니다. 그리고 그것이 실패했다면 어떨까요? 이 경우 빈 참조를 얻습니다. 따라서 MQL5 개발자가 제공한 유효성을 확인할 수있는 가능성을 활용 해 보겠습니다. 포인터가 생성되지 않은 경우 함수가 반환하는 핸들 값은 표준 상수 INVALID_HANDLE = -1과 같습니다.
- 지표에서 데이터를 가져 오면 그 값을 지표의 버퍼에 복사하여 계산에 사용합니다. 실패하면 어떻게 됩니까? 복사에 실패하면 거래 시스템이 잘못된 거래 신호를 생성 할 수 있습니다. 이러한 경우에 MQL5 개발자들은 복사된 요소의 수를 즉시 확인할 수있는 가능성을 제공해왔습니다. 오류 발생시 복사된 요소의 수는 -1입니다.
이제 코드화 방법을 고려해 보겠습니다.
//---- arrays for indicators double MA[]; // array for the indicator iMA //---- handles for indicators int MA_handle; // handle of the indicator iMA //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iMA MA_handle=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE); //--- report if there was an error in object creation if(MA_handle<0) { Print("The creation of iMA has failed: MA_handle=",INVALID_HANDLE); Print("Runtime error = ",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array MA[] with current values of iMA //--- 100 elements should be written to the array //--- if there was an error, we terminate the execution of program if(CopyBuffer(MA_handle,0,0,100,MA)<=0) return; //--- set indexation of array MA[] as timeseries ArraySetAsSeries(MA,true); //--- here you can use the data of MA[] as you wish if(MA[0]>MA[1]) { //--- some operations } }
코드를 약간만 변경해도 안전성과 신뢰성이 향상됩니다. 그러나 그게 다가 아닙니다. 이제 인디케이터의 값을 배열에 복사하는 절차가 개선 될 수 있으므로 작성된 함수를 사용해야 합니다.
//+------------------------------------------------------------------------------+ //| The function copies the values of the indicator,the elements | //| will be indexed depending on the value of the input parameter asSeries | //+------------------------------------------------------------------------------+ bool CopyBufferAsSeries( int handle, // indicator's handle int bufer, // buffer index int start, // start index int number, // number of elements to copy bool asSeries, // if it's true, the elements will be indexed as series double &M[] // target array ) { //--- filling the array M with current values of the indicator if(CopyBuffer(handle,bufer,start,number,M)<=0) return(false); //--- the elements will be indexed as follows: //--- if asSeries=true, it will be indexed as timeseries //--- if asSeries=false, it will be indexed as default ArraySetAsSeries(M,asSeries); //--- return(true); }
CopyBufferAsSeries 함수는 이 글에 첨부된 GetIndicatorBuffers.mqh 파일에 있습니다. 이를 사용하려면 코드에 include 지시문을 추가해야 합니다. 꼭 ..\ MQL5\Include\ 폴더에 복사해야 합니다. 인디케이터 iMA를 호출하고 인디케이터의 버퍼에서 해당 배열로 데이터를 복사하는 최종 코드는 다음과 같습니다.
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double MA[]; // array for the indicator iMA //---- handles for indicators int MA_handle; // handle for the indicator iMA //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iMA MA_handle=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE); //--- report if there was an error in object creation if(MA_handle<0) { Print("The creation of iMA has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array MA[] with current values of iMA //--- set indexation of array MA[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(MA_handle,0,0,100,true,MA)) return; //--- here you can use the data of MA[] as you wish, for example: if(MA[0]>MA[1]) { //--- some operations } }
다중 버퍼 인디케이터의 기능
예를 들어, 3 개의 인디케이터 버퍼 가 있는 iAlligator 인디케이터를 살펴 보겠습니다.
- 0 buffer - GATORJAW_LINE
- 1st buffer - GATORTEETH_LINE
- 2nd buffer - GATORLIPS_LINE
한 번의 호출을 사용하여 이러한 인디케이터의 버퍼에서 데이터 수신을 수행하기 위해 이 글에 포함된 파일에서 찾을 수 있는 다음 함수를 사용합니다.
//+------------------------------------------------------------------------------+ //| The function copies the values of the indicator Alligator to three arrays: | //| Jaws[], Teeth[], Lips[] (with elements indexed as timeaseries). | //+------------------------------------------------------------------------------+ bool GetAlligatorBuffers(int Alligator_handle, int start, int number, double &Jaws[], double &Teeth[], double &Lips[], bool asSeries=true // (elements indexed as timeaseries) ) { //--- filling an array Jaws with current values of GATORJAW_LINE if(!CopyBufferAsSeries(Alligator_handle,0,start,number,asSeries,Jaws)) return(false); //--- filling an array Teeth with current values of GATORTEETH_LINE if(!CopyBufferAsSeries(Alligator_handle,1,start,number,asSeries,Teeth)) return(false); //--- filling an array Lisp with current values of GATORLIPS_LINE if(!CopyBufferAsSeries(Alligator_handle,2,start,number,asSeries,Lips)) return(false); //--- return(true); }
다음과 같이 사용할 수 있습니다.
#include <GetIndicatorBuffers.mqh> //---- indicator buffers double Jaws[]; // array for GATORJAW_LINE of iAlligator double Teeth[]; // array for GATORTEETH_LINE of iAlligator double Lips[]; // array for GATORLIPS_LINE of iAlligator //---- handles for indicators int Alligator_handle; // handle of the indicator iAlligator //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iAlligator Alligator_handle=iAlligator(NULL,0,13,8,8,5,5,3,MODE_EMA,PRICE_MEDIAN); //--- report if there was an error in object creation if(Alligator_handle<0) { Print("The creation of iAlligator has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation of arrays as timeseries //--- fill arrays with current values of Alligator //--- return if there was an error if(!GetAlligatorBuffers(Alligator_handle,0,100,Jaws,Teeth,Lips,true)) return; }
그래서 저희는 요점을 요약했고 이제 모든 표준 지표에 대한 예를 고려할 준비가 되었습니다.
표준 지표 사용의 예
iAC
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double AC[]; // array for the indicator iAC //---- handles for indicators int AC_handle; // handle of the indicator iAC //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iAC AC_handle=iAC(NULL,0); //--- report if there was an error in object creation if(AC_handle<0) { Print("The creation of iAC has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array AC[] with current values of iAC //--- set indexation of array AC[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(AC_handle,0,0,100,true,AC)) return; }
iAD
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double AD[]; // array for the indicator iAD //---- handles for indicators int AD_handle; // handle for the indicator iAD //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iAD AD_handle=iAD(NULL,0,VOLUME_TICK); //--- report if there was an error in object creation if(AD_handle<0) { Print("The creation of iAD has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array AD[] with current values of iAD //--- set indexation of array AD[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(AD_handle,0,0,100,true,AD)) return; }
iADX
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Main[]; // array for MAIN_LINE of iADX double PlusDI[]; // array for PLUSDI_LINE of iADX double MinusDI[]; // array for MINUSDI_LINE of iADX //---- handles for indicators int ADX_handle; // handle of the indicator iADX //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iADX ADX_handle=iADX(NULL,0,14); //--- report if there was an error in object creation if(ADX_handle<0) { Print("The creation of iADX has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation of arrays as timeseries //--- filling the arrays with current values of all indicator's buffers //--- return if there was an error if(!GetADXBuffers(ADX_handle,0,100,Main,PlusDI,MinusDI,true)) return; }
iADXWilder
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Main[]; // array for MAIN_LINE of iADXWilder double PlusDI[]; // array for PLUSDI_LINE of iADXWilder double MinusDI[]; // array for MINUSDI_LINE of iADXWilder //---- handles for indicators int ADXWilder_handle; // handle of the indicator iADXWilder //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iADXWilder ADXWilder_handle=iADXWilder(NULL,0,14); //--- report if there was an error in object creation if(ADXWilder_handle<0) { Print("The creation of iADXWilder has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation of arrays as timeseries //--- filling the arrays with current values of all indicator's buffers //--- return if there was an error if(!GetADXWilderBuffers(ADXWilder_handle,0,100,Main,PlusDI,MinusDI,true)) return; }
iAlligator
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Jaws[]; // array for GATORJAW_LINE of iAlligator double Teeth[]; // array for GATORTEETH_LINE of iAlligator double Lips[]; // array for GATORLIPS_LINE of iAlligator //---- handles for indicators int Alligator_handle; // handle of the indicator iAlligator //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iAlligator Alligator_handle=iAlligator(NULL,0,13,8,8,5,5,3,MODE_EMA,PRICE_MEDIAN); //--- report if there was an error in object creation if(Alligator_handle<0) { Print("The creation of iAlligator has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation of arrays as timeseries //--- filling the arrays with current values of all indicator's buffers //--- return if there was an error if(!GetAlligatorBuffers(Alligator_handle,0,100,Jaws,Teeth,Lips,true)) return; }
iAMA
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double AMA[]; // array for the indicator iAMA //---- handles for indicators int AMA_handle; // handle for the indicator iAMA //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iAMA AMA_handle=iAMA(NULL,0,21,5,8,0,PRICE_CLOSE); //--- report if there was an error in object creation if(AMA_handle<0) { Print("The creation of iAMA has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array AMA[] with current values of iAMA //--- set indexation of array AMA[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(AMA_handle,0,0,100,true,AMA)) return; }
iAO
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double AO[]; // array for the indicator iAO //---- handles for indicators int AO_handle; // handle of the indicator iAO //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iAO AO_handle=iAO(NULL,0); //--- report if there was an error in object creation if(AO_handle<0) { Print("The creation of iAO has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array AO[] with current values of iAO //--- set indexation of array AO[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(AO_handle,0,0,100,true,AO)) return; }
iATR
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double ATR[]; // array for the indicator iATR //---- handles for indicators int ATR_handle; // handle of the indicator iATR //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iATR ATR_handle=iATR(NULL,0,14); //--- report if there was an error in object creation if(ATR_handle<0) { Print("The creation of iATR has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array ATR[] with current values of iATR //--- set indexation of array ATR[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(ATR_handle,0,0,100,true,ATR)) return; }
iBearsPower
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double BearsPower[]; // array for the indicator iBearsPower //---- handles for indicators int BearsPower_handle; // handle for the indicator iBearsPower //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iBearsPower BearsPower_handle=iBearsPower(NULL,0,14); //--- report if there was an error in object creation if(BearsPower_handle<0) { Print("The creation of iBearsPower has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array BearsPower[] with current values of iBearsPower //--- set indexation of array BearsPower[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(BearsPower_handle,0,0,100,true,BearsPower)) return; }
iBands
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Base[]; // array for BASE_LINE of iBands double Upper[]; // array for UPPER_BAND of iBands double Lower[]; // array for LOWER_BAND of iBands //---- handles for indicators int Bands_handle; // handle of the indicator iBands //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iBands Bands_handle=iBands(NULL,0,144,0,2,PRICE_CLOSE); //--- report if there was an error in object creation if(Bands_handle<0) { Print("The creation of iBands has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation of arrays as timeseries //--- filling the arrays with current values of all indicator's buffers //--- return if there was an error if(!GetBandsBuffers(Bands_handle,0,100,Base,Upper,Lower,true)) return; }
iBullsPower
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double BullsPower[]; // array for the indicator iBullsPower //---- handles for indicators int BullsPower_handle; // handle for the indicatoriBullsPower //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iBullsPower BullsPower_handle=iBullsPower(NULL,0,14); //--- report if there was an error in object creation if(BullsPower_handle<0) { Print("The creation of iBullsPower has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array BullsPower[] with current values of iBullsPower //--- set indexation of array BullsPower[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(BullsPower_handle,0,0,100,true,BullsPower)) return; }
iCCI
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double CCI[]; // array for the indicator iCCI //---- handles for indicators int CCI_handle; // handle for the indicator iCCI //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iCCI CCI_handle=iCCI(NULL,0,14,PRICE_CLOSE); //--- report if there was an error in object creation if(CCI_handle<0) { Print("The creation of iCCI has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array CCI[] with current values of iCCI //--- set indexation of array CCI[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(CCI_handle,0,0,100,true,CCI)) return; }
iChaikin
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Chaikin[]; // array for the indicator iChaikin //---- handles for indicators int Chaikin_handle; // handle for the indicator iChaikin //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iChaikin Chaikin_handle=iChaikin(NULL,0,8,14,MODE_EMA,VOLUME_TICK); //--- report if there was an error in object creation if(Chaikin_handle<0) { Print("The creation of iChaikin has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array Chaikin[] with current values of iChaikin //--- set indexation of array AC[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(Chaikin_handle,0,0,100,true,Chaikin)) return; }
iDEMA
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double DEMA[]; // array for the indicator iDEMA //---- handles for indicators int DEMA_handle; // handle for the indicator iDEMA //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iDEMA DEMA_handle=iDEMA(NULL,0,8,0,PRICE_CLOSE); //--- report if there was an error in object creation if(DEMA_handle<0) { Print("The creation of iDEMA has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array DEMA[] with current values of iDEMA //--- set indexation of array DEMA[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(DEMA_handle,0,0,100,true,DEMA)) return; }
iDeMarker
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double DeMarker[]; // array for the indicator iDeMarker //---- handles for indicators int DeMarker_handle; // handle for the indicator iDeMarker //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iDeMarker DeMarker_handle=iDeMarker(NULL,0,21); //--- report if there was an error in object creation if(DeMarker_handle<0) { Print("The creation of iDeMarker has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array DeMarker[] with current values of iDeMarker //--- set indexation of array DeMarker[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(DeMarker_handle,0,0,100,true,DeMarker)) return; }
iEnvelopes
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Upper[]; // array for UPPER_LINE of iEnvelopes double Lower[]; // array for LOWER_LINE of iEnvelopes //---- handles for indicators int Envelopes_handle; // handle of the indicator iEnvelopes //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iEnvelopes Envelopes_handle=iEnvelopes(NULL,0,14,0,MODE_SMA,PRICE_CLOSE,0.1); //--- report if there was an error in object creation if(Envelopes_handle<0) { Print("The creation of iEnvelopes has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation for arrays as timeseries //--- return if there was an error //--- filling the arrays with current values of iEnvelopes if(!GetEnvelopesBuffers(Envelopes_handle,0,100,Upper,Lower,true)) return; }
iForce
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Force[]; // array for the indicator iForce //---- handles for indicators int Force_handle; // handle for the indicator iForce //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iForce Force_handle=iForce(NULL,0,21,MODE_SMA,VOLUME_TICK); //--- report if there was an error in object creation if(Force_handle<0) { Print("The creation of iForce has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array Force[] with current values of iForce //--- set indexation of array Force[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(Force_handle,0,0,100,true,Force)) return; }
iFractals
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Upper[]; // array for UPPER_LINE of iFractals double Lower[]; // array for LOWER_LINE of iFractals //---- handles for indicators int Fractals_handle; // handle of the indicator iFractals //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iFractals Fractals_handle=iFractals(NULL,0); //--- report if there was an error in object creation if(Fractals_handle<0) { Print("The creation of iFractals has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation of arrays as timeseries //--- filling the arrays with current values of all indicator's buffers //--- return if there was an error if(!GetFractalsBuffers(Fractals_handle,0,100,Upper,Lower,true)) return; }
iFrAMA
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double FrAMA[]; // array for the indicator iFrAMA //---- handles for indicators int FrAMA_handle; // handle for the indicator iFrAMA //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iFrAMA FrAMA_handle=iFrAMA(NULL,0,21,0,MODE_SMA); //--- report if there was an error in object creation if(FrAMA_handle<0) { Print("The creation of iFrAMA has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array FrAMA[] with current values of iFrAMA //--- set indexation of array FrAMA[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(FrAMA_handle,0,0,100,true,FrAMA)) return; }
iGator
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Upper[]; // array for UPPER_LINE of iGator double Lower[]; // array for LOWER_LINE of iGator //---- handles for indicators int Gator_handle; // handle of the indicator iGator //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iGator Gator_handle=iGator(NULL,0,13,8,8,5,5,3,MODE_EMA,PRICE_MEDIAN); //--- report if there was an error in object creation if(Gator_handle<0) { Print("The creation of iGator has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation of arrays as timeseries //--- filling the arrays with current values of all indicator's buffers //--- return if there was an error if(!GetGatorBuffers(Gator_handle,0,100,Upper,Lower,true)) return; }
iIchimoku
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Tenkansen[]; // array for TENKANSEN_LINE of iIchimoku double Kijunsen[]; // array for KIJUNSEN_LINE of iIchimoku double SenkouspanA[]; // array for SENKOUSPANA_LINE of iIchimoku double SenkouspanB[]; // array for SENKOUSPANB_LINE of iIchimoku double Chinkouspan[]; // array for CHINKOUSPAN_LINE of iIchimoku //---- handles for indicators int Ichimoku_handle; // handle of the indicator iIchimoku //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iIchimoku Ichimoku_handle=iIchimoku(NULL,0,9,26,52); //--- report if there was an error in object creation if(Ichimoku_handle<0) { Print("The creation of iIchimoku has failed: Runtime error =",GetLastError()); //--- forced program terminatio return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation of arrays as timeseries //--- filling the arrays with current values of all indicator's buffers //--- return if there was an error if(!GetIchimokuBuffers(Ichimoku_handle,0,100, Tenkansen, Kijunsen, SenkouspanA, SenkouspanB, Chinkouspan, true)) return; }
iBWMFI
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double BWMFI[]; // array for the indicator iBWMFI //---- handles for indicators int BWMFI_handle; // handle of the indicato iBWMFI //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iBWMFI BWMFI_handle=iBWMFI(NULL,0,VOLUME_TICK); //--- report if there was an error in object creation if(BWMFI_handle<0) { Print("The creation of iBWMFI has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array BWMFI[] with current values of iBWMFI //--- set indexation of array BWMFI[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(BWMFI_handle,0,0,100,true,BWMFI)) return; }
iMomentum
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Momentum[]; // array for the indicator iMomentum //---- handles for indicators int Momentum_handle; // handle for the indicator iMomentum //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iMomentum Momentum_handle=iMomentum(NULL,0,14,PRICE_CLOSE); //--- report if there was an error in object creation if(Momentum_handle<0) { Print("The creation of iMomentum has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array Momentum[] with current values of iMomentum //--- set indexation of array Momentum[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(Momentum_handle,0,0,100,true,Momentum)) return; }
iMFI
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double MFI[]; // array for the indicator iMFI //---- handles for indicators int MFI_handle; // handle of the indicator iMFI //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iMFI MFI_handle=iMFI(NULL,0,14,VOLUME_TICK); //--- report if there was an error in object creation if(MFI_handle<0) { Print("The creation of iMFI has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array MFI[] with current values of iMFI //--- set indexation of array MFI[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(MFI_handle,0,0,100,true,MFI)) return; }
iMA
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double MA[]; // array for the indicator iMA //---- handles for indicators int MA_handle; // handle of the indicator iMA //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iMA MA_handle=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE); //--- report if there was an error in object creation if(MA_handle<0) { Print("The creation of iMA has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array MA[] with current values of iMA //--- set indexation of array MA[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(MA_handle,0,0,100,true,MA)) return; }
iOsMA
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double OsMA[]; // array for the indicator iOsMA //---- handles for indicators int OsMA_handle; // handle of the indicator iOsMA //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iOsMA OsMA_handle=iOsMA(NULL,0,8,21,14,PRICE_MEDIAN); //--- report if there was an error in object creation if(OsMA_handle<0) { Print("The creation of iOsMA has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array OsMA[] with current values of iOsMA //--- set indexation of array OsMA[] timeseries //--- return if there was an error if(!CopyBufferAsSeries(OsMA_handle,0,0,100,true,OsMA)) return; }
iMACD
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Main[]; // array for MAIN_LINE of iMACD double Signal[]; // array for SIGNAL_LINE of iMACD //---- handles for indicators int MACD_handle; // handle of the indicator iMACD //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iMACD MACD_handle=iMACD(NULL,0,12,26,9,PRICE_CLOSE); //--- report if there was an error in object creation if(MACD_handle<0) { Print("The creation of iMACD has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation of arrays as timeseries //--- filling the arrays with current values of all indicator's buffers //--- return if there was an error if(!GetMACDBuffers(MACD_handle,0,100,Main,Signal,true)) return; }
iOBV
#include <GetIndicatorBuffers.mqh> //---- indicator buffers double OBV[]; // array for the indicator iOBV //---- handles for indicators int OBV_handle; // handle for the indicator iOBV //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iOBV OBV_handle=iOBV(NULL,0,VOLUME_TICK); //--- report if there was an error in object creation if(OBV_handle<0) { Print("The creation of iOBV has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array OBV[] with current values of iOBV //--- set indexation of array AC[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(OBV_handle,0,0,100,true,OBV)) return; }
iSAR
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double SAR[]; // array for the indicator iSAR //---- handles for indicators int SAR_handle; // handle of the indicator iSAR //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iSAR SAR_handle=iSAR(NULL,0,0.02,0.2); //--- report if there was an error in object creation if(SAR_handle<0) { Print("The creation of iSAR has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array SAR[] with current values of iSAR //--- set indexation of array SAR[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(SAR_handle,0,0,100,true,SAR)) return; }
iRSI
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double RSI[]; // array for the indicator iRSI //---- handles for indicators int RSI_handle; // handle of the indicator iRSI //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iRSI RSI_handle=iRSI(NULL,0,21,PRICE_CLOSE); //--- report if there was an error in object creation if(RSI_handle<0) { Print("The creation of iRSI has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array RSI[] with current values of iRSI //--- set indexation of array RSI[] as timeserie //--- return if there was an error if(!CopyBufferAsSeries(RSI_handle,0,0,100,true,RSI)) return; }
iRVI
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Main[]; // array for MAIN_LINE of iRVI double Signal[]; // array for SIGNAL_LINE of iRVI //---- handles for indicators int RVI_handle; // handle of the indicator iRVI //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iRVI RVI_handle=iRVI(NULL,0,14); //--- report if there was an error in object creation if(RVI_handle<0) { Print("The creation of iRVI has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation of arrays as timeseries //--- filling the arrays with current values of all indicator's buffers //--- return if there was an error if(!GetRVIBuffers(RVI_handle,0,100,Main,Signal,true)) return; }
iStdDev
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double StdDev[]; // array for the indicator iStdDev //---- handles for indicators int StdDev_handle; // handle for the indicator iStdDev //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iStdDev StdDev_handle=iStdDev(NULL,0,20,0,MODE_SMA,PRICE_CLOSE); //--- report if there was an error in object creation if(StdDev_handle<0) { Print("The creation of iStdDev has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array StdDev[] with current values of iStdDev //--- set indexation of array StdDev[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(StdDev_handle,0,0,100,true,StdDev)) return; }
iStochastic
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Main[]; // array for MAIN_LINE of iStochastic double Signal[]; // array for SIGNAL_LINE of iStochastic //---- handles for indicators int Stochastic_handle; // handle of the indicator iStochastic //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iStochastic Stochastic_handle=iStochastic(NULL,0,5,3,3,MODE_SMA,STO_LOWHIGH); //--- report if there was an error in object creation if(Stochastic_handle<0) { Print("The creation of iStochastic has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- set indexation of arrays as timeseries //--- filling the arrays with current values of all indicator's buffers //--- return if there was an error if(!GetStochasticBuffers(Stochastic_handle,0,100,Main,Signal,true)) return; }
iTEMA
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double TEMA[]; // array for the indicator iTEMA //---- handles for indicators int TEMA_handle; // handle of the indicator iTEMA //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iTEMA TEMA_handle=iTEMA(NULL,0,20,0,PRICE_CLOSE); //--- report if there was an error in object creation if(TEMA_handle<0) { Print("The creation of iTEMA has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array TEMA[] with current values of iTEMA //--- set indexation of array TEMA[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(TEMA_handle,0,0,100,true,TEMA)) return; }
iTriX
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double TriX[]; // array for the indicator iTriX //---- handles for indicators int TriX_handle; // handle of the indicator iTriX //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iTriX TriX_handle=iTriX(NULL,0,20,PRICE_CLOSE); //--- report if there was an error in object creation if(TriX_handle<0) { Print("The creation of iTriX has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array TriX[] with current values of iTriX //--- set indexation of array TriX[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(TriX_handle,0,0,100,true,TriX)) return; }
iWPR
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double WPR[]; // array for the indicator iWPR //---- handles for indicators int WPR_handle; // handle of the indicator iWPR //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iWPR WPR_handle=iWPR(NULL,0,14); //--- report if there was an error in object creation if(WPR_handle<0) { Print("The creation of iWPR has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array WPR[] with current values of iWPR //--- set indexation of array WPR[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(WPR_handle,0,0,100,true,WPR)) return; }
iVIDyA
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double VIDyA[]; // array for the indicator iVIDyA //---- handles for indicators int VIDyA_handle; // handle of the indicator iVIDyA //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iVIDyA VIDyA_handle=iVIDyA(NULL,0,14,21,0,PRICE_MEDIAN); //--- report if there was an error in object creation if(VIDyA_handle<0) { Print("The creation of iVIDyA has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array VIDyA[] with current values of iVIDyA //--- set indexation of array VIDyA[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(VIDyA_handle,0,0,100,true,VIDyA)) return; }
iVolumes
#include <GetIndicatorBuffers.mqh> //---- arrays for indicators double Volumes[]; // array for the indicator iVolumes //---- handles for indicators int Volumes_handle; // handle of the indicator iVolumes //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- creation of the indicator iVolumes Volumes_handle=iVolumes(NULL,0,VOLUME_TICK); //--- report if there was an error in object creation if(Volumes_handle<0) { Print("The creation of iVolumes has failed: Runtime error =",GetLastError()); //--- forced program termination return(-1); } return(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- filling an array Volumes[] with current values of iVolumes //--- set indexation of array Volumes[] as timeseries //--- return if there was an error if(!CopyBufferAsSeries(Volumes_handle,0,0,100,true,Volumes)) return; }
결론
- MQL5의 Expert Advisors에서 표준 기술 지표를 사용하는 것은 이전 버전에서처럼 쉽습니다.
- Expert Advisors에서는 안전한 프로그래밍 방법만 사용하십시오. 가능한 모든 오류를 분석하고 제외하십시오. 실수의 대가가 너무 큽니다. 당신의 보증금이잖아요!
MetaQuotes 소프트웨어 사를 통해 러시아어가 번역됨.
원본 기고글: https://www.mql5.com/ru/articles/31



