インジケーターに関する雑多な質問 - ページ 15

 

OnCalculate

OnCalculate()関数は、Calculate イベントによってインジケータ値を計算する必要がある場合にのみ、カスタムインジケータで呼び出されます。

これは通常、インジケータが計算されるシンボルに対して新しいティックが受信されたときに発生します。

このインジケータは、このシンボルのどの価格チャートにも添付する必要はありません。

OnCalculate()関数の戻り値はint型でなければなりません。 2つの定義が可能です。1つのインジケータ内で、この関数の両方のバージョンを使用することはできません。

最初の形式は、単一のデータ・バッファで計算できるインジケータを対象としています。このようなインジケータの例として、カスタム移動平均があります。

intOnCalculate(constint rates_total,// price[] 配列の大き さ)
constint prev_calculated,// 前の呼び出しで処理されたバー
constint begin,// 重要なデータの開始位置
constdouble& price[]// 計算する配列
);

 
Marco vd Heijden:

OnCalculate

OnCalculate()関数は、Calculate イベントによってインジケータ値を計算する必要がある場合にのみ、カスタムインジケータで呼び出されます。

これは通常、インジケータが計算されるシンボルに対して新しいティックが受信されたときに発生します。

このインジケータは、このシンボルのどの価格チャートにも添付する必要はありません。

OnCalculate()関数の戻り値はint型でなければなりません。 2つの定義が可能です。1つのインジケータ内で、この関数の両方のバージョンを使用することはできません。

最初の形式は、単一のデータ・バッファで計算できるインジケータを対象としています。このようなインジケータの例として、カスタム移動平均があります。

intOnCalculate(constint rates_total,// price[] 配列の大き さ)
constint prev_calculated,// 前の呼び出しで処理されたバー
constint begin,// 重要なデータの開始位置
constdouble& price[]// 計算する配列
);

完璧です、Marcoさん、本当にありがとうございました。
 

("Lag "という言葉を使いますが、これは価格変動、注文の開始、終了の遅れを意味し、たった一言で私の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

Q: このような場合、どうしたらよいでしょうか?

よろしくお願いします。

 
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:
それをテストして 後ろにずらすということはしないんですね。

OK!ありがとう!
 

もっと明確な回答が必要です。

ありがとうございました。

 

回答は: 現在の MAクロスと前回の MAクロスの両方をチェック します。

#バッファ (array out of range in ) - Closed
#カスタムインジケーターが遅延している - 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

よろしくお願いします。

理由: