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

 
RomanRott:

我的意思是在我的指标/顾问中规定一些代码,在打开时立即连接一些其他指标。
什么样的代码?

直觉告诉我这是为测试人员准备的。这一点在半次点击中就能解决,无需编程。当您创建一个包含所有您需要的指标的模板并给它命名为 "测试者 "或顾问的名字.然后,当您在测试者中运行顾问,一个图表将被打开,指标已经设置好.

 
RomanRott:

我的意思是在我的指标/顾问中写一些代码,当打开
,它将立即连接一些其他的指标,我应该如何添加?

我有很多变种。例如 1)ChartApplyTemplate- 将指定的模板应用于图表(模板显示指标)。2) 添加要包含在指标中的指标代码。3) 在专家顾问中,通过图形对象显示该指标。4) ...
 

你好,请你告诉我,我需要将Vinini_HMA指标整合到一个EA中,我已经设法连接它并通过资源和iCustom获得数据,但测试变得非常慢。请告知如何使指标值在EA本身中计算,我只需要一个参数来计算最后3根蜡烛。

以下是该指标的代码。

#property indicator_chart_window 
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Green 
#property indicator_color3 Red 
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2

//---- input parameters 
extern int period=15; 
extern int method=3; // MODE_SMA 
extern int price=0; // PRICE_CLOSE 
extern int sdvig=0;
//---- buffers 

double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];

double vect[]; 

//+------------------------------------------------------------------+ 
//| Custom indicator initialization function | 
//+------------------------------------------------------------------+ 
int init() { 
   IndicatorBuffers(4); 
   SetIndexBuffer(0, ExtMapBuffer); 
   SetIndexBuffer(1, Uptrend); 
   SetIndexBuffer(2, Dntrend); 
   SetIndexBuffer(3, vect); 
   
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);

   SetIndexDrawBegin(0,1*period);
   SetIndexDrawBegin(1,2*period);
   SetIndexDrawBegin(2,3*period);

   IndicatorShortName("Signal Line("+period+")"); 
   SetIndexLabel(1,"UP");
   SetIndexLabel(2,"DN");
   return(0); 
} 

//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function | 
//+------------------------------------------------------------------+ 
int deinit() { return(0); } 

//+------------------------------------------------------------------+ 
//| ?????????? ??????? | 
//+------------------------------------------------------------------+ 
double WMA(int x, int p) { return(iMA(NULL, 0, p, 0, method, price, x+sdvig)); } 

//+------------------------------------------------------------------+ 
//| Custom indicator iteration function | 
//+------------------------------------------------------------------+ 
int start() { 
   int counted_bars = IndicatorCounted(); 

   if (counted_bars < 0) return(-1); 
   if (counted_bars > 0) counted_bars--;
   
   int p = MathSqrt(period); 

   int i, limit0,limit1,limit2;
   
   limit2=Bars - counted_bars;
   limit1=limit2;
   limit0=limit1;

   if (counted_bars==0){
      limit1-=(period);
      limit2-=(2*period);
   }

   for(i = limit0; i >= 0; i--)    vect[i]          = 2*WMA(i, period/2) - WMA(i, period); 
   for(i = limit1; i >= 0; i--)    ExtMapBuffer[i]  = iMAOnArray(vect, 0, p, 0, method, i); 
   for(i = limit2; i >= 0; i--) { 
      Uptrend[i] = EMPTY_VALUE; if (ExtMapBuffer[i]> ExtMapBuffer[i+1]) Uptrend[i] = ExtMapBuffer[i]; `  AZ4
      Dntrend[i] = EMPTY_VALUE; if (ExtMapBuffer[i]< ExtMapBuffer[i+1]) Dntrend[i] = ExtMapBuffer[i]; 
   }
   return(0); 
} 

我需要计算缓冲区ExtMapBuffer[i] 中的最后3个值 我是个初学者,请不要苛责。我试图将这些代码片段插入专家顾问中,但数值的计算是不正确的

extern int period1=14;
extern int method1=3;
extern int price1=0;
extern int sdvig1=0;

-----------------------------------------------------
.
int p = MathSqrt(period1);      
        
        int z = 3;
        double vect[];
        ArrayResize(vect,z);
        
for(int i = 2; i >= 0; i--) vect[i] = 2*WMA(i, period1/2) - WMA(i, period1);
                
        int y = 3;;
        double HMA[];
        ArrayResize(HMA,y);
        
for(i = 2; i >= 0; i--) HMA[i]  = iMAOnArray(vect, 0, p, 0, method, i);

-------------------------------------------------------

double WMA(int x, int p) { return(iMA(NULL, 0, p, 0, method1, price1, x+sdvig1)); }

我真的需要它!谢谢你!提前感谢!很抱歉给你发了这么长的信息。

附加的文件:
123.png  22 kb
 

我最终有3个值vect[0],vect[1],vect[2]。但我需要HMA值。HMA[0]被计算出来,但不正确。HMA[1]和HMA[2]为零。

 
ilfat85:

我最终有3个值vect[0],vect[1],vect[2]。但我需要HMA值。HMA[0]被计算出来,但不正确。HMA[1]和HMA[2]为零。

我想这个问题已经在这个页面上讨论过 了...你是否尝试过与作者联系?
 
ilfat85:

你好,请你告诉我,我需要将Vinini_HMA指标整合到一个EA中,我已经设法连接它并通过资源和iCustom获得数据,但测试变得非常慢。请告知如何使指标值在EA本身中计算,我只需要一个参数来计算最后3根蜡烛。

以下是该指标的代码。

我需要计算缓冲区ExtMapBuffer[i] 中的最后3个值 我是个初学者,请不要苛责。我试图将这些代码片段插入专家顾问中,但数值的计算是不正确的

我真的需要它们!谢谢你!提前感谢!很抱歉给你发了这么长的信息。

对于测试者来说,不要连接一个资源-- 它很慢(不适用于这个特定的指标,而是所有的--在测试者中所有的资源都很慢)。

只需通过iCustom()从其文件夹中的文件位置(而不是从资源中)连接。

 
STARIJ:
我想这个问题已经在这个页面上讨论 过了......你是否尝试过与作者联系?

维蒂亚很少出现在这里。

 
STARIJ:
我想这个问题已经在这个页面上讨论过 了...你是否尝试过与作者联系?

那里有一个稍微不同的问题,他们从指标中获取数值,而我希望这些数值能直接在EA中计算。这些公式似乎很简单,但我在某处犯了一个错误。我没有联系过作者,我没有。谢谢你的提示,我将尝试给他写信。

 
Artyom Trishkin:

对于测试者来说,不要连接一个资源-- 它变慢了(不适用于这个特定的指标,而是适用于所有--测试者中的资源变慢)。

只需通过iCustom()从其文件夹中的文件位置(而不是从资源中)连接。


谢谢你!不知道这一点,我就这样试试吧。

 

你好,我正在制作一个基于蜡烛大小的柱状图。帮助我知道,第一支蜡烛的大小是最后十支蜡烛中最大的。直方图的条形图应以某种方式标记,通过宽度或颜色。也许你还应该增加一个缓冲区。

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,limit = Bars-1;
//--- counting from 0 to rates_total
   

//--- the main loop of calculations
   for(i = limit; i >= 0; i--)
     {
      if (hl) ExtATRBuffer[i] = (iHigh(Symbol(),Period(),i) - iLow(Symbol(),Period(),i)); 
                        
      else    ExtATRBuffer[i] = MathAbs(iOpen(Symbol(),Period(),i) - iClose(Symbol(),Period(),i));
      
      if (ExtATRBuffer[i] < x) ExtATRBuffer[i] = 0;
    
    //
      
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
п
原因: