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

 
有必要根据一个标准来隐藏物体。如何隐藏图形上的对象(主要是线条)?对象可以通过前缀来选择。
 
Seric29:
有必要根据一个标准来隐藏物体。如何隐藏图形上的对象(主要是线条)?可以通过前缀来选择对象。

OBJPROP_TIMEFRAMES有助于做到这一点。但不是一串一串的,而是一个一个的循环。

 
Alexey Viktorov:

OBJPROP_TIMEFRAMES会对此有所帮助。但并不是都在一起,而是一次一个循环。

我会这样做的,我想要一个逐个时期的映射,并将进行实验,谢谢你的建议。

 

程序如何运行得更快?

1.var.-如果你写的是通用函数。在这种情况下,检查的数量增加了,但代码量却减少了,因为最后函数少了,初始化的变量少了,但有一个前面提到的缺点。

第2种情况是,如果我们写更多的函数,将进行不太复杂的计算。在这种情况下,代码量增加,更多的变量被初始化,编译器将不得不经常闲置地运行代码以找到正确的函数,但有一个好处,检查的数量减少了。

谁想过这个问题?

 
Seric29:

程序如何运行得更快?

1.var.-如果你写的是通用函数。在这种情况下,检查的数量增加了,但代码量却减少了,因为最后函数少了,初始化的变量少了,但有一个前面提到的缺点。

第2种情况是,如果我们写更多的函数,将进行不太复杂的计算。在这种情况下,代码量增加,更多的变量被初始化,编译器将不得不经常闲置地运行代码以找到正确的函数,但有一个好处,检查的数量减少了。

谁想过这个问题?

选项2,很多小函数,但你对编译器和解释器之间的区别有2个月的了解,编译器不会空闲地运行代码,它会创建链接到函数、变量、常量的表格。然后使用这些表在运行时跳入

在这里阅读https://habr.com/ru/company/intel/blog/143446/

开发人员在这里的某个地方写了同样的东西,请搜索该主题https://www.mql5.com/ru/forum/304239/page36#comment_11049194


SZZ: 这里是编译器的工作原理https://habr.com/ru/sandbox/114988/

Делиться не всегда полезно: оптимизируем работу с кэш-памятью
Делиться не всегда полезно: оптимизируем работу с кэш-памятью
  • habr.com
Делиться с ближним своим для нас, божьих тварей, это очень характерно, считается добродетелью, и вообще, как утверждает первоисточник, положительно отражается на карме. Однако в мире, созданном архитекторами микропроцессоров, такое поведение не всегда приводит к хорошим результатам, особенно если это касается разделения памяти между потоками...
 
Alexey Viktorov:

这实在是太神奇了。如何在阅读文档时看到DRAW_HISTOGRAM2而没有看到DRAW_COLOR_HISTOGRAM2

哦,还有额外的缓冲区声明。

晚上好。试了很久,都是徒劳。直方图画得很正确,但不同颜色的着色(高于和低于50级)并没有赢。请告诉我,我哪里搞砸了。下面是文字,文件有链接。

//+------------------------------------------------------------------+
//|                                       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[];
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);
   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);
////--- установим пустое значение для HISTOGRAM2
//   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0);   
//--- 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;
   
   //PlotIndexSetInteger(2,PLOT_LINE_COLOR,0);
   
//--- 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=0;
         ColorHistogram_2Buffer1[i]=50; 
         ColorHistogram_2Buffer2[i]=ExtMainBuffer[i]; 
         ColorHistogram_2Colors[i]=colors[cl];
         } 
      if(ExtMainBuffer[i]<50){
         cl=1;
         ColorHistogram_2Buffer1[i]=ExtMainBuffer[i]; 
         ColorHistogram_2Buffer2[i]=50; 
         ColorHistogram_2Colors[i]=colors[cl];
         } 
     }
//--- 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.
   return(rates_total);
  }
//+------------------------------------------------------------------+ 

附加的文件:
 
Sergey Voytsekhovsky:

晚上好。试了很久,都是徒劳。直方图画得很正确,但不同颜色的着色(高于和低于50级)并没有赢。请告诉我,我哪里搞砸了。下面是文字,文件有链接。


调试模式 下,我正在一步一步地查看这些数值。

  • ExtMainBuffer[i]
  • 粘土
  • 颜色柱状图_2Buffer1[i]。
  • 颜色柱状图_2Buffer2[i]。
  • 颜色柱状图_2Colors[i]。
它似乎什么都对了,但柱状图只有绿色,低于50的柱状图没有染成红色。
 
Sergey Voytsekhovsky:

调试模式 下,一步一步地看完这些数值。

  • ExtMainBuffer[i]
  • 粘土
  • 颜色柱状图_2Buffer1[i]。
  • 颜色柱状图_2Buffer2[i]。
  • 色彩柱状图_2Colors[i]。
它似乎计数正确,但直方图只有绿色,低于50的没有染成红色。
 
Sergey Voytsekhovsky:

调试模式 下,一步一步地看完这些数值。

  • ExtMainBuffer[i]
  • 粘土
  • 颜色柱状图_2Buffer1[i]。
  • 颜色柱状图_2Buffer2[i]。
  • 色彩柱状图_2Colors[i]。
它似乎什么都对,但直方图只有绿色,那些低于50的直方图没有用红色标示。
检查代码
Normalized_Volume
Normalized_Volume
  • www.mql5.com
Индикатор Normalized Volume - индикатор нормализованного объёма. Отображает средний объём в диапазоне баров в виде цветной гистограммы с пороговым уровнем. Имеет два настраиваемых параметра:
 
Igor Makanu:

但你是在拉...

嗯,这是可以理解的,我只是形象地把程序称为编译器,但一般来说在哪种情况下会更好?

原因: