错误、漏洞、问题 - 页 1175

 
A100:

......................f函数(搜索、计算等)一般会返回长度/大小,如果不成功则返回-1,这使得错误处理更加容易。

不至于牺牲一半的价值范围
 

问候。对于新手来说,在出现反向信号的情况下,用什么函数来设置一格订单的共同取舍,有什么提示吗?

 
我正在学习文件操作。有谁知道MQL4/5在使用csv或txt文件时是否更快?
 
paladin800:
我正在学习文件操作。有谁知道MQL4/5在使用csv或txt文件时是否更快?
 
papaklass:
你想通过处理文件来解决什么问题?
您需要将头寸的状态写入文件,并使用MT4读取这些数据。你需要一个符号的位置与其他符号相关联。例如,如果在欧元兑美元上已经有一定数量的头寸,就不应该再为英镑兑美元建立头寸。我知道在没有文件操作的情况下如何做,我只是想学习 如何使用文件操作,只是为了拓宽我的眼界。
 

请给出一个代码例子,说明如何从EA中调用一个链接资源指标,而该指标本身又使用另一个链接资源指标。例如,有一个指标A,B是由它调用的。也有专家C使用A。在所有情况下,#resource和调用iCustom 时,应该怎么写?

在这方面,帮助没有明确写明。在指标A中的通常构造:#resource "\\Indicators\B.ex4",然后iCustom(::Indicators\B.ex4)在A 本身启动时工作正常但是,如果A被插入到专家顾问#资源"\\Indicators\A.ex4 "中,就会出现无法加载所附指标资源的错误,表明某些绝对错误的合成路径,不知为何提到了Libraries目录,而指标B则是在其内部搜索的(MQL4\Libraries\::Indicators\B.ex4::Indicators\B.ex4

 
meat:

关于ArraySize,那天我在MQL4上提出了一个类似的问题:https://www.mql5.com/ru/forum/152471。 据我所知,在MQL5中一切都应该是一样的。

也许,我的信息已经被考虑到了 :) 关于这个问题,服务台已经答复说,原因是优化器的操作不正确,他们将在新的构建中把类型改为uint。其实现在是uint,只是没有记录 :) 顺便说一下,他们也会把ArrayResize改成uint,我建议他们改成ulong,否则在不久的将来他们会因为存储大体积时缺乏32位值而不得不回到这个问题。

至于错误时的值-1,应该是没有问题的,因为。(int)-1 = (uint)-1 = 0xFFFFFFFFFF = UINT_MAX,也就是说,位的表示方法是一样的。 尽管比较操作会得到不同的结果,也就是说,如果在代码中是这样的话

它将变得不正确。

再次感谢您的请求,ArraySize和ArrayRange函数的返回类型不会改变,我们将保留int类型。 我们纠正了代码优化器,现在您描述的错误不会发生。

MQL数组中的元素总数不得超过INT_MAX,这一点将不会改变。
如果你在MQL程序中需要更大尺寸的数组,你必须创建一个单独的类(例如,CBigArray)。
 

试图在mql5中掌握iCustom。我在mql4中掌握了它:)

问题是要画出类似于MACD的东西,但不应该使用快速移动平均线,而应该使用实例文件夹中的VIDYA指标。

我采用了一个标准的MACD代码,并把VIDYA的参数代替了MA。问题是,所有的东西都能编译,但没有任何东西被画出来

我在下面的代码中标记了两个地方,我改变了标准的MACD代码。否则一切都是一样的。请告诉我,我还漏掉了什么。我猜想它是在代码的某个下游...

//+------------------------------------------------------------------+
//|                                                         MACD.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2009, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property description "Moving Average Convergence/Divergence"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   2
#property  indicator_type1   DRAW_HISTOGRAM
#property  indicator_type2   DRAW_LINE
#property  indicator_color1  Silver
#property  indicator_color2  Red
#property  indicator_width1  2
#property  indicator_width2  1
#property  indicator_label1  "MACD"
#property  indicator_label2  "Signal"
//--- input parameters
Первый вставленный кусок:
input int                Per=7;               // Per
input int                Per1=21;             // Per1
input int                Shift=0            // Shift
Конец

input int                InpSlowEMA=84;               // Slow EMA period
input int                InpSignalSMA=9;              // Signal SMA period
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
//--- indicator buffers
double                   ExtMacdBuffer[];
double                   ExtSignalBuffer[];
double                   ExtFastMaBuffer[];
double                   ExtSlowMaBuffer[];
//--- MA handles
int                      ExtFastMaHandle;
int                      ExtSlowMaHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtMacdBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpSignalSMA-1);
//--- name for Dindicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"MACD("+string(InpSlowEMA)+","+string(InpSignalSMA)+")");
//--- get MA handles
Второй вставленный кусок
   ExtFastMaHandle=iCustom(NULL,0,"Examples\\VIDYA",
                     Per,
                     Per1,
                     Shift
                     );
Конец
   ExtSlowMaHandle=iMA(NULL,0,InpSlowEMA,0,MODE_SMA,InpAppliedPrice);
//--- initialization done
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
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 &TickVolume[],
                const long &Volume[],
                const int &Spread[])
  {
//--- check for data
   if(rates_total<InpSignalSMA)
      return(0);
//--- not all data may be calculated
   int calculated=BarsCalculated(ExtFastMaHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtFastMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
   calculated=BarsCalculated(ExtSlowMaHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtSlowMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
//--- we can copy not all data
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0) to_copy++;
     }
//--- get Fast EMA buffer
   if(IsStopped()) return(0); //Checking for stop flag
   if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
     {
      Print("Getting fast EMA is failed! Error",GetLastError());
      return(0);
     }
//--- get SlowSMA buffer
   if(IsStopped()) return(0); //Checking for stop flag
   if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0)
     {
      Print("Getting slow SMA is failed! Error",GetLastError());
      return(0);
     }
//---
   int limit;
   if(prev_calculated==0)
      limit=0;
   else limit=prev_calculated-1;
//--- calculate MACD
   for(int i=limit;i<rates_total && !IsStopped();i++)
      ExtMacdBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
//--- calculate Signal
   SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Nilog:

试图在mql5中掌握iCustom。在mql4中,我能够熟练地掌握它:)


它在日志中写了什么?没有对错误的检查(例如,在接收句柄时)。新指标中的缓冲区编号是否与旧指标一致?
 

我不知道这是否已经发生了,但问题是,新的酒吧,PLOT_EMPTY_VALUE的缓冲区的值被设置为0.0,但实际上有时有完全不同的值

原因: