改变TF是一个问题 - 页 5

 

这里有一个指标。

//+------------------------------------------------------------------+
//|                                                    Shabl_ind.mq4 |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "eevviill"
#property link      "http://alievtm.blogspot.com"
#property version   "1.42"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property  indicator_color1 clrLightBlue
#property  indicator_color2 clrRed
#property  indicator_width1 2
#property  indicator_width2 2

input string   arr_set="Arrow settings";
input int      arrow_indent=22;
input int      up_arrow_code=233;
input int      down_arrow_code=234;

double         up_arr[];
double         down_arr[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,up_arr);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,up_arrow_code);
   SetIndexLabel(0,"UP arrow");

   SetIndexBuffer(1,down_arr);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,down_arrow_code);
   SetIndexLabel(1,"DOWN arrow");

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Shabl_ind                                                        |
//+------------------------------------------------------------------+
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=0;
//---
   if(rates_total<=20)
      return(0);
//--- last counted bar will be recounted
   if(prev_calculated==0)
      limit=rates_total-1;
   if(prev_calculated>0)
      limit=rates_total-prev_calculated+1;
   Comment("rates_total=",rates_total,"; prev_calculated=",prev_calculated,"; limit=",limit);
//--- Shabl_ind counted in the 1-st buffer
   datetime temp;
   for(i=0; i<limit; i++)
     {
      temp=time[i];
      if(close[i]>close[i+1])
         up_arr[i]=low[i]-arrow_indent*Point; //up arrow
      if(close[i]<close[i+1])
         down_arr[i]=high[i]+arrow_indent*Point; //down arrow
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

只需注意,根据你的条件,指标可能会在零条上绘制两个缓冲区。

附加的文件:
 
Karputov Vladimir:

这里有一个指标。

请注意,根据您的条件,指示器可能在零气压下绘制两个缓冲区

为了避免抽取两个缓冲区,你需要在一个缓冲区满时将另一个缓冲区清零。

      if(close[i]>close[i+1])
       {
        down_arr[i] = EMPTY_VALUE;
        up_arr[i]=low[i]-arrow_indent*Point; //up arrow
       }
      if(close[i]<close[i+1])
       {
        up_arr[i] = EMPTY_VALUE;
        down_arr[i]=high[i]+arrow_indent*Point; //down arrow
       }
 
Vasyl Nosal:
你有一个解决方案的代码吗?

像许多其他人一样,我对你的问题有不止一个解决办法。因为指标在细微之处可以有所不同(它们执行的任务/编码/计算的间隔,总之,很多因素)。

 
Karputov Vladimir:

这里有一个指标。

只需注意,根据你的条件,指标可以在零点的时候抽取两个缓冲区。

你们是在耍我还是真的不知道问题出在哪里?

当你在未加载的历史上改变TF时,这里是你的指标。

:)))))))))))))))))))))))))))))))))))))))))))

 
Dina Paches:

像许多其他人一样,我对你的问题有不止一个解决办法。因为指标在细微之处可以有所不同(它们执行的任务/编码/计算的间隔,总之,很多因素)。

胡说八道......。
 
Vasyl Nosal:

你们都在跟我胡扯,还是真的不知道问题出在哪里?

这是你的指标,用于衡量未加载历史的TF变化。

:)))))))))))))))))))))))))))))))))))))))))))

你能告诉我,你用什么方法来实现这样一个有趣的画面?而且我希望你今后能更加缄默。

补充:我在上面提到,在泵送历史数据时,你需要自己考虑指标缓冲区的内容。

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

改变TFs是一个问题

Karputov Vladimir, 2015.12.07 10:09

你有两个变量供你使用:prev_calculated和rate_total。通过控制历史加载(用prev_calculated==0),你必须考虑如何处理指标缓冲区 - 在这种情况下,通常的行为是将历史加载等同于第一个指标加载 事件。

但你出于某种原因忽略了它,不想进行编辑。

无论如何,这里是1.43版(这里有我的更正和Alexey Viktorov 的更正)。

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

TF变化--问题

Alexey Viktorov, 2015.12.07 12:52

如果你想避免绘制两个缓冲区,你必须在一个缓冲区满时将其重置为零。

      if(close[i]>close[i+1])
       {
        down_arr[i] = EMPTY_VALUE;
        up_arr[i]=low[i]-arrow_indent*Point; //up arrow
       }
      if(close[i]<close[i+1])
       {
        up_arr[i] = EMPTY_VALUE;
        down_arr[i]=high[i]+arrow_indent*Point; //down arrow
       }

:

//+------------------------------------------------------------------+
//|                                                    Shabl_ind.mq4 |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "eevviill"
#property link      "http://alievtm.blogspot.com"
#property version   "1.43"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property  indicator_color1 clrLightBlue
#property  indicator_color2 clrRed
#property  indicator_width1 2
#property  indicator_width2 2

input string   arr_set="Arrow settings";
input int      arrow_indent=22;
input int      up_arrow_code=233;
input int      down_arrow_code=234;

double         up_arr[];
double         down_arr[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,up_arr);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,up_arrow_code);
   SetIndexLabel(0,"UP arrow");

   SetIndexBuffer(1,down_arr);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,down_arrow_code);
   SetIndexLabel(1,"DOWN arrow");

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Shabl_ind                                                        |
//+------------------------------------------------------------------+
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=0;
//---
   if(rates_total<=20)
      return(0);
//--- last counted bar will be recounted
   if(prev_calculated==0)
     {
      limit=rates_total-1;
      ArrayInitialize(up_arr,EMPTY_VALUE);
      ArrayInitialize(down_arr,EMPTY_VALUE);
     }
   if(prev_calculated>0)
      limit=rates_total-prev_calculated+1;
   Comment("rates_total=",rates_total,"; prev_calculated=",prev_calculated,"; limit=",limit);
//--- Shabl_ind counted in the 1-st buffer
   for(i=0; i<limit; i++)
     {
      if(close[i]>close[i+1])
        {
         down_arr[i]=EMPTY_VALUE;
         up_arr[i]=low[i]-arrow_indent*Point; //up arrow
        }
      if(close[i]<close[i+1])
        {
         up_arr[i]=EMPTY_VALUE;
         down_arr[i]=high[i]+arrow_indent*Point; //down arrow
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
附加的文件:
 
Karputov Vladimir:

你能告诉我们你用什么方法来实现这样有趣的画面吗?而且我希望你从现在开始在语言上要更加谨慎。

我打开了一个我以前从未打开过的货币对的图表。例如,M1。我附上你的指标。我把它改为M5。

所以我是对的?我们需要重置箭头缓冲区?

 
Vasyl Nosal:

mql4

不,这是你在一对没有历史的地方的设计。

这是什么?

if(i>Bars-20) i=Bars-20;

正如我所想的,这个循环在内部扎根。另外,由于在循环体中,你访问了前一个柱子([i+1]),你应该不早于历史上的第二个柱子开始计算(从左边开始计算)。而且,缓冲区必须在每个酒吧都被填满,而不是只有一个。好吧,或者事先在OnInit()中初始化它们。

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 nStartBar = rates_total - MathMax(prev_calculated, 2);

   for(int i = nStartBar; i >= 0; i--)
   {
      if(Close[i] > Close[i+1])
      {
         up_arr[i] = Low[i] - arrow_indent * _Point; //up arrow
         down_arr[i] = 0;
      }
         
      if(Close[i] < Close[i+1])
      {
         up_arr[i] = 0;
         down_arr[i] = High[i] + arrow_indent * _Point; //down arrow
      }
   }

   return(rates_total);
}
 
Karputov Vladimir:

总之,这里是1.43版(我的更正和Alexey Viktorov的 更正在此)。


:

Vladimir,你为什么要在OnCalculate()里面做这个?我指的是最后两行--数组的重新初始化。两个缓冲区都是在每个柱子上计算的,这是一个不必要的动作。

if(prev_calculated==0)
{
   limit=rates_total-1;
   ArrayInitialize(up_arr,EMPTY_VALUE);
   ArrayInitialize(down_arr,EMPTY_VALUE);
}
 
Sergei Vladimirov:

这是什么?

正如我所想的那样,这个循环在内部被破坏了。此外,如果你在循环体中访问前一栏([i+1]),那么计算应该不早于历史上的第二个栏(从左边开始计算)。而且,缓冲区必须在每个酒吧都被填满,而不是只有一个。好吧,或者事先在OnInit()中初始化它们。

就这样,不会出现故障吗?