新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 1494

 
ANDREY:
请你告诉我,为什么程序(在mql 4上,在分钟上,所有的ticks上)明确读出的数字和函数中计算出的同一数字不同。以下是代码

尽管Print()显示Pr 的值为1.608 54,但程序并没有将Pr读为1.60854结果,程序打开了第二个订单,但它不应该这样做


而如果我们设置数字1.60854 而不是Pr 变量 ,程序就会读取它而不打开 第二单。

问题 对代码应该做什么修改,使程序读取Pr而不打开第二单
谢谢
你的帮助

不建议直接比较实数。将它们的归一化差异与零进行比较更为正确。

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_С
但它并不那么容易起作用。

预期的宏参数,而不是'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;
 

大家好。亲爱的程序员们,我需要你们的帮助。

我想做一个多货币指标,它应该在地下室显示两个符号的均线。

如果不难, 请告知错误在哪里。


//+------------------------------------------------------------------+
//|                                          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;}
我知道有一个数学函数可以在上述条件中使用,没有&& 符号。但我不记得这个数学函数叫什么,如何应用它。
谢谢你的帮助。

如果(MathAbs(Bid - Low[1]) >= 0.0004){行动;}

 
Taras Slobodyanik:

如果(MathAbs(Bid - Low[1]) >= 0.0004){行动;}

哦,塔拉斯,塔拉斯......你在学校没有学会思考吗?0.0004是否永远小于0.0035 ...............

 
Alexey Viktorov:

哦,塔拉斯,塔拉斯......他们在学校没有教你思考吗?0.0004是否小于0.0035 ...............

学会阅读,你这个骗子。

并且程序将检查4点 范围内的价格一致性。

原因: