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

 
Andrei Gerasimenko:

mql4を使って、このようなアルゴリズムを実装してみたいという思いが強いです。

異なるブローカーによる2つのMT4端末があります。そのうちの1つには「排他的」インジケータがあり、(「マーケット」のように)他の端末に移動することはできません。

それがどうした!?専用」インジケーターバッファの読み取り値を、自分の端末のインジケーターに実装することは可能でしょうか?

リソースがどうにもこうにも動かない。

選択肢その1=ミハイロクに口座を開く(でよかったのか?)

選択肢その2=インジケーターの データをファイルに保存するインジケーターを書いて 保存し、このファイルを別の端末の別のインジケーターで読み込んでラインを作成する。

 

助けてください - RSIから変換したインジケータ-を軽くしようとしているのですが、なぜインジケータの値が違うのか理解できないのですが?

//+------------------------------------------------------------------+
//|                                                       SVA_02.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;
        }

      Pos=positive;
      Neg=negative;
      i--;
     }
   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {

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


и

//+------------------------------------------------------------------+
//|                                                       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=positive;
      y=negative;
      Pos=positive;
      Neg=negative;
      if(x>0)sma=Close[i+1]+x;
      else sma=Close[i+1]-y;
      MABuffer[i]=sma;

      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
ファイル:
SVA_02.mq4  4 kb
SVA_03.mq4  4 kb
 
-Aleks-:

助けてください - RSIからの変換 - インジケータを軽くしようとしているのですが、なぜインジケータの値が違うのか理解できません?

...

и

...

ただ、何をしようとして、何を間違えたのか、最終的に何を手に入れたかったのかが、まったくわからないのです。
 
-Aleks-:

助けてください - RSIから変換したインジケータ-を軽くしようとしているのですが、なぜインジケータの値が違うのか理解できないのですが?

03では、バーに対してプラスとマイナスを計算し、すぐに平均を計算するために使用しました。02別周期での平均値の計算では、プラスとマイナスで何?何かがあるのだが、計算中のバーにはない。
 
Artyom Trishkin:
ただ、何をしようとして、何を間違えて、最終的に何を手に入れたかったのかが、まったくわからないんです。

当初は、RSIの計算時に理論上不要なバッファを削除しようとしていました。

   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--;
     }

PosBuffer[i]とNegBuffer[i]は実際には過去のプラスとマイナスの値で、1本より深いバーは使用されず、メモリを消費 するようになったのです。

   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;
        }

      Pos=positive;
      Neg=negative;
      i--;
     }

さらに、私のインジケータ(コードの問題のある部分を提供)の部分をトリミングし、同一のループでさらにSVA_02を計算する。

   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {

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

そして、ループが同じなので、最初のループに計算を入れればいいのではと思い、SVA_03を 取得しました。

   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=positive;
      y=negative;
      Pos=positive;
      Neg=negative;
      if(x>0)sma=Close[i+1]+x;
      else sma=Close[i+1]-y;
      MABuffer[i]=sma;

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

ここで最後のステップですが、MABuffer[i]の結果がSVA_02とSVA_03で異なることが判明しました。何がエラーなのか論理的に 理解できません。

 
Dmitry Fedoseev:
03では、バーに対してプラスとマイナスを計算し、すぐに平均値を算出するために使用した。02では、平均値の計算は、プラスとマイナスで、別々のサイクルになっている?あるにはあるが、計算中のバーにはない。
そうなんですが、実際、何が違うのでしょうか?サイクルは同じです。論理的な間違いが何であるかを理解するためにご指導ください。
 
-Aleks-:
確かにそうですが、実際のところはどうなのでしょうか?サイクルは同じです。論理的な間違いが何であるかを理解するためにご指導ください。
何をどう説明したらいいんだ?すでにこちらで 解説しています。この説明のどこが不明確なのでしょうか?馬鹿になって、馬鹿をやるというのは、生き方なのでしょうか。その後、どのように説明すればいいのでしょうか?頭をハンマーで殴られながら?じゃあ、ヘルメットを脱げよ。
 
Dmitry Fedoseev:
何をどう説明したらいいんだ?それはすでにここで 説明したとおりです。この説明のどこが不明確なのでしょうか?バカになってバカをやるのが生き方なのか?この後、どう説明するんだ?頭をハンマーで殴られながら?じゃあ、ヘルメットを脱げよ。
なぜなら、「あるにはあるが、数えられているバーのためではない」というフレーズがあるからです。" は奇妙に聞こえますが、ループは最後のループから正と負の 値を持っているからです。
 
-Aleks-:
そう、「何かはあるが、数えられているバーにはない」というフレーズがあるからです。" は、前回のサイクルからプラスとマイナスの 値を持っているので、変に聞こえます。
ある最後のバーの最後のサイクルから、何かがそこに残っていますが、すべてのバーに対してそれを適用するのです。正しい変形では、変数には何も残りませんが、各バーで計算され、すぐに平均を計算するために使用されます。
 
Dmitry Fedoseev:
ある最後の小節のための最後のサイクルから、何かが残っていて、それを各小節に適用するのです。正しい方法では、変数には何も残りませんが、各バーについて計算され、すぐに平均を計算するために使用されます。

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