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

 
新しいインジケータを見つけたので、私のEAに導入したかったのですが、問題は、すべてのローソク足で取引を開始することです。矢印信号の時だけ開くようにするにはどうしたらいいか教えてください。
//------------------------------------------------------------------
#property copyright "Hill"
#property link      "Romio.com"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Orange
#property indicator_color2 DarkGray
#property indicator_color3 Orange
#property indicator_color4 LimeGreen
#property indicator_style2 STYLE_DOT
#property indicator_style3 STYLE_DOT
#property indicator_style4 STYLE_DOT
//

//
//
//
//
//

extern int    RsiLength  = 4;
extern int    RsiPrice   = PRICE_CLOSE;
extern int    HalfLength = 5;
extern int    DevPeriod  = 100;
extern int    Sise       = 10;
extern double Deviations = 1.0;
extern bool   UseAlert   = true;
extern bool   DrawArrows = true;

color ColorDn = Crimson;
color ColorUp = DodgerBlue;
int     CodDn = 222;
int     CodUp = 221;

string   Font = "Verdana";

// ti init() if(ObjectFind("100s")<0)GetText(3,"100s","BuySell Pro",LawnGreen,5,5,7);


string PrefixArrow = "ArrowsHill";

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];

double up[];
double dn[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   HalfLength=MathMax(HalfLength,1);
   SetIndexBuffer(0,buffer1);
   SetIndexBuffer(1,buffer2);
   SetIndexBuffer(2,buffer3);
   SetIndexBuffer(3,buffer4);

   SetIndexStyle(4,DRAW_ARROW,0,2,Blue);
   SetIndexArrow(4,233);
   SetIndexBuffer(4,up);

   SetIndexStyle(5,DRAW_ARROW,0,2,Red);
   SetIndexArrow(5,234);
   SetIndexBuffer(5,dn);


   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   DellObj(PrefixArrow);

   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int i,j,k,counted_bars=IndicatorCounted();
   if(counted_bars<0)
      return(-1);
   if(counted_bars>0)
      counted_bars--;
   int limit=MathMin(Bars-1,Bars-counted_bars+HalfLength);

   static datetime timeLastAlert = NULL;

   for(i=limit; i>=0; i--)
      buffer1[i] = iRSI(NULL,0,RsiLength,RsiPrice,i);
   for(i=limit; i>=0; i--)
     {
      double dev  = iStdDevOnArray(buffer1,0,DevPeriod,0,MODE_SMA,i);
      double sum  = (HalfLength+1)*buffer1[i];
      double sumw = (HalfLength+1);
      for(j=1, k=HalfLength; j<=HalfLength; j++, k--)
        {
         sum  += k*buffer1[i+j];
         sumw += k;
         if(j<=i)
           {
            sum  += k*buffer1[i-j];
            sumw += k;
           }
        }
      buffer2[i] = sum/sumw;
      buffer3[i] = buffer2[i]+dev*Deviations;
      buffer4[i] = buffer2[i]-dev*Deviations;

      if(buffer1[i] >= buffer3[i] /*&& buffer1[i+1] < buffer3[i+1]*/)
        {
         dn[i] = buffer3[i];
         if(DrawArrows)
            ArrowDn(Time[i], High[i]);

         if(UseAlert && i == 0 && Time[0] != timeLastAlert)
           {
            Alert("Signal DOWN!");
            timeLastAlert = Time[0];
           }
        }

      if(buffer1[i] <= buffer4[i] /*&& buffer1[i+1] > buffer4[i+1] */)
        {
         up[i] = buffer4[i];
         if(DrawArrows)
            ArrowUp(Time[i], Low[i]);

         if(UseAlert && i == 0 && Time[0] != timeLastAlert)
           {
            Alert("Signal UP!");
            timeLastAlert = Time[0];
           }
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ArrowUp(datetime tim,double pr)
  {
   if(ObjectFind(PrefixArrow+"TextUp"+tim)==-1)
     {
      if(ObjectCreate(PrefixArrow+"TextUp"+tim,OBJ_TEXT,0,tim,pr-GetDistSdvig()))
         ObjectSetText(PrefixArrow+"TextUp"+tim,CharToStr(CodUp),Sise,"WingDings",ColorUp);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ArrowDn(datetime tim,double pr)
  {
   if(ObjectFind(PrefixArrow+"TextDn"+tim)==-1)
     {
      if(ObjectCreate(PrefixArrow+"TextDn"+tim,OBJ_TEXT,0,tim,pr+GetDistSdvig()))
         ObjectSetText(PrefixArrow+"TextDn"+tim,CharToStr(CodDn),Sise,"WingDings",ColorDn);
     }
  }
extern double TextSdvigMnoj = 2;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetDistSdvig()
  {
   return(iATR(NULL, 0, 100, 1) * TextSdvigMnoj);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DellObj(string dell)
  {
   string name;
   for(int i = ObjectsTotal()-1 ; i >=0 ; i--)
     {
      name = ObjectName(i);
      if(StringFind(name, dell) != EMPTY)
         ObjectDelete(name);
     }
  }
//+------------------------------------------------------------------+
ファイル:
 
jarikn:
新しいインジケータを見つけたので、EAに載せようと思ったのですが、問題は、すべてのローソク足で取引を開始してしまうことです。矢印の信号の時だけ開くようにするにはどうしたらいいか教えてください

まず、このインジケーターは全く新しいものではなく、非常に古い ものです。4でもインターフェースが古いくらい

2つ目は、再描画です。Exact at HalfLength (デフォルトは5小節、パラメータで設定)

最後に - Expert Advisor の取引開始方法は、EA の 90% に依存します、つまり、EA のコードなしには、すべてが役に立ちません。

 
Maxim Kuznetsov:

まず、このインジケーターは全く新しいものではなく、非常に古い ものです。4でもインターフェースが古いくらい

2つ目は、再描画です。Exact at HalfLength (デフォルトは5小節、パラメータで設定)

そして最後に、Expert Advisorのトレードを開く方法は、EAに90%依存します。つまり、EAのコードがなければ、すべては役に立ちません。

OK、了解です。例えば、期間の異なる2つの指標を用意し、「1つのローソク足で1つの指標が上向き矢印、2つの指標が上向き矢印を示したら、アラートとチャート上の矢印を表示する」という条件を記述すると、次のようになります。どうすれば実現できるのか、ご存じですか?バッファを追加する必要があるのか、それとも両方のシグナルをフォローするインジケータを作成 することができるのか?そして、あなたがハードでない場合は、それを行う方法を例示する。

 
jarikn:

OK、了解です。例えば、期間の異なる2つの指標を取り上げ、「1つのローソク足で1つの指標が上向き矢印、2つの指標が上向き矢印を示したら、アラートとチャート上の矢印を表示する」という条件を記述すると、次のようになります。どうすれば実現できるのか、ご存じですか?バッファを追加する必要があるのか、それとも両方のシグナルをフォローするインジケータを作成 することができるのか?そして、あなたがハードでない場合は、それを行う方法を例示する。

Expert Advisorに期間の異なる2つのiCustomを追加すれば、(たぶん)幸せになれるでしょう。
 
MakarFX:
EAに期間の異なる2つのiCustomを追加すれば、(たぶん)幸せになれるでしょう。

OK、試してみます、ありがとうございました。

 

また、こんにちは )))どなたか、指標となるものを教えてください。

<*.ex* ファイルを削除しました

 

通過したポイントの数でZigZagのようなインジケータを書こうとしています。

自分で書くには知識が足りないので、誰かのインジケータを書き換えることにしました。

これが、今回出てきたものです。

#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_SECTION
#property indicator_color1  clrCrimson
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      Points=50;
//--- indicator buffers
int Trend=1,InTrend;
datetime ttime;
double Last_High,Last_Low;
double Buffer01[],Buffer02[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorBuffers(2);
   IndicatorDigits(Digits);
//--- indicator buffers mapping
   SetIndexBuffer(0,Buffer01);
   SetIndexBuffer(1,Buffer02);
   SetIndexEmptyValue(0,0);
//---
   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-2;
   if(limit<2) return(0);
   for(int i=limit; i>=0;i--)
     {
      if(time[i]!=ttime) {InTrend=InTrend+1; ttime=time[i];}
      Buffer01[i]=0;
      Buffer02[i]= open[i]; 
      if(Buffer02[i+1]>Last_High && Trend==1)   InTrend=1;
      if(Buffer02[i+1]<Last_Low  && Trend==0)   InTrend=1;
      if(Buffer02[i+1]>Last_High) Last_High=Buffer02[i+1];
      if(Buffer02[i+1]<Last_Low ) Last_Low =Buffer02[i+1];
      //----
      if(Trend==1 && Buffer02[i+1]<Last_High-Points*Point && InTrend>1)
        {
         Trend=0;
         if(i+InTrend<ArraySize(Buffer01))
         Buffer01[i+InTrend]=Buffer02[i+InTrend];
         Last_High=Buffer02[i+1];
         Last_Low=Buffer02[i+1];
         InTrend=1;
        }
      if(Trend==0 && Buffer02[i+1]>Last_Low+Points*Point && InTrend>1)
        {
         Trend=1;
         if(i+InTrend<ArraySize(Buffer01))
         Buffer01[i+InTrend]=Buffer02[i+InTrend];
         Last_Low=Buffer02[i+1];
         Last_High=Buffer02[i+1];
         InTrend=1;
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

正しく描画されているように見えますが、ラグがあります。

価格が50ポイントを超えたが、インジケータが描画されない。

この問題を解決するためにご協力をお願いします。

 
MakarFX:

問題解決にご協力ください。

mt5用ポイント・バイ・ポイントZZはこちら

https://www.mql5.com/ru/forum/318267#comment_12508440


は、メインの計算サイクルの番号付けを変更すれば、MT4でも動作するはずです。

 
Igor Makanu:

ZZが投稿したmt5用のポイントはこちらです。

https://www.mql5.com/ru/forum/318267#comment_12508440


MT4では、主な計算サイクルの番号を変更すれば動作するはずです。

Igorさん、ありがとうございます。しかし、MT4は正しく動作しません。


何が正しくなければならないのか、教えてください。

 
そんな問題に遭遇したことがあります。問題は、新しいローソク足ごとに取引を開始し、上向きにしか取引しないことです。何が問題なのか、誰にもわからない。
ファイル:
Screenshot_8.png  121 kb
123.mq4  5 kb