MQL4、MQL5に関する初心者からの質問、アルゴリズムやコードに関するヘルプ、ディスカッションなど。 - ページ 9

 
-Aleks-:

意味を理解しようとしている。つまり、あなたの考えでは、正しい選択肢はSVA_03 なのですね?

はい、そうですね。しかし、_02は間違いなく間違っている。
 
Dmitry Fedoseev:
ええ、そうですね。しかし、_02は間違いなく間違っている。

うーん...自分の中で1つミスを発見、これでほとんど矛盾がなくなりました、以下は原文です。

//+------------------------------------------------------------------+
//|                                                       SVA_04.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property strict

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow

//---- input parameters
extern int RSIPeriod=14;
extern int Levl=50;
extern int TF=0;
//---- buffers
double MABuffer[];
double PosBuffer[];
double NegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
   IndicatorBuffers(1);
   SetIndexBuffer(0,MABuffer);
   SetIndexBuffer(1,PosBuffer);
   SetIndexBuffer(2,NegBuffer);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
//----
//---- name for DataWindow and indicator subwindow label
//   short_name="RSI("+IntegerToString(RSIPeriod)+")";
   short_name="RSI("+RSIPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
   SetIndexLabel(1,"U");
   SetIndexLabel(2,"D");
   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive,sma,x,y,Pos,Neg;
//----
   if(Bars<=RSIPeriod) return(0);
   if(TF!=0)
     {
      string name=WindowExpertName();
      for(i=0; i<Bars-counted_bars+1; i++)
        {
         int barIndex=iBarShift(NULL,TF,Time[i],false);
         MABuffer[i]=iCustom(Symbol(),TF,name,RSIPeriod,Levl,0,0,barIndex);
        }
      return(0);
     }

   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double sumn=0.0,sump=0.0;
      if(i==Bars-RSIPeriod-1)
        {
         int k=Bars-2;
         //---- initial accumulation
         while(k>=i)
           {
            rel=Close[k]-Close[k+1];
            if(rel>0) sump+=rel;
            else      sumn-=rel;
            k--;
           }
         positive=sump/RSIPeriod;
         negative=sumn/RSIPeriod;
        }
      else
        {
         //---- smoothed moving average
         rel=Close[i]-Close[i+1];
         if(rel>0) sump=rel;
         else      sumn=-rel;
         positive=(PosBuffer[i+1]*(RSIPeriod-1)+sump)/RSIPeriod;
         negative=(NegBuffer[i+1]*(RSIPeriod-1)+sumn)/RSIPeriod;
        }
      PosBuffer[i]=positive;
      NegBuffer[i]=negative;
      i--;
     }
   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {

      x=PosBuffer[i+1];
      y=NegBuffer[i+1];
      if(x>0)sma=Close[i+1]+x;
      else sma=Close[i+1]-y;
      MABuffer[i]=sma;
      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

以下は、SVA_03の修正版です。

//+------------------------------------------------------------------+
//|                                                       SVA_03.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property strict

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow

//---- input parameters
extern int RSIPeriod=14;
extern int Levl=50;
extern int TF=0;
//---- buffers
double MABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
   IndicatorBuffers(1);
   SetIndexBuffer(0,MABuffer);

//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
//----
//---- name for DataWindow and indicator subwindow label
//   short_name="RSI("+IntegerToString(RSIPeriod)+")";
   short_name="RSI("+RSIPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);

   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive,sma,x,y,Pos,Neg;
//----
   if(Bars<=RSIPeriod) return(0);
   if(TF!=0)
     {
      string name=WindowExpertName();
      for(i=0; i<Bars-counted_bars+1; i++)
        {
         int barIndex=iBarShift(NULL,TF,Time[i],false);
         MABuffer[i]=iCustom(Symbol(),TF,name,RSIPeriod,Levl,0,0,barIndex);
        }
      return(0);
     }

   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double sumn=0.0,sump=0.0;
      if(i==Bars-RSIPeriod-1)
        {
         int k=Bars-2;
         //---- initial accumulation
         while(k>=i)
           {
            rel=Close[k]-Close[k+1];
            if(rel>0) sump+=rel;
            else      sumn-=rel;
            k--;
           }
         positive=sump/RSIPeriod;
         negative=sumn/RSIPeriod;
        }
      else
        {
         //---- smoothed moving average
         rel=Close[i]-Close[i+1];
         if(rel>0) sump=rel;
         else      sumn=-rel;
         positive=(Pos*(RSIPeriod-1)+sump)/RSIPeriod;
         negative=(Neg*(RSIPeriod-1)+sumn)/RSIPeriod;
        }

      x=Pos;
      y=Neg;
      Pos=positive;
      Neg=negative;
      if(x>0)sma=Close[i+1]+x;
      else sma=Close[i+1]-y;
      MABuffer[i]=sma;

      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

其れと

      x=positive;;
      y=negative;

に。

      x=Pos;
      y=Neg;
歴史は合うが、バーゼロで問題 - 矛盾がある、どうやって買い取るのか?
ファイル:
SVA_03.mq4  3 kb
SVA_04.mq4  4 kb
 
間違って投稿された間違ったファイル - 上記を変更...
 
-Aleks-:
История сходится, но проблемы на нулевом баре - имеется расхождение, как их купировать?
確かにゼロバーでの計算しすぎが原因であることは理解できるのですが、解決方法がわからないのです?
 

こんにちは。

助けて保留中の注文を 開くためのコードが必要です。そして、注文が開始されてから20分後、もしそれがクローズされていなければ、SLは50pipsに変更されます。ありがとうございました。

 

こんにちは

とても素朴な(たぶん)質問ですがよろしくお願いします。標準機能があります。

int  ArraySize(const void& array[]);

const void &」の意味と使い方を教えてください。?同じような関数を書こうとすると、単純にコンパイルエラーになる。

int test(const void& array[]) {
    return ArraySize(array);
}

コンパイルエラー:'const' - 'void' 型の不正使用

自分でコードを書くとき、「const void &」を正しく 使うにはどうしたらいいですか?まったくできないのですか?

 
mql4-2016:

こんにちは

とても素朴な(たぶん)質問ですがよろしくお願いします。標準機能があります。

int  ArraySize(const void& array[]);

const void &」の意味と使い方を教えてください。?同じような関数を書こうとすると、単純にコンパイルエラーになる。

int test(const void& array[]) {
    return ArraySize(array);
}

コンパイルエラー:'const' - 'void' 型の不正な使用

自分でコードを書くとき、「const void &」を正しく 使うにはどうしたらいいですか?それとも、まったく使えないのでしょうか?

void を、配列を格納するデータ型に置き換えます。標準機能は、テンプレートとして設計されています。

実はこのシステム関数はオーバーロードされた関数であり、そのオーバーロードの実装全体はMQL4の開発者には隠されているのです。

intArraySize(
void&array[]// チェックする配列
);

MQL4コンパイラは、実際にこの関数を呼び出すたびに、必要な実装を代入します。例えば、次のような整数型の配列の場合です。

intArraySize(
int&array[]// int 型の要素を持つ配列
);

また、ヒストリーデータ形式で相場を扱うMqlRates型の配列の場合、ArraySize()関数は以下のように表すことができます。

intArraySize(
MqlRates&array[]// MqlRates 型の値で満たされた配列
);

 
Kot:

こんにちは。

助けて保留中の注文を オープンするコードが必要です。そして、注文が開始されてから20分後、もしそれがクローズされていなければ、SLは50pipsに変更されます。ありがとうございました。

どのようなご用件でしょうか?あなたのために書く?フリーランスで お願いします。
 
Artyom Trishkin:

void を、配列を格納するデータ型に置き換えます。標準機能は、テンプレートとして設計されています。

実はこのシステム関数はオーバーロード関数で、このオーバーロードの実装全体は、MQL4のプログラム開発者には隠されています。

MQL4/MQL5では、"const void &" コンストラクトは正しく理解されましたか?- は、実はリファレンスの記号表記であり、実際には自作関数では書けない?

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

 
mql4-2016:

MQL4/MQL5では、"const void &" 構造を正しく理解していたのでしょうか?- は、実は参考書用の記号表記で、実際には自分の関数では使えないのでは?

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

いいえ。