指标杂项问题 - 页 15

 

OnCalculate

OnCalculate()函数只在自定义指标中被调用,当有必要通过计算 事件来计算指标值时。

这通常发生在收到该符号的新刻度线时,该指标被计算。

这个指标不需要附加到这个符号的任何价格图表上。

OnCalculate()函数必须有一个返回类型int。有 两种可能的定义。在一个指标中,你不能同时使用该函数的两个版本。

第一种形式是为那些可以在单个数据缓冲区上进行计算的指标准备的。这种指标的一个例子是自定义移动平均线。

intOnCalculate(constint rates_total,// size of the price[] array)
冲区int prev_calculated,// 在之前的调用中处理过的条数
constint begin,// 重要数据从哪里 开始
constdouble& price[]// 要计算的数组
);

 
Marco vd Heijden:

OnCalculate

OnCalculate()函数只在自定义指标中被调用,当有必要通过计算 事件来计算指标值时。

这通常发生在收到该符号的新刻度线时,该指标被计算。

这个指标不需要附加到这个符号的任何价格图表上。

OnCalculate()函数必须有一个返回类型int。有 两种可能的定义。在一个指标中,你不能同时使用该函数的两个版本。

第一种形式是为那些可以在单个数据缓冲区上进行计算的指标准备的。这种指标的一个例子是自定义移动平均线。

intOnCalculate(constint rates_total,// size of the price[] array)
冲区int prev_calculated,// 在之前的调用中处理过的条数
constint begin,// 重要数据从哪里 开始
constdouble& price[]// 要计算的数组
);

完美,马可先生,非常感谢。
 

(我使用 "滞后 "一词,它意味着延迟价格行动,订单打开,关闭,只是一个字就把我的MT4平台搞垮了)

我在我的自定义指标 上使用了以下函数。

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[]){...}

当我把下面的返回 代码写到我的自定义指标 时,我的自定义指标开始滞后。但工作正常,这是我想要的。

return(0); // starts to lag...

而当我把下面的返回 代码写到我的自定义指标上时,我的自定义指标就不能正常工作,这是我想要的。我的意思是,当假的 MA交叉时,"箭头 "不会返回到之前的MA交叉点。

return rates_total-1; // does not go back to previous MA cross point
return(rates_total-1); // and same thing here

问: 请问这种情况下我能做什么?

谢谢。

 
Max Enrik: 当我把下面的返回 代码写到我的自定义指标上时,我的自定义指标就不能正常工作,这是我想要的。我的意思是,当假的 MA交叉时,"箭头 "并没有回到之前的MA交叉点。
发布你所有的代码。如果没有上下文,那就毫无意义。
 
whroeder1:
发布你所有的代码。没有上下文,那是毫无意义的。

给你。

提前感谢。

指标示例图06

#property strict
#property indicator_chart_window
#property indicator_buffers 2

string arrowIcon="delete arrow icon";

int i;
double arrowLow,arrowHigh,priceOne,priceTwo,priceOne_pre,priceTwo_pre,bufferOne[],bufferTwo[];
color clrup=clrBlue,clrdown=clrRed;
datetime arrowTime;
//---------------------------------------------------------
// OnDeinit
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(0,"delete");
   return;
  }
// OnInit
int OnInit()
  {
   IndicatorDigits(Digits);
// line
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,clrdown);
   SetIndexBuffer(0,bufferOne);

   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,clrup);
   SetIndexBuffer(1,bufferTwo);
//---
   return(0);
  }
// OnCalculate
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 lookback=30; // I do not know what could I write here.
   for(i=Bars-1-MathMax(lookback,prev_calculated); i>=0; --i)
     {
      bufferOne[i]=iMA(Symbol(),0,lookback/2,0,MODE_EMA,PRICE_CLOSE,i);
      bufferTwo[i]=iMA(Symbol(),0,lookback,0,MODE_EMA,PRICE_CLOSE,i);

      priceOne = bufferOne[i];
      priceTwo = bufferTwo[i];
      priceOne_pre = bufferOne[i+5];
      priceTwo_pre = bufferTwo[i+5];

      // buy
      if(priceOne>priceTwo && priceOne_pre<=priceTwo_pre)
        {
         arrowTime=Time[i];
         //arrowLow  = iLow( Symbol(), 0, i );
         arrowLow=Low[i];

         objArrow();
         if(ObjectFind(0,arrowIcon)>=0)
           {
            ObjectMove(0,arrowIcon,0,arrowTime,arrowLow-5*Point);
            ObjectSetInteger(0,arrowIcon,OBJPROP_COLOR,clrup);
            ObjectSetInteger(0,arrowIcon,OBJPROP_ANCHOR,ANCHOR_TOP);
           }
        }
      // sell
      if(bufferOne[i]<bufferTwo[i] && priceOne_pre>=priceTwo_pre)
        {
         arrowTime = Time[i];
         arrowHigh = High[i];

         objArrow();
         if(ObjectFind(0,arrowIcon)>=0)
           {
            ObjectMove(0,arrowIcon,0,arrowTime,arrowHigh+5*Point);
            ObjectSetInteger(0,arrowIcon,OBJPROP_COLOR,clrdown);
            ObjectSetInteger(0,arrowIcon,OBJPROP_ANCHOR,ANCHOR_BOTTOM);
           }
        }
     }
   Print("Time: ",arrowTime,"  Low: ",arrowLow);
//    Print( "priceOne ", DoubleToString( priceOne, Digits ), "  priceTwo ", DoubleToString( priceTwo, Digits ) );
//---
//return(0); // works correct but cause lags
   return(rates_total - 1); // no lags but does not go to previous ma cross after fake ma cross
  }
// objects
void objArrow()
  {
   if(ObjectFind(0,arrowIcon)<0)
     {
      ObjectCreate(0,arrowIcon,OBJ_ARROW,0,arrowTime,arrowLow);
      ObjectSetInteger(0,arrowIcon,OBJPROP_ARROWCODE,159);
      ObjectSetInteger(0,arrowIcon,OBJPROP_WIDTH,2);
     }
//---
   return;
  }
//+------------------------------------------------------------------+
 
Max Enrik: 我的意思是,当假的 MA交叉时,"箭头 "并没有回到之前的MA交叉点。
你不会为此进行测试 并将其移回。
 
whroeder1:
你不会为此进行测试 并将其移回。

好的!谢谢!
 

我仍然需要更明确的答案。

请提前感谢。

 

答案是: 同时检查 当前的 MA交叉点和之前的 MA交叉点。

#Buffer (array out of range in ) - Closed
#Custom Indicator Lagging - Closed

 

# 循环的第一个结果 - 打开

string counts;
void _a()
{
    counts += "a - " + IntegerToString( ObjectsTotal( OBJ_ARROW ) );
    //---
    return;
}
void _b()
{
    counts += " - b - " + IntegerToString( ObjectsTotal( OBJ_ARROW ) );
    //---
    return;
}
Print( counts );
// while 1st loop: a - 2 - b - 4
// while 2nd loop: a - 2 - b - 4a - 2 - b - 4
// while 3rd loop: a - 2 - b - 4a - 2 - b - 4a - 2 - b - 4a - 2 - b - 4
// and so on...
// But I like only 1st loop results even that loop runs 10 thousand times

提前感谢。