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

 

伙计们,请在代码中帮助我把TF d1/week改为任何其他的。

我知道如何把它改成H1或分钟。

对如何改成M30、M15、M5感兴趣?

//|                                               For__red_r2005.mq4 |
//|                                       Copyright © 2010, PapaYozh |
//|                                                                * |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, PapaYozh"
#property link      "*"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Coral
#property indicator_color2 CornflowerBlue
#property indicator_width1 2
#property indicator_width2 2

// ---- buffers ----
double BuffD[];
double BuffM[];
//+------------------------------------------------------------------+
int init()
{
   SetIndexBuffer(0,BuffD);
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexStyle(0,DRAW_SECTION,EMPTY,EMPTY);

   SetIndexBuffer(1,BuffM);
   SetIndexEmptyValue(1,EMPTY_VALUE);
   SetIndexStyle(1,DRAW_SECTION,EMPTY,EMPTY);
   
   return(0);
} // init()
//+------------------------------------------------------------------+
int deinit()
{
   return(0);
} // deinit()
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
int start()
{
   int    shift;

   shift = Bars - 1 - IndicatorCounted();
   for ( ; shift>0 ; shift-- )
   {
      if ( TimeDayOfYear(Time[shift]) != TimeDayOfYear(Time[shift-1]) )
      {
         BuffD[shift]   = Close[shift];
         if ( TimeDayOfWeek(Time[shift-1]) == 1 )
            BuffM[shift]   = Close[shift];
         else
            BuffM[shift]   = EMPTY_VALUE;
      }
      else
      {
         BuffD[shift]   = EMPTY_VALUE;
         BuffM[shift]   = EMPTY_VALUE;
      }
   }
   return(0);
} // start()
//+------------------------------------------------------------------+
 
需要将指标暂停一段时间,但如帮助中所述,Sleep()函数 不能从自定义指标中调用...还有别的办法吗?
 
Yevhenii Levchenko:
我需要将指标暂停一段时间,但帮助中提到的Sleep()函数 不能从自定义指标中调用。还有其他方法吗?

在OnCalculate()中按条件输出,而不计算指标值--最简单的是tick计数器,更复杂一点的是使用计时器,它在指标中起作用。

 
Igor Makanu:

在OnCalculate()中按条件输出,而不计算指标值--最简单的是tick计数器,更复杂一点的是使用计时器,它在指标中起作用。

谢谢你!

我已经用定时器做了。这个选项对我来说似乎更容易...

 
Yevhenii Levchenko:

谢谢你!

用定时器做了。这个选项对我来说似乎更容易...

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[])
  {
//---
   static int TickCount = 0;
   TickCount--;
   if(TickCount>0) return(rates_total);
   TickCount=10;
 
Igor Makanu:

我已经完全忘记了静态变量...谢谢 :)

而如果你把一个普通的变量声明为全局变量,那么事实上它在某种意义上与静态变量是一样的?在这个意义上,它将可以从程序中的所有地方改变?

 

你好。

请告诉我,是否可以通过引用将一个 结构类型的动态数组 传递给一个函数?

例如,将struct_name_array[]数组传递给Func()处理,并在此填充。

struct StructName {int x;
                   int y;} struct_name_array[];

void Func (int &x[],
           int &y[])
        {
        }

如果有可能的话,究竟如何处理转会的问题?函数参数的格式是怎样的?我似乎不能使用C++指南。

谢谢你。

 
Mikhail Sobolev:

例如,将一个数组struct_name_array[]传递给Func(),在那里进行处理和填充。

//+------------------------------------------------------------------+
struct StructName
  {
   int               x;
   int               y;
  }
struct_name_array[];
//+------------------------------------------------------------------+
void OnStart()
  {
   ArrayResize(struct_name_array,5);
   for(int i=0;i<5;i++)
     {
      struct_name_array[i].x = i;
      struct_name_array[i].y = i*100;
     }
   Func(struct_name_array);
   for(int i=0;i<5;i++)
     {
      printf("%s : s[%d].x = %d , s[%d].y = %d",__FUNCTION__,i,struct_name_array[i].x,i,struct_name_array[i].y);
     }
  }
//+------------------------------------------------------------------+
void Func(StructName &s[])
  {
   for(int i=0;i<ArraySize(s);i++)
     {
      printf("%s : s[%d].x = %d , s[%d].y = %d",__FUNCTION__,i,s[i].x,i,s[i].y);
      s[i].x*=33;
      s[i].y*=12;
     }
  }
//+------------------------------------------------------------------+
 

你好!

我意识到我已经用我的愚蠢问题惹恼了这里的很多人,所以请宽大处理以下问题,并仍然解释这里有什么问题。

        if((op1-lo1)>50 && (cl1-lo1)<10)
        {  Alert("VertLine");
        string obj_name="VertLine";
        datetime time=Time[0];
        color col = clrGreen; 
        ObjectCreate(0,obj_name,OBJ_VLINE,0,time,0,0,0);
        ObjectSetInteger(0,obj_name,OBJPROP_COLOR,col);
        }

警报已发出,但没有垂直线。原因是什么?

 
novichok2018:

你好!

我意识到我已经用我的愚蠢问题惹恼了这里的很多人,所以请宽大处理以下问题,并仍然解释这里有什么问题。

显示了警报,但没有垂直线。原因是什么?

我已经明白了原因,甚至提到了这个论坛。我想我明白,我已经画了一条线。为了画其他的线,我必须擦掉这一条。