有错误 我编译了你的代码并测试了它。
2014.05.22 22:39:43.936 自定义指标 Test Indicator 3 XAUUSD,M1: 已删除
2014.05.22 22:39:43.905 测试指标3 XAUUSD,M1:全局初始化失败
2014.05.22 22:39:43.905 测试指标3 XAUUSD,M5: uninit reason 3 //----------------------- change chart
2014.05.22 22:39:17.323 在'测试指标3.mq4'中阵列超出范围(117,32)
2014.05.22 22:39:15.591 测试指标3 XAUUSD,M5: 已初始化
2014.05.22 22:39:09.570 自定义指标Test Indicator 3 XAUUSD,M5:加载成功
你应该在指标首先启动时添加一行:prev_calculated == 0。
类似这样的内容。
int limit = -100; if( prev_calculated == 0 ) limit = 3000;// will calculate 3000 Bars else limit = rates_total-prev_calculated;
在我的电脑上也没有错误;-)
嗨,ffoorr。
你的解决方案真的很好。
实话告诉你,我昨晚雇了个人来解决这个问题。是的,他做到了,但是代码的效率很低,请看下面,因为他多加了一个for(i)。
如果你能解释一下prev_calculated ==0是什么意思,我将不胜感激。
//+------------------------------------------------------------------+ //| hf1.mq4 | //| Copyright 2013, MetaQuotes Software Corp. | //| httakeprofit://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MetaQuotes Software Corp." #property link "httakeprofit://www.mql5.com" #property version "1.00" #property strict //--- indicator settings //#property indicator_chart_window #property indicator_separate_window #property indicator_buffers 5 #property indicator_width1 2 #property indicator_width2 2 #property indicator_width3 1 #property indicator_width4 1 #property indicator_width5 1 #property indicator_color1 Yellow #property indicator_color2 Red #property indicator_color3 Red #property indicator_color4 Orange #property indicator_color5 Orange //--- input parameter input int kperiod=30; input int dperiod=9; input int slow=9; input int sample_roc_quartile=100; //--- buffers double buy[]; double sell[]; double stoploss[]; double takeprofit1[]; double takeprofit2[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit(void) //*/*/*/*/*/ { //--- indicator buffers mapping //--- 1 additional buffer used for counting. //IndicatorBuffers(6); IndicatorDigits(Digits); //--- indicator line SetIndexStyle(0,DRAW_ARROW); SetIndexBuffer(0,buy); SetIndexArrow(0,241); SetIndexStyle(1,DRAW_ARROW); SetIndexBuffer(1,sell); SetIndexArrow(1,242); SetIndexStyle(2,DRAW_ARROW); SetIndexBuffer(2,stoploss); SetIndexStyle(3,DRAW_ARROW); SetIndexBuffer(3,takeprofit2); SetIndexStyle(4,DRAW_ARROW); SetIndexBuffer(4,takeprofit1); //--- name for DataWindow and indicator subwindow label //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { int limit=rates_total-prev_calculated; if(limit<=0)limit =2; double roc_s[]; ArrayResize(roc_s,sample_roc_quartile+1); //--- //------------------------------------------ for(int i=1; i<limit; i++) { //FIRST PSART if(iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i)>iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i) && iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1)) { buy[i]=Close[i]; stoploss[i]=Low[i]-0.005; takeprofit1[i]=Close[i]+0.005; takeprofit2[i]=Close[i]+0.01; } if(iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i) && iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)>iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1)) { sell[i]=Close[i]; stoploss[i]=High[i]; takeprofit1[i]=Close[i]-0.0050; takeprofit2[i]=Close[i]-0.01; } } //SECOND PART //--------------------------------------- HERE IS THE WHAT HE DID int mid = (sample_roc_quartile +1)/2; for(int i=1; i<limit&&(i+1)<rates_total; i++) { //--------------------------------------------- for(int j=0;j<=sample_roc_quartile&&(i+j+1)<rates_total;j++) { roc_s[j]=Close[i+j]-Close[i+j+1]; ArraySort(roc_s); } if( (Close[i]-Close[i+1])<roc_s[mid] ) { buy[i]=0; stoploss[i]=0; takeprofit1[i]=0; takeprofit2[i]=0; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
嗨,ffoorr。
你的解决方案真的很好。
实话告诉你,我昨晚雇了个人来解决这个问题。是的,他做到了,但是代码的效率很低,请看下面,因为他多加了一个for(i)。
如果你能解释一下prev_calculated ==0是什么意思,我将不胜感激。
好吧,scfx,我不明白你的指标的第二部分,所以我不能说。
当一个指标第一次启动时,(放在图表上)previous_calculation在结构上等于零,所以可以固定指标开始计算的起始点。
if( prev_calculated == 0) limit = 100。
或
if( prev_calculated < 50) limit = 500。
或者说
if( prev_calculated < 500) limit = 3000: (都一样,不使用图表的开头)
int limit = -100; if( prev_calculated == 0 ) limit = 3000;// will calculate 3000 Bars else limit = rates_total-prev_calculated; at the first lauch of the indicator limit = 3000; for(int i=1; i<3000; i++) // draw 3000 bars at the second lauch limit = 0; // ( because rates_total-prev_calculated = 0) ; for(int i=1; i<0; i++) // draw the last bars only, faster
非常好的想法,这在......
你好。
我开始使用一个指标(第一部分)。当改变时间框架时,它运行良好。
然后我添加了第二部分,即。如果Close[i]-Close[i+1]小于过去100条差值的中位数,我将为所有缓冲区赋值0。
现在这个组合指标在一个图表中运行良好,但当我改变时间框架时,这个指标就消失了。我必须把它重新连接到图表上。
我认为这个问题是由Array引起的,但我不知道如何解决它。
谁能帮我解决这个错误?
非常感谢你。
SCFX