inputint InpSlowEMA=84; // Slow EMA periodinputint InpSignalSMA=9; // Signal SMA periodinputENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price//--- indicator buffersdouble ExtMacdBuffer[];
double ExtSignalBuffer[];
double ExtFastMaBuffer[];
double ExtSlowMaBuffer[];
//--- MA handlesint ExtFastMaHandle;
int ExtSlowMaHandle;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+voidOnInit()
{
//--- indicator buffers mappingSetIndexBuffer(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 drawnPlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpSignalSMA-1);
//--- name for Dindicator subwindow labelIndicatorSetString(INDICATOR_SHORTNAME,"MACD("+string(InpSlowEMA)+","+string(InpSignalSMA)+")");
//--- get MA handles
ExtSlowMaHandle=iMA(NULL,0,InpSlowEMA,0,MODE_SMA,InpAppliedPrice);
//--- initialization done
}
//+------------------------------------------------------------------+//| Moving Averages Convergence/Divergence |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,constint prev_calculated,
constdatetime &Time[],
constdouble &Open[],
constdouble &High[],
constdouble &Low[],
constdouble &Close[],
constlong &TickVolume[],
constlong &Volume[],
constint &Spread[])
{
//--- check for dataif(rates_total<InpSignalSMA)
return(0);
//--- not all data may be calculatedint 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 dataint 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 bufferif(IsStopped()) return(0); //Checking for stop flagif(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
{
Print("Getting fast EMA is failed! Error",GetLastError());
return(0);
}
//--- get SlowSMA bufferif(IsStopped()) return(0); //Checking for stop flagif(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 MACDfor(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);
}
//+------------------------------------------------------------------+
......................f函数(搜索、计算等)一般会返回长度/大小,如果不成功则返回-1,这使得错误处理更加容易。
问候。对于新手来说,在出现反向信号的情况下,用什么函数来设置一格订单的共同取舍,有什么提示吗?
我正在学习文件操作。有谁知道MQL4/5在使用csv或txt文件时是否更快?
你想通过处理文件来解决什么问题?
请给出一个代码例子,说明如何从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)。
关于ArraySize,那天我在MQL4上提出了一个类似的问题:https://www.mql5.com/ru/forum/152471。 据我所知,在MQL5中一切都应该是一样的。
也许,我的信息已经被考虑到了 :) 关于这个问题,服务台已经答复说,原因是优化器的操作不正确,他们将在新的构建中把类型改为uint。其实现在是uint,只是没有记录 :) 顺便说一下,他们也会把ArrayResize改成uint,我建议他们改成ulong,否则在不久的将来他们会因为存储大体积时缺乏32位值而不得不回到这个问题。
至于错误时的值-1,应该是没有问题的,因为。(int)-1 = (uint)-1 = 0xFFFFFFFFFF = UINT_MAX,也就是说,位的表示方法是一样的。 尽管比较操作会得到不同的结果,也就是说,如果在代码中是这样的话
它将变得不正确。
MQL数组中的元素总数不得超过INT_MAX,这一点将不会改变。
如果你在MQL程序中需要更大尺寸的数组,你必须创建一个单独的类(例如,CBigArray)。
试图在mql5中掌握iCustom。我在mql4中掌握了它:)
问题是要画出类似于MACD的东西,但不应该使用快速移动平均线,而应该使用实例文件夹中的VIDYA指标。
我采用了一个标准的MACD代码,并把VIDYA的参数代替了MA。问题是,所有的东西都能编译,但没有任何东西被画出来。
我在下面的代码中标记了两个地方,我改变了标准的MACD代码。否则一切都是一样的。请告诉我,我还漏掉了什么。我猜想它是在代码的某个下游...
Первый вставленный кусок:
input int Per=7; // Per input int Per1=21; // Per1 input int Shift=0; // Shift
Конец
Второй вставленный кусок
Конец
试图在mql5中掌握iCustom。在mql4中,我能够熟练地掌握它:)
我不知道这是否已经发生了,但问题是,新的酒吧,PLOT_EMPTY_VALUE的缓冲区的值被设置为0.0,但实际上有时有完全不同的值