Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
自己写了一个指标(MACD图),通过iCustom函数调用内部数据,
在回测调试时,不断的在图中打开MACD指标.
请问该是哪里出现了错误
=========调用代码=======EA中
void OnTick()
{
zb.MACD(macdz,macdf,dif,dea,3);
========CLASS代码===========
void MACD(double &macdz[],double &macdf[],double &dif[],double &dea[],int count)
{
int macd_h=iCustom(Symbol(),PERIOD_CURRENT,"MACD_DL",12,26,9,PRICE_CLOSE);
......
}
你在 MACD 函数中用 iCustom 创建新的指标句柄,那么在 OnTick() 里执行 zb.MACD() 时当然就会有新的指标出现。
请问该如何处理
我想调用自定义指标中的四个值 在EA中使用
该如何处理
是使用新的函数
还是对MACD自定义指标 代码进行处理
指标句柄在MT5是比较特殊的存在。
定义一个全局的句柄handle,然后在OnInit()中创建,在OnTick()中调用。
指标句柄在MT5是比较特殊的存在。
定义一个全局的句柄handle,然后在OnInit()中创建,在OnTick()中调用。
不是十分了解
能不能请帮忙修改下~~做一个示范
万分感谢
//+------------------------------------------------------------------+ //| test_macd.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" int handle=-1; double macdz[]; double macdf[]; double dea[]; double dif[]; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- handle=iCustom(Symbol(),PERIOD_CURRENT,"MACD_DL",12,26,9,PRICE_CLOSE); if(handle==INVALID_HANDLE) { return(INIT_FAILED); } ArraySetAsSeries(macdz,true); ArraySetAsSeries(macdf,true); ArraySetAsSeries(dif,true); ArraySetAsSeries(dea,true); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool MACD(int count) { if(CopyBuffer(handle,0,0,count,dif)!=count)return(false); if(CopyBuffer(handle,1,0,count,dea)!=count)return(false); if(CopyBuffer(handle,2,0,count,macdz)!=count)return(false); if(CopyBuffer(handle,3,0,count,macdf)!=count)return(false); return(true); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- IndicatorRelease(handle); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- if(MACD(3)) { //--- 你的代码 } } //+------------------------------------------------------------------+
上午想了一个上午,想将MACD写进一个类里面,但是还是出了错误.
还请老师指点~~~~
错误代码为
for(int i=kaiswei;i<shuliang;i++) ExtDIFFBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
ExtFastMaBuffer[0]和ExtSlowMaBuffer[0]的数据能够获取
但是 ExtDIFFBuffer[0]不能获取 出现报错
critical error while running
array out of range
//全部代码
//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2012, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #include <MovingAverages.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class Macdzb { public: void macd(double &ExtDIFFBuffer[],double &ExtDEABuffer[],double &ExtMACDBuffer[],int kaiswei,int shuliang) { int ExtFastMaHandle; int ExtSlowMaHandle; double ExtFastMaBuffer[]; double ExtSlowMaBuffer[]; ArraySetAsSeries(ExtDIFFBuffer,true); ArraySetAsSeries(ExtDEABuffer,true); ArraySetAsSeries(ExtMACDBuffer,true); ArraySetAsSeries(ExtFastMaBuffer,true); ArraySetAsSeries(ExtSlowMaBuffer,true); ExtFastMaHandle=iMA(NULL,0,12,0,MODE_EMA,PRICE_CLOSE); ExtSlowMaHandle=iMA(NULL,0,26,0,MODE_EMA,PRICE_CLOSE); //--- get Fast EMA buffer if(CopyBuffer(ExtFastMaHandle,0,0,shuliang,ExtFastMaBuffer)<=0) { Print("Getting fast EMA is failed! Error",GetLastError()); } //--- get SlowSMA buffer if(CopyBuffer(ExtSlowMaHandle,0,0,shuliang,ExtSlowMaBuffer)<=0) { Print("Getting slow SMA is failed! Error",GetLastError()); } //dif int i=kaiswei; for(int i=kaiswei;i<shuliang;i++) ExtDIFFBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i]; //--- calculate DEA SimpleMAOnBuffer(1,0,0,9,ExtDIFFBuffer,ExtDEABuffer);//shuliang //--- calculate MACD for(int i=kaiswei;i<shuliang;i++) ExtMACDBuffer[i] = 2*(ExtDIFFBuffer[i]-ExtDEABuffer[i]); IndicatorRelease(ExtFastMaHandle); IndicatorRelease(ExtSlowMaHandle); } }; //+------------------------------------------------------------------+
自己写了一个指标(MACD图),通过iCustom函数调用内部数据,
在回测调试时,不断的在图中打开MACD指标.
请问该是哪里出现了错误
=========调用代码=======EA中
========CLASS代码===========
MACD.指标