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

 
inter78:

実は、そうなんですが、レスポンスが長いのが嫌なんです

長いというか、カチカチというか...でも、一般的にはヘルプを読む必要があります。MQLは「勘」では覚えられません。 MQLはC++がベースですが、MTプラットフォームに紐づいているので、ヘルプを勉強する必要があるんです。

ファイル操作やグローバル変数 やグラフィックをコードで扱うと ...ティックごとに不要な操作が多い

高速なレスポンスを求めるなら、OnChartEvent()を使いましょう。テスターでは生成されませんが、まずはMQL4のヘルプから勉強してみてください。

 
Igor Makanu:

操作は長くはないです、tick by tickですが・・・一般的にはヘルプを読むことから始めましょう、MQLは「勘」では覚えられません、MQLはC++がベースですが、MTプラットフォームと結びついています、ヘルプを読まないと出来ませんよ。

ファイル操作やグローバル変数 やグラフィックをコードで扱うと ...ティックごとに不要な操作が多い

高速に実行したい場合は、OnChartEvent()を使用します。テスターでは生成されませんが、まずはMQL4のヘルプを勉強し始めましょう。

おそらく、技術者にお願いして、正気に戻してもらうことになると思います。できなくなる。このインジケータは、オープンチャートの数が無制限で作業するのに非常に便利です。ボタンには、シンボルの現在の利益と、売買注文の数が表示されます。
 

皆さん、こんにちは。

コードライブラリの中に便利なInd-Fractalsのインジケータを発見。しかし、それは適切に計算する代わりに、すべてのバーでフラクタルが描画されます。このインジケータを使いたいのですが、「壊れている」のです(( エラーを見つけるのを手伝ってください。作者に連絡しようとしましたが、彼はメッセージに応答しません。便宜上、ここにコードを複製しています。

#property copyright "著作権 © 2005, MetaQuotes Software Corp.

#プロパティリンク "http://www.metaquotes.net"

//----

#property indicator_chart_window

#プロパティ indicator_buffers 8

#property indicator_color1 レッド

#property indicator_color2 レッド

#property indicator_color3 ブルー

#property indicator_color4 ブルー

#プロパティ indicator_color5 Lime

#プロパティ indicator_color6 Lime

#プロパティ indicator_color7 Sienna

#プロパティ indicator_color8 Sienna

//---- 入力パラメータ

extern bool Comm=true;

//---- バッファ

double ExtMapBuffer1[]。

double ExtMapBuffer2[]。

double ExtMapBuffer3[]。

double ExtMapBuffer4[]。

double ExtMapBuffer5[]。

double ExtMapBuffer6[]です。

double ExtMapBuffer7[]です。

double ExtMapBuffer8[]。

//+------------------------------------------------------------------+

//| カスタムインジケータ初期化関数

//+------------------------------------------------------------------+

int init()

{

//---- インジケータ

SetIndexStyle(0,DRAW_ARROW);//インジケーターのラインスタイル

SetIndexArrow(0,217); //矢印の種類を指定する。

SetIndexBuffer(0,ExtMapBuffer1);//index バッファを double 型の一次元動的配列で束縛します.機能には2つのバージョンがあります。

SetIndexEmptyValue(0,0.0);// インジケータラインの空値を設定します。

SetIndexStyle(1,DRAW_ARROW)を設定します。

SetIndexArrow(1,218)を設定します。

SetIndexBuffer(1,ExtMapBuffer2)を設定。

SetIndexEmptyValue(1,0.0);

SetIndexStyle(2,DRAW_ARROW)を設定します。

SetIndexArrow(2,217)。

SetIndexBuffer(2,ExtMapBuffer3)を設定。

SetIndexEmptyValue(2,0.0);

SetIndexStyle(3,DRAW_ARROW)を設定します。

SetIndexArrow(3,218)を設定します。

SetIndexBuffer(3,ExtMapBuffer4)を設定します。

SetIndexEmptyValue(3,0.0);

SetIndexStyle(4,DRAW_ARROW)を設定します。

SetIndexArrow(4,217)。

SetIndexBuffer(4,ExtMapBuffer5)を設定。

SetIndexEmptyValue(4,0.0);

SetIndexStyle(5,DRAW_ARROW)を設定します。

SetIndexArrow(5,218)。

SetIndexBuffer(5,ExtMapBuffer6)を設定。

SetIndexEmptyValue(5,0.0);

SetIndexStyle(6,DRAW_ARROW)を設定します。

SetIndexArrow(6,217)。

SetIndexBuffer(6,ExtMapBuffer7)を設定。

SetIndexEmptyValue(6,0.0);

SetIndexStyle(7,DRAW_ARROW)を設定します。

SetIndexArrow(7,218)を設定します。

SetIndexBuffer(7,ExtMapBuffer8)を設定。

SetIndexEmptyValue(7,0.0);

return(0); }

//+------------------------------------------------------------------+

//| カストマーインジケーター初期化機能

//+------------------------------------------------------------------+

int deinit() {return(0); }.

//------------------------------------------------------------------

bool Fractal(文字列F,int Per,int シフト) { .

if(Period()>Per) return(-1);

Per=Per/Period()*2+MathCeil(Per/Period()/2);

if(shift<Per)return(-1)。

if(shift>Bars-Per)return(-1)。

for(int i=1;i<=Per;i++){.

if(shift+i>=Bars || shift-i<0) return(-1);

if(F=="U"){。

if(High[shift+i]>High[shift])return(-1)。

if(High[shift-i]>=High[shift])return(-1); }.

if(F=="L"){。

if(Low[shift+i]<Low[shift])return(-1)。

if(Low[shift-i]<=Low[shift])return(-1);} }。

return(1); }.

//------------------------------------------------------------------

int start()

{

int D1=1440,H4=240,H1=60,M15=15,B;

ダブルP

int counted_bars=IndicatorCounted();// 最後にインジケータをコールした後、変更されていないバーの本数

B=Bars-counted_bars;

if(counted_bars==0) B--;

if(Period()==D1)P=150*Point;// periodは現在のチャートの期間を返します。

if(Period()==H4)P=70*Point。

if(Period()==H1)P=40*Point。

if(Period()==30)P=30*Point;

if(Period()==M15)P=20*Point。

if(Period()==5)P=10*Point。

if(Period()==1)P=5*Point。

for(int shift=B;shift>0;shift--)

{

if(Fractal("U",M15,shift)==1) ExtMapBuffer1[shift]=High[shift]+P.Fractal("U",M15,shift)==1) ExtMapBuffer1[shift]=High[shift]+P;

else ExtMapBuffer1[shift]=0;

if(Fractal("L",M15,shift)==1) ExtMapBuffer2[shift]=Low[shift]-P;

else ExtMapBuffer2[shift]=0;

if(Fractal("U",H1,shift)==1) ExtMapBuffer3[shift]=High[shift]+P.Fractal("U",H1,shift)==1) ExtMapBuffer3[shift]=High[shift]+P;

else ExtMapBuffer3[shift]=0;

if(Fractal("L",H1,shift)==1) ExtMapBuffer4[shift]=Low[shift]-P;

else ExtMapBuffer4[shift]=0;

if(Fractal("U",H4,shift)==1) ExtMapBuffer5[shift]=High[shift]+P.Fractal("U",H4,shift)==1) ExtMapBuffer5[shift]=High[shift]+P;

else ExtMapBuffer5[shift]=0;

if(Fractal("L",H4,shift)==1) ExtMapBuffer6[shift]=Low[shift]-P;

else ExtMapBuffer6[shift]=0;

if(Fractal("U",D1,shift)==1) ExtMapBuffer7[shift]=High[shift]+P.Fractal("U",D1,shift)==1) ExtMapBuffer7[shift]=High[shift]+P;

else ExtMapBuffer7[shift]=0;

if(Fractal("L",D1,shift)==1) ExtMapBuffer8[shift]=Low[shift]-P;

else ExtMapBuffer8[shift]=0;

}

if(Comm) Comment("D1 - brown ⇄ H4 - green ⇄ H1 - blue ⇄ M15 - red ");


return(0)です。

}

MetaQuotes Software Corp.
MetaQuotes Software Corp.
  • www.metaquotes.net
Миллионы трейдеров и сотни брокеров не могут ошибаться — они выбрали MetaTrader 5 для торговли на Форексе и финансовых рынках! Узнать больше
 

この手のコードでここで叱られたのは初めてです :-)

Alt+Sで開くフォームにコードを挿入 する必要があります。

 
psyman:

この手のコードでここで叱られたのは初めてです :-)

Alt+Sで開くフォームにコードを貼り 付ける必要があります。

叱られることはないですか?一切ありません。好きなようにコードを書いてください。でも...自分の質問に答えたいのなら、助けを求めている人を尊重するようにしましょう。というくらいにシンプルです。

 

トレーディング、自動売買システム、ストラテジーテストに関するフォーラム

MQL4初心者のための質問、アルゴリズムやコードに関するヘルプとディスカッション

アルチョム・トリシキン さん 2018.10.18 08:07

言ってみれば、エディターでインジケーターのテンプレートを作り、作成時に入力変数と描画バッファを適切な数だけ追加するのです。

次に、具体的なタスクから何をすべきかを分析しよう。

前回は変数名と配列名を変えただけでしたね。

iMAを使用する場合、それはろうそくが100ポイント以上を含む週とdairesにのみ動作し、それは低い時間枠で何もしません。理由は四捨五入にあるようです。




iMAOnArrayを使用した場合、i-rasウィンドウはすべてのTFで空となります。ログにエラーはありません。




//+------------------------------------------------------------------+
//|                                                        _null.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot OC
#property indicator_label1  "O-C"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrSteelBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         ip1Buf[];

input int ip1=100;
double tmp1[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  
IndicatorBuffers(2);
string s_name1;

s_name1="O-C (" + IntegerToString(ip1) + ")";

IndicatorShortName(s_name1);
SetIndexLabel(0, s_name1);
SetIndexBuffer(1, tmp1);


//--- indicator buffers mapping
   SetIndexBuffer(0,ip1Buf);
   
//---
   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 i;

      Print("rates_total = ",rates_total);
      for(i=1; i<rates_total-1; i++)
      {
      //Print("i = ",i);
      tmp1[i]=MathMax(open[i],close[i])-MathMin(open[i],close[i]);      
     // tmp1[i]=close[i];      
      //ip1Buf[i]=iMA(NULL,0,1,0,0,tmp1[i],0);
      ip1Buf[i]=iMAOnArray(tmp1,1,1,0,0,0);
      
      }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


 
psyman:

iMAOnArrayを使用した場合、i-raウィンドウはすべてのTFで空となる。ログにエラーはありません。

iMAOnArray()をピリオド1で使用しているため、iMAOnArray()の値は実質的に配列tmp1の値となります。

何を計算しているのかを明らかにしたいのであれば、ループを短くするfor(i=1; i<10; i++)

で、計算したいデータをすべてアンプリントする。複雑な計算式はしないほうが楽かもしれないが、iMAOnArray()でiMAとiMAOnArray()を構築する - iMAもiMAOnArray()も同じ計算である...ということだ。alasさん、この掲示板で技術的な質問に対する回答が得られたら、あなた一人で情報を計算して対処する術を身につけるべきです。

 
psyman:

前回は、変数と配列の名前だけを変更しました。

iMA i-rを使用する場合、100pips以上のローソク足がある週や日にのみ動作し、下位TFでは何も描画されません。理由は四捨五入にあるようです。




iMAOnArrayを使用した場合、i-rasウィンドウはすべてのTFで空となります。ログにエラーはありません。





第1サイクルでは、第1バッファの値を計算する。

2サイクル目は、1サイクル目で算出した値でMAを算出する。

iMAOnArray()が何を意味するのかを考えてみましょう。ArrayにMAを書き込む。どのように訳すのですか?誰もがGoogle翻訳機を手にしている。プット・トランスレート・レシーブMAオンアレイ。

あらかじめ計算され、満たされた配列に基づく移動平均であることを意味します。

第1サイクル:必要な配列の作成、第2サイクル:第1サイクルで作成された配列に基づく移動平均の作成に対応。

で、どうするんだ?最初の配列に値を入力し(他の値はまだ用意されていない)、この値でMAを構築しようとするのです。

テンプレートをお渡ししました。

トレーディング、自動売買システム、ストラテジーテストに関するフォーラム

MQL4初心者の質問、ヘルプ、アルゴリズムやコードに関するディスカッションなど何でもOK

アルチョム・トリシキン さん 2018.10.18 09:39

指標となる。

//+------------------------------------------------------------------+
//|                                                       TestMA.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                             https://mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://mql5.com/ru/users/artmedia70"
#property version   "1.00"
#property indicator_chart_window
#ifdef __MQL4__
#property strict
#property indicator_buffers 2
#else 
#property indicator_buffers 3
#property indicator_plots   2
#endif 
//--- plot MAstd
#property indicator_label1  "Calculation MA"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  4
//--- plot MAcalc
#property indicator_label2  "Standart MA"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrDarkOrange
#property indicator_style2  STYLE_DOT
#property indicator_width2  2
//--- input parameters
input int      InpPeriod                     =  10;            // Period
input ENUM_MA_METHOD       InpMethod         =  MODE_EMA;      // Method
input ENUM_APPLIED_PRICE   InpAppliedPrice   =  PRICE_CLOSE;   // Applied price  
//--- indicator buffers
double         BufferMAcalc[];
double         BufferMAstd[];
double         BufferPrice[];
//---
int            digits;
int            period_ma;
int            handle_ma;
CAvg           avg();
//--- includes

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
#ifdef __MQL4__
   IndicatorBuffers(3);
#endif 
    period_ma=(InpPeriod<1? 1 : InpPeriod);
   digits=Digits()+1;
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferMAcalc,INDICATOR_DATA);
   SetIndexBuffer(1,BufferMAstd,INDICATOR_DATA);
   SetIndexBuffer(2,BufferPrice,INDICATOR_CALCULATIONS);
//---
   ArraySetAsSeries(BufferMAcalc,true);
   ArraySetAsSeries(BufferMAstd,true);
   ArraySetAsSeries(BufferPrice,true);
//---
#ifdef __MQL5__
   ResetLastError();
   handle_ma=iMA(NULL,PERIOD_CURRENT,period_ma,0,InpMethod,InpAppliedPrice);
   if(handle_ma==INVALID_HANDLE)
     {
      Print("Error creation iMA(",(string)period_ma,"): ",GetLastError());
      return INIT_FAILED;
     }
#endif 
//---
   Comment("\nMA type: ",avg.MethodToString(InpMethod),", price: ",avg.PriceToString(InpAppliedPrice),", period: ",(string)period_ma);
//---
   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[])
  {
//--- Установка массивов буферов как таймсерий
#ifdef __MQL5__
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
#endif 
//--- Проверка количества доступных баров
   if(rates_total<fmax(period_ma,4)) return 0;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-1;
      ArrayInitialize(BufferMAcalc,EMPTY_VALUE);
      ArrayInitialize(BufferMAstd,EMPTY_VALUE);
      ArrayInitialize(BufferPrice,0);
     }
//--- Подготовка данных
#ifdef __MQL5__
   int count=(limit>1 ? rates_total : 1),copied=0;
   copied=CopyBuffer(handle_ma,0,0,count,BufferMAstd);
   if(copied!=count) return 0;
#endif 
//--- Расчёт индикатора
   for(int i=limit; i>=0 && !IsStopped(); i--)
     {
      #ifdef __MQL4__ BufferMAstd[i]=iMA(NULL,PERIOD_CURRENT,period_ma,0,InpMethod,InpAppliedPrice,i); #endif 
       BufferPrice[i]=avg.AppliedPrice(InpAppliedPrice,NULL,PERIOD_CURRENT,i);
      BufferMAcalc[i]=avg.GetMA(rates_total,InpMethod,period_ma,i,BufferPrice);
     }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

5に関することはすべて捨てて、4に関するテンプレートを用意すればいいのです。このテンプレートはマルチプラットフォームですが、バッファとその数を設定するだけで、両方の端末で使用することができます。このテンプレートでは、2つの図面と1つの計算があり、ここで見ることができます。

//--- indicator buffers mapping
   SetIndexBuffer(0,BufferMAcalc,INDICATOR_DATA);
   SetIndexBuffer(1,BufferMAstd,INDICATOR_DATA);
   SetIndexBuffer(2,BufferPrice,INDICATOR_CALCULATIONS);
//---
 

=また、iMAOnArray()をピリオド1で使用します。つまり、iMAOnArray()の値は、実質的に配列tmp1の値と なります。


いろいろな値を試してみましたが、1がこの実験の最後のバリエーションとして残っています。

配列の値がすべて異なるtmp1[4] = 0.13000000000097などに対し、ip1Buf[4] = 2147483647.0 はなぜかすべてのTFのi-r bufferに同じ数字を書き込んでいます。

しかし、それでも直線は引けるはずで、i-rチャートには全く何もない、目盛りは0からと記されている。



 
psyman:

=また、iMAOnArray()をピリオド1で使用します。つまり、iMAOnArray()の値は実質的に配列tmp1の 値になります。


いろいろな値を試してみましたが、1がこの実験の最後のバリエーションとして残っています。

配列の値がすべて異なるtmp1[4] = 0.13000000000097などに対し、ip1Buf[4] = 2147483647.0 はなぜかすべてのTFのi-r bufferに同じ数字を書き込んでいます。

しかし、この場合でも直線は引けるはずで、i-rチャートには全く何もなく、0から目盛りがついているのです。



2147483647.0 さて、検索エンジンを使い始めましょう!https://www.mql5.com/ru/forum/224831

もう一度言いますが、私は今アーテムを書きました、自分で読んでください、簡単なものから始めてください...。チャート上に終値をインジケータで描き、さらに複雑にして、1サイクルで同じことを行い、2サイクル目では終値があるすでに計算済みのバッファを元にМА計算を行う。

2147483647 в буфере
2147483647 в буфере
  • 2018.01.15
  • www.mql5.com
День Добрый! Подскажите, пожалуйста, что это за хрень. Не первый раз сталкиваюсь...