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

 
ANDREY:
プログラム(mql 4、分単位、全ティック)が明示的に読み取る数値と、関数で計算した同じ数値が異なる理由を教えてください。以下、コード

Print()でPrの値が1.60854と 表示されているのに、プログラムではPrが1.60854と読み取れない。その結果、プログラムは2次を開くが、
、それを行うべきでは
ありません。


また、Pr 変数の代わりに 1.60854という 数値を設定 すると、 プログラムがそれを読み込んで 2次を 開けない

質問 プログラムがPrを 読み、2次を開けない ようにするには、コードをどのように変更すればよいですか。
ご協力
ありがとう ございました

実数を直接比較することはお勧めしません。正規化した差分をゼロと比較するのがより正しい。

NormalizeDouble(Lt1-Pr, _Digits) != 0.0;
 
Alexey Viktorov:

実数を直接比較することはお勧めしません。正規化した差分をゼロと比較するのが正しい。

貴重な情報をありがとうございました。私自身、想像もしていなかったことです。

 
ANDREY:

貴重な情報をありがとうございました。私自身、想像もしていませんでした。

推奨されないということは、禁止されるということではありません。例えば、現在の価格とストップ高の予想価格を比較すれば、それが多いか少ないかを直接比較することができる・・・その差は相当なものになるはずだ。しかし、対等な条件で比較するのは全く別の問題です...。

 
Alexey Viktorov:

推奨されていないからといって、禁止されているわけではありません。例えば、現在の価格とストップ高の予想価格を比較すれば、それが多いか少ないかを直接比較することができる・・・その差は相当なものになるはずだ。しかも、平等と比較すると全く別問題ですが...。

了解です。ありがとうございます。

 
指定されたコードファイルをインクルードするために、マクロ置換のリストを含む別のmqhファイルを作成することを考えました。
// файл со списком макроподстановок

#define  ARRAY_C #include <JvL/Arrays/C_Array.mqh>
#define  MTF_C #include <JvL/C_MTF.mqh>
// файл с кодом в котором нужно использовать включения других файлов с кодом

#include <JvL/Includes.mqh>
ARRAY_С
でも、そう簡単にうまくいくわけではありません。

macro argument expected instead of 'include' Includes.mqh
'include' - グローバルスコープでの式は許可されません C_Meter.mqh


どうすればコンパイラーを出し抜けるか?

 

こんにちは。Zigzagインジケーターを理解するために、ご教授ください。配列ZigZagBuffer[]全体が値0.0をとることがわかりました。なぜif(res != 0.0)という式が真になることがあるのでしょうか?結局、配列全体の値は0.0????????????????????????!

 if(prev_calculated==0)
     {
      ArrayInitialize(ZigZagBuffer,0.0);
      ArrayInitialize(HighMapBuffer,0.0);
      ArrayInitialize(LowMapBuffer,0.0);
      start=InpDepth;//Print(start);
     }
   if(prev_calculated>0) 
     {
      i=rates_total-1;//Print(i);
      //--- searching for the third extremum from the last uncompleted bar
      while(extreme_counter<ExtRecalc && i>rates_total-100)
        {
         res=ZigZagBuffer[i]; 
         if(res!=0.0)                       //!!!
            extreme_counter++; x++;
         i--;
        }
      i++;
      start=i;
 

皆さん、こんにちは。プログラマーの皆さん、助けてください。

多通貨のインジケータを作ろうとしているのですが、ベースメントに2つのシンボルのSMAを表示する必要があります。

難しい ことでなければ、何がエラーになっているのかアドバイスしてください。


//+------------------------------------------------------------------+
//|                                          Normalzd_I_I_Oscill.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                                 https://mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://mql5.com"
#property version   "1.00"
#property description "Normlzd_I_I_Oscill"
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots   2
//--- plot Int0
#property indicator_label1  "Int0"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDeepSkyBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Int1
#property indicator_label2  "Int1"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

//--- input parameters - buffer 0 ---------
input string          symbol0="EURUSD";      //----- Instrument 1 ------
input ENUM_TIMEFRAMES tf0=PERIOD_CURRENT; //Timeframe 1
input uint            InpPeriod0=10;   // Period1
//--- input parameters - buffer 1 ---------
input string          symbol1="USDCAD";      //----- Instrument 2 ------
input ENUM_TIMEFRAMES tf1=PERIOD_CURRENT; //Timeframe 2
input uint            InpPeriod1=10;   // Period2
//--- input other parameters --------------
input int             max_bars=100;       //Maximum Bars Calculate

//--- indicator buffers
double         Buffer1NII[];
double         Buffer1Temp[];
double         Buffer1Raw[];
double         Buffer2NII[];
double         Buffer2Temp[];
double         Buffer2Raw[];
//--- global variables
int            period_sm0;
int            period_sm1;
string         _symbol0,_symbol1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(symbol0==symbol1)
     {
      Alert("Wrong setting Symbol NAME");
      return(INIT_FAILED);
     }
   _symbol0=symbol0;
   _symbol1=symbol1;
   if(symbol0=="")
      _symbol0=Symbol();
   if(symbol1=="")
      _symbol1=Symbol();
//--- set global variables
   period_sm0=int(InpPeriod0<1 ? 1 : InpPeriod0);
   period_sm1=int(InpPeriod1<1 ? 1 : InpPeriod1);
   
//--- indicator buffers mapping
   SetIndexBuffer(0,Buffer1NII,INDICATOR_DATA);
   SetIndexBuffer(1,Buffer1Raw,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,Buffer1Temp,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,Buffer2NII,INDICATOR_DATA);
   SetIndexBuffer(4,Buffer2Raw,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,Buffer2Temp,INDICATOR_CALCULATIONS);

   PlotIndexSetString(0,PLOT_LABEL,symbol0+" Int0-" +EnumToString(tf0));   
   PlotIndexSetString(1,PLOT_LABEL,symbol1+" Int1-" +EnumToString(tf0));   
//--- setting indicator parameters
   IndicatorSetString(INDICATOR_SHORTNAME,"Normlzd_I_I_O"); 
   IndicatorSetInteger(INDICATOR_DIGITS,Digits());
//--- setting buffer arrays as timeseries
   ArraySetAsSeries(Buffer1NII,true);
   ArraySetAsSeries(Buffer1Temp,true);
   ArraySetAsSeries(Buffer1Raw,true);
   ArraySetAsSeries(Buffer2NII,true);
   ArraySetAsSeries(Buffer2Temp,true);
   ArraySetAsSeries(Buffer2Raw,true);
   
   if(!SymbolInfoInteger(symbol0,SYMBOL_SELECT)) 
      SymbolSelect(symbol0,true);                
   if(!SymbolInfoInteger(symbol1,SYMBOL_SELECT))
      SymbolSelect(symbol1,true);
//---
   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[])
  {
   bool error=false;
   string symerror="";
   ResetLastError();
//--- Установка массивов буферов как таймсерий
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(tick_volume,true);
//--- Проверка и расчёт количества просчитываемых баров
   if(rates_total<fmax(period_sm0,4)) return 0;
   if(rates_total<fmax(period_sm1,4)) return 1;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-0;
      ArrayInitialize(Buffer1NII,EMPTY_VALUE);
      ArrayInitialize(Buffer1Temp,0);
      ArrayInitialize(Buffer1Raw,0);
          
      limit=rates_total-1;
      ArrayInitialize(Buffer2NII,EMPTY_VALUE);
      ArrayInitialize(Buffer2Temp,1);
      ArrayInitialize(Buffer2Raw,1);
     }

//--- Расчёт индикатора
   for(int i=limit; i>=0 && !IsStopped(); i--)
     {
      Buffer1Temp[i]=(high[i]-low[i]!=0 ? (2.0*close[i]-high[i]-low[i])/(high[i]-low[i])*tick_volume[i] : 0);
      Buffer1Raw[i]=(double)tick_volume[i];
      double raw_avg1=GetSMA(rates_total,i,period_sm0,Buffer1Raw);
      Buffer1NII[i]=(raw_avg1!=0 ? GetSMA(rates_total,i,period_sm0,Buffer1Temp)/raw_avg1 : 0);
           {
            error=true;
            symerror=symbol0; 
           }
     
      Buffer2Temp[i]=(high[i]-low[i]!=0 ? (2.0*close[i]-high[i]-low[i])/(high[i]-low[i])*tick_volume[i] : 0);
      Buffer2Raw[i]=(double)tick_volume[i];
      double raw_avg2=GetSMA(rates_total,i,period_sm1,Buffer2Raw);
      Buffer2NII[i]=(raw_avg2!=0 ? GetSMA(rates_total,i,period_sm1,Buffer2Temp)/raw_avg2 : 0);
           {
            error=true;
            symerror=symbol0; 
           } 
     }
//--- return value of prev_calculated for next call
   if(error)
     
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Simple Moving Average                                            |
//+------------------------------------------------------------------+
double GetSMA(const int rates_total,const int index,const int period,const double &price[],const bool as_series=true)
  {
//---
   double result=0.0; 
//--- check position
   bool check_index=(as_series ? index<=rates_total-period-1 : index>=period-1);
   if(period<1 || !check_index)
      return 0;
//--- calculate value
   for(int i=0; i<period; i++)
      result=result+(as_series ? price[index+i]: price[index-i]);
//---
   return(result/period);
  }
//+------------------------------------------------------------------+
 
ANDREY:

皆さん、ごきげんよう。
どの数学関数を使って、次の条件を正しくコード化する方法を教えてください。

if (Bid - Low[1]>=0.0030 &&Bid - Low[1]<0.0035) {action;}
上記の条件で、&& 記号を使わずに使える数学関数があることは知っているのですが、それを使うことはできますか?しかし、この数学的な関数が何と呼ばれていて、どのように適用するのか覚えていない。
よろしくお願いします。

if(MathAbs(Bid - Low[1]) >= 0.0004){アクション;}。

 
Taras Slobodyanik:

if(MathAbs(Bid - Low[1]) >= 0.0004){アクション;}。

タラス、タラス... 学校で考えることを習わなかったのか?0.0004は0.0035より小さいことがあるのか.........................。

 
Alexey Viktorov:

タラス、タラス・・・学校で考えることを教わらなかったのか?0.0004は0.0035より小さいか............................0.0004

読解力を身につけろ、この嘘つきが。

をクリックすると、プログラムが4点 範囲で価格の整合性をチェックします。