Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 943

 

Guys, please help me in the code to change the TF d1/week to any other.

I know how to change it to H1 or minutes.

Interested in how to change to 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()
//+------------------------------------------------------------------+
 
Need to pause the indicator for a while, but the Sleep() function, as stated in the help, cannot be called from the custom indicator... Is there any other way?
 
Yevhenii Levchenko:
I need to pause the indicator for some time, but the Sleep() function, as mentioned in the help, cannot be called from the custom indicator... Are there other ways?

output by condition in OnCalculate() without calculating indicator values - easiest is the tick counter, a bit more complicated is to use a timer, it works in indicators

 
Igor Makanu:

output by condition in OnCalculate() without calculating indicator values - easiest is the tick counter, a bit more complicated is to use a timer, it works in indicators

Thank you!

I have done it with timer. This option seemed easier to me...

 
Yevhenii Levchenko:

Thank you!

Did it with a timer. This option seemed easier to me...

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:

I'd completely forgotten about the static variables... Thanks :)

And if you declare an ordinary variable as a global variable, it will in fact be the same as a static variable in a certain sense? In the sense, it will be available to change from all places in the program?

 

Hello.

Can you please tell me if it's possible to pass a dynamic array of structure type by reference to a function?

For example, to pass struct_name_array[] array to Func() to process and fill it there:

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

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

How exactly is the transfer handled, if at all possible? How are the function parameters formatted? I can't seem to use C++ guides.

Thank you.

 
Mikhail Sobolev:

For example, pass struct_name_array[] array to Func() to be processed and filled there:

//+------------------------------------------------------------------+
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;
     }
  }
//+------------------------------------------------------------------+
 

Hello!

I realise I've already annoyed a lot of people here with my stupid questions, so please be lenient with the following and still explain what's wrong here:

        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);
        }

The alert is issued, but there is no vertical line. What's the reason?

 
novichok2018:

Hello!

I realise that I've already annoyed a lot of people here with my stupid questions, so please be lenient with the following and still explain what's wrong here:

The alert is issued, but there is no vertical line. What's the reason?

I have already understood the reason, even the very reference to the forum. I think I understood that I had already drawn one line. In order to draw other lines, I have to erase this one.

Reason: