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

 
Konstantin Nikitin:

是的,这就是我的意思。好吧,我们错过了。最主要的是让他明白什么是什么。

他是谁?这就是我开始的地方。

关于交易、自动交易系统和策略测试的论坛

初学者对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论

Alexey Viktorov, 2019.06.11 09:06

你不能用SymbolInfoInteger来获取Point())。

一般来说,有必要记住Point()或_Point只针对当前符号。对于EA工作的符号以外的符号,你应该使用这个功能。

SymbolInfoInteger函数 不仅返回int值,而且还返回long、bool和枚举值。

接下来,当然,他的意思是Digits()或_Digits,并写下了他所写的东西。而最后一行回答涉及问题的第二部分。不要忘记俄罗斯的一句谚语:"聪明人不说,傻瓜不猜"。猜测并说,所以它既不是一件事,也不是另一件事。
 
Alexey Viktorov:

Может вам очень не повезло, но я не люблю колупаться в чужом коде. Тем более править его...

阿列克谢-维克多罗夫

下一个问题:你认为指标值多长时间会正好是50?

按照我对问题的理解,应该是一种颜色>50,另一种颜色<50,但我没有在任何地方看到==50。当然,为了避免在==50的情况下失败,我们应该在其中一个中加入>=50,在另一个中加入<=50。它可能看起来更好。

而第二个问题:改变整个缓冲区的索引有多大的必要性?在重新索引之后,你是否修复了你的代码中的所有内容?也许让彩色缓冲区索引4,以及相应的辅助缓冲区 5和6会更容易。你会有更少的时间来编辑,更少的机会来犯一些更多的错误。

  • 谢谢你的回答。如果卢比在别人的代码中打探,我们很可能会失去你这个专家,所以在这方面只是LUCKY。
  • 关于<=或>=我同意,省略,当然其中一个必须存在,只要我跑过去,但现在这不是一个原则问题。
  • 试过了,重新分配了一个颜色的缓冲区,重新分配了整个组,交换了组的位置(上面/下面)--没有任何帮助。我现在要完成这个帖子,并尝试做一个单独的直方图指标,没有线条。如果成功的话,我将尝试再次将它们结合起来。这是一个原则问题。我不希望留下不理解的白点。

 
Sergey Voytsekhovsky:

  • 谢谢你的答复。如果Lubilee一直在别人的代码中打探,我们可能已经失去了你这个专家,所以在这方面只是LUCKY。
  • 关于<=或>=我同意,省略,当然其中一个必须存在,只要我跑过去,但到目前为止不是一个原则问题。
  • 试过了,重新分配一个颜色的缓冲区,重新分配整个组,交换组(上面/下面)--没有任何帮助。我现在要完成这个帖子,并尝试做一个单独的直方图指标,没有线条。如果成功的话,我将尝试再次将它们结合起来。这是一个原则问题。我不希望留下不理解的白点。

我想你在改变缓冲区索引的时候可能已经绞尽脑汁了。

回去把信息8806 的旧代码拿出来,只改变缓冲区的顺序。

   SetIndexBuffer(4,ColorHistogram_2Colors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(5,ExtHighesBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(6,ExtLowesBuffer,INDICATOR_CALCULATIONS);
那么,在有必要放0和有必要放1的情况下,追踪条件
 
Alexey Viktorov:

你在改变缓冲区的索引时一定没有想得太周到。

回去把8806号 帖子中的旧代码拿出来,只改变那里的缓冲区序列。

然后追踪什么时候在颜色缓冲区里放0,什么时候放1的条件

我这样做了,没有帮助,承认我在犯错,在你的帖子之后我又做了一次。以下是我修改的代码地方。旧的那个没有注释。

//+------------------------------------------------------------------+
//|                                       Stoch_HISTOGRAM_MQL5_4.mq5 |
//|                   Copyright 2009-2017, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_plots   3

#property indicator_type1   DRAW_LINE       // основная
#property indicator_color1  clrLightSeaGreen
#property indicator_style1  STYLE_SOLID

#property indicator_type2   DRAW_LINE       // сигнальная
#property indicator_color2  clrYellow
#property indicator_style2  STYLE_SOLID

#property indicator_type3   DRAW_COLOR_HISTOGRAM2
#property indicator_color3  clrGreen,clrRed
#property indicator_style3  STYLE_SOLID

#property indicator_width1  3 
#property indicator_width2  2 
#property indicator_width3  1 
//--- input parameters
input int InpKPeriod=5;  // K period
input int InpDPeriod=3;  // D period
input int InpSlowing=3;  // Slowing
//--- indicator buffers
double    ExtMainBuffer[];
double    ExtSignalBuffer[];
double    ColorHistogram_2Buffer1[]; 
double    ColorHistogram_2Buffer2[]; 
     //double    ExtHighesBuffer[];
     //double    ExtLowesBuffer[];
     //double    ColorHistogram_2Colors[];
double    ColorHistogram_2Colors[];
double    ExtHighesBuffer[];
double    ExtLowesBuffer[];
color     colors[]={clrRed,clrGreen};
int       cl;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtMainBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ColorHistogram_2Buffer1,INDICATOR_DATA);
   SetIndexBuffer(3,ColorHistogram_2Buffer2,INDICATOR_DATA);
        //SetIndexBuffer(4,ExtHighesBuffer,INDICATOR_CALCULATIONS);
        //SetIndexBuffer(5,ExtLowesBuffer,INDICATOR_CALCULATIONS);
        //SetIndexBuffer(6,ColorHistogram_2Colors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(4,ColorHistogram_2Colors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(5,ExtHighesBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(6,ExtLowesBuffer,INDICATOR_CALCULATIONS);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0);
//--- set accuracy
   IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- set levels
   IndicatorSetInteger(INDICATOR_LEVELS,3);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,0,20);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,1,50);
   IndicatorSetDouble(INDICATOR_LEVELVALUE,2,80);
//--- set maximum and minimum for subwindow 
   IndicatorSetDouble(INDICATOR_MINIMUM,0);
   IndicatorSetDouble(INDICATOR_MAXIMUM,100);
//--- name for DataWindow and indicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"Stoch_HISTOGRAM("+(string)InpKPeriod+","+(string)InpDPeriod+","+(string)InpSlowing+")");
   //PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0);
   PlotIndexSetString(0,PLOT_LABEL,"Main");
   PlotIndexSetString(1,PLOT_LABEL,"Signal");
        //PlotIndexSetString(2,PLOT_LABEL,"UP");
        //PlotIndexSetString(3,PLOT_LABEL,"LOW");
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpKPeriod+InpDPeriod);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2);
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,InpKPeriod+InpSlowing-2);
//--- initialization done
  }
//+------------------------------------------------------------------+
//| Stochastic Oscillator                                            |
//+------------------------------------------------------------------+
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,k,start;
//--- check for bars count
   if(rates_total<=InpKPeriod+InpDPeriod+InpSlowing)
      return(0);
//---
   start=InpKPeriod-1;
   if(start+1<prev_calculated) start=prev_calculated-2;
   else
     {
      for(i=0;i<start;i++)
        {
         ExtLowesBuffer[i]=0.0;
         ExtHighesBuffer[i]=0.0;
        }
     }
//--- calculate HighesBuffer[] and ExtHighesBuffer[]
   for(i=start;i<rates_total && !IsStopped();i++)
     {
      double dmin=1000000.0;
      double dmax=-1000000.0;
      for(k=i-InpKPeriod+1;k<=i;k++)
        {
         if(dmin>low[k])  dmin=low[k];
         if(dmax<high[k]) dmax=high[k];
        }
      ExtLowesBuffer[i]=dmin;
      ExtHighesBuffer[i]=dmax;
     }
//--- %K
   start=InpKPeriod-1+InpSlowing-1;
   if(start+1<prev_calculated) start=prev_calculated-2;
   else
     {
      for(i=0;i<start;i++) ExtMainBuffer[i]=0.0;
     }
//--- main cycle
   for(i=start;i<rates_total && !IsStopped();i++)
     {
      double sumlow=0.0;
      double sumhigh=0.0;
      for(k=(i-InpSlowing+1);k<=i;k++)
        {
         sumlow +=(close[k]-ExtLowesBuffer[k]);
         sumhigh+=(ExtHighesBuffer[k]-ExtLowesBuffer[k]);
        }
      if(sumhigh==0.0) ExtMainBuffer[i]=100.0;
         else ExtMainBuffer[i]=sumlow/sumhigh*100;
      if(ExtMainBuffer[i]>=50){
         cl=1;
         ColorHistogram_2Buffer1[i]=50; 
         ColorHistogram_2Buffer2[i]=ExtMainBuffer[i]; 
         ColorHistogram_2Colors[i]=colors[cl];
     Print("ExtMainBuffer[i]=",ExtMainBuffer[i],
           " cl=",cl,
           " ColorHistogram_2Buffer1[i]=",ColorHistogram_2Buffer1[i],
           " ColorHistogram_2Buffer2[i]=",ColorHistogram_2Buffer2[i],
           " ColorHistogram_2Colors[i]=",ColorHistogram_2Colors[i]);
         } 
      if(ExtMainBuffer[i]<50){
         cl=0;
         ColorHistogram_2Buffer1[i]=ExtMainBuffer[i]; 
         ColorHistogram_2Buffer2[i]=50; 
         ColorHistogram_2Colors[i]=colors[cl];
     Print("ExtMainBuffer[i]=",ExtMainBuffer[i],
           " cl=",cl,
           " ColorHistogram_2Buffer1[i]=",ColorHistogram_2Buffer1[i],
           " ColorHistogram_2Buffer2[i]=",ColorHistogram_2Buffer2[i],
           " ColorHistogram_2Colors[i]=",ColorHistogram_2Colors[i]);
         } 
     }
//--- signal
   start=InpDPeriod-1;
   if(start+1<prev_calculated) start=prev_calculated-2;
   else
     {
      for(i=0;i<start;i++) ExtSignalBuffer[i]=0.0;
     }
   for(i=start;i<rates_total && !IsStopped();i++)
     {
      double sum=0.0;
      for(k=0;k<InpDPeriod;k++) sum+=ExtMainBuffer[i-k];
      ExtSignalBuffer[i]=sum/InpDPeriod;
     }
//--- OnCalculate done. Return new prev_calculated.
   //PlotIndexSetInteger(2,PLOT_LINE_COLOR,colors[i]);
   return(rates_total);
  }
//+------------------------------------------------------------------+ 

这是我做出改变之前的情况。直方图在那里,正确的颜色不在那里。

现在的情况就是这样。直方图没有了,不显示了。

我想我又想不明白了。


 
Sergey Voytsekhovsky:

我这样做了,但没有帮助,我犯了错误,在你的帖子之后我又做了一次。以下是我在代码中修改的地方。旧的那个没有注释。

这是我做出改变之前的情况。直方图在那里,正确的颜色不在那里。

现在的情况就是这样。直方图没有了,不显示了。

我一定是又在绞尽脑汁了。


这里根本就没有逻辑。顺序应该是这样的:直方图值被确定,指标缓冲区的 第i个索引被填入。然后进行单独检查,如果该值>=50,则颜色缓冲区被填充为0,否则为1。 这是由指令中的颜色顺序决定的

#property indicator_color3  clrGreen,clrRed

如果是0,则采取clrGreen颜色,如果是1,则采取clrRed颜色。

而这句话完全没有必要,其顺序与第一句相反。

color     colors[]={clrRed,clrGreen};

而这

int       cl;

添加的目的是什么?直接填写比较容易。

ColorHistogram_2Colors[i]=0;
// или 
ColorHistogram_2Colors[i]=1;

为了填充颜色缓冲区,我将使用这样的结构

         ColorHistogram_2Colors[i]=ExtMainBuffer[i] >= 50 ? 0 : 1; 
?: 操作符等同于if else,但应用起来更方便
 
Alexey Viktorov:

这里的逻辑总体上是坏的。顺序应该是这样的:确定直方图值,填入指标缓冲区 的第i个索引。然后进行单独检查,如果该值>=50,则颜色缓冲区被填充为0,否则为1。 这是由指令中的颜色序列决定的

如果是0,则采取clrGreen颜色,如果是1,则采取clrRed颜色。

而这句话是绝对没有必要的,而且这个顺序与第一句话相反。

而这

添加的目的是什么?直接填写比较容易。

为了填充颜色缓冲区,我将使用这样的结构

?: 操作符等同于if else,但应用起来更方便

WURRAA,而我的灵魂已经唱起。阿列克谢,非常感谢!!!!!

这一切都成功了,我不太明白没有阵列怎么可能呢?

color     colors[]={clrRed,clrGreen};

因为其描述已被删除。所以你可以不在这里做额外的阵列?


 
Sergey Voytsekhovsky:

  • 谢谢你的答复。如果Lubilee一直在别人的代码中打探,我们可能已经失去了你这个专家,所以在这方面只是LUCKY。
  • 关于<=或>=我同意,省略,当然其中一个必须存在,只要我跑过去,但现在这不是一个原则问题。
  • 试过了,重新分配了一个颜色的缓冲区,重新分配了整个组,交换了组的位置(上面/下面)--没有任何帮助。我现在要完成这个帖子,并尝试做一个单独的直方图指标,没有线条。如果成功的话,我将尝试再次将它们结合起来。这是一个原则问题。我不希望留下不理解的白点。

我的Squeaky简直是个奇迹,他带着它到处跑,到处走。

p.s 我还没有学会如何正确地附上图片,请原谅我,我会从屏幕上张贴皮肤。

附加的文件:
EURUSD.png  52 kb
GBPUSD.png  54 kb
 
Alexey Viktorov:

为了填充颜色缓冲区,我将使用这个结构

?: 操作符等同于if else,但更容易使用

伟大的建议和对未来的伟大科学!!!。甚至走得更远一点。下面是结果。

因此,它是。

if(ExtMainBuffer[i]>=50){
         //cl=1;
         ColorHistogram_2Buffer1[i]=50; 
         ColorHistogram_2Buffer2[i]=ExtMainBuffer[i]; 
         ColorHistogram_2Colors[i]=0;
     Print("ExtMainBuffer[i]=",ExtMainBuffer[i],
           " # ExtSignalBuffer[i]=",ExtSignalBuffer[i],
           " # ColorHistogram_2Buffer1[i]=",ColorHistogram_2Buffer1[i],
           " # ColorHistogram_2Buffer2[i]=",ColorHistogram_2Buffer2[i],
           " # ColorHistogram_2Colors[i]=",ColorHistogram_2Colors[i]);
         } 
if(ExtMainBuffer[i]<50){
         //cl=0;
         ColorHistogram_2Buffer1[i]=ExtMainBuffer[i]; 
         ColorHistogram_2Buffer2[i]=50; 
         ColorHistogram_2Colors[i]=1;
     Print("ExtMainBuffer[i]=",ExtMainBuffer[i],
           " # ExtSignalBuffer[i]=",ExtSignalBuffer[i],
           " # ColorHistogram_2Buffer1[i]=",ColorHistogram_2Buffer1[i],
           " # ColorHistogram_2Buffer2[i]=",ColorHistogram_2Buffer2[i],
           " # ColorHistogram_2Colors[i]=",ColorHistogram_2Colors[i]);
         } 

所以就变成了,这个方法的有效性是显而易见的!!!。谢谢你。

      ColorHistogram_2Buffer1[i]=ExtMainBuffer[i] >= 50 ? 50 : ExtMainBuffer[i]; 
      ColorHistogram_2Buffer2[i]=ExtMainBuffer[i] >= 50 ? ExtMainBuffer[i] : 50; 
      ColorHistogram_2Colors [i]=ExtMainBuffer[i] >= 50 ? 0 : 1;
         Print("ExtMainBuffer[i]=",ExtMainBuffer[i],
            " # ExtSignalBuffer[i]=",ExtSignalBuffer[i],
            " # ColorHistogram_2Buffer1[i]=",ColorHistogram_2Buffer1[i],
            " # ColorHistogram_2Buffer2[i]=",ColorHistogram_2Buffer2[i],
            " # ColorHistogram_2Colors[i]=",ColorHistogram_2Colors[i]);
 
Sergey Voytsekhovsky:

伟大的建议和对未来的伟大科学!!!。甚至比这更进一步。下面是结果。

因此,它是。

所以就变成了,这个方法的有效性是显而易见的!!!。谢谢你。

这里没有效率--三个if-else条件而不是一个。在这里,更糟糕的是它的方式......。

 
Artyom Trishkin:

这里没有效率:有三个if-else条件,而不是一个。这里的情况更糟...

是的,的确,我没有注意到这一点。它看起来更好,字母更少。

而且没有办法三个执行(我不知道怎么说才对) 放在一个操作者之下?

原因: