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

 
HELLO PEOPLE ! Help PLEASE have an informer, it needs to be REMOVED ... Can I make it to count the net profit, without swaps, commissions? Much obliged in advance
Files:
 
ANDREY:

Good day all!
Question about for() statement in mql4. The loop header contains a sequential decrease or increase of some variable value

for(int A=14; A>=0;A--) or for(int A=0; A<14;A++) or for(int A=0; A<14;A=+2) The sizes of A variable increase , or decrease are assumed to be always the same in the given examples 1 or 2.

QUESTION: If A variable is a timeframe value (1 (minute),5,15,30,60,240,1440), it is obvious that the sizes of increasing or decreasing this variable cannot be equal. In this case, how to format the for header so that variable A starts with 1 and then is incremented at each iteration by the required number of minutes, non-uniformly.

The example with variable A is a special case. In general, how do I format a loop if the change in the variable in the loop header should be done non-uniformly at the desired intervals.
Or is there some other operator to be used for these cases? But as it seems to me other operators are very bulky in comparison with for. Please help me to solve my problem exactly with the help of for statement , and exactly with its header. Because to solve my problem inside of the body of for statement , of course, you can use if statements, but it will be very cumbersome andfor statementwill have to do 1440 iterations for the sake of filtering 7 correct values.
Thank you.

There is an error here. It should be for(int A=0; A<14;A+=2)

The easiest thing I can think of is to put the periods into the array

ENUM_TIMEFRAMES per[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1};
/********************Script program start function*******************/
void OnStart()
 {
  for(int i = 0; i < ArraySize(per); i++)
   {
    Print(EnumToString(per[i]));
   }
 }/******************************************************************/

/*****************************End program****************************/


 
Alexey Viktorov:

The simplest thing that comes to mind is to score the periods in an array

Thanks, I could use it too)

 
Alexey Viktorov:

There is an error here. It should be for(int A=0; A<14;A+=2)

The easiest thing I can think of is to store the periods in an array


Thanks a lot for the tip. It turned out to be much simpler than I thought.
I don't understand only one thing. The name of the array is per. And ENUM_TIMEFRAMES is an identifier of a variable type? I haven't found such an identifier in mql4 Reference. There are only

Перечисления - Целые типы - Типы данных - Основы языка - Справочник MQL4
Перечисления - Целые типы - Типы данных - Основы языка - Справочник MQL4
  • docs.mql4.com
Перечисления - Целые типы - Типы данных - Основы языка - Справочник MQL4
 
ANDREY:

Thank you very much for the tip. It turned out to be a lot easier than I thought.
Only one thing I didn't understand. The name of the array per. And ENUM_TIMEFRAMES is an identifier of the variable type? I haven't found such an identifier in mql4 Reference. There are only

here

Периоды графиков - Константы графиков - Константы, перечисления и структуры - Справочник MQL4
Периоды графиков - Константы графиков - Константы, перечисления и структуры - Справочник MQL4
  • docs.mql4.com
Периоды графиков - Константы графиков - Константы, перечисления и структуры - Справочник MQL4
 
MakarFX:

here

Did I understand correctly that you sent me information about mql 5 ? Or does this information also apply to mql 4 ?

 
ANDREY:

Did I understand correctly that you sent me information about mql 5? Or does this information also apply to mql 4 ?

I corrected it.
 
MakarFX:
I've corrected it.

Thank you.

 
ANDREY:

Thank you.

A small recommendation: Get used to ENUM_TIMEFRAMES immediately and forget about numerical representation as number of minutes.

Firstly PERIOD_W1 is more informative than 10080, it's clearer that it is a week.

Secondly, in mql5 the period doesn't correspond to the number of minutes and it won't be an unnecessary problem during migration to mql5, and it's inevitable.

Well, if you really need the number of minutes in a period, then you can

int  PeriodSeconds( 
   ENUM_TIMEFRAMES  period=PERIOD_CURRENT      // период графика 
   );
Print(PeriodSeconds(PERIOD_W1)/60); // = 10080
 
Guys, help me attach an alert to the indicator.
#property copyright "Subu"
#property link      "http://www.google.com"
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_chart_window

double UpArrow[];
double DownArrow[];
extern int ShiftArrow = -2;
extern bool FilterBullBearCandle = false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY,2);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, UpArrow);
   SetIndexEmptyValue(0,0.0);
   SetIndexShift(0,ShiftArrow);
   SetIndexStyle(1, DRAW_ARROW, EMPTY,2);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, DownArrow);
   SetIndexEmptyValue(1,0.0);
   SetIndexShift(1,ShiftArrow);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit, i, counter;
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
//----
    for(i = 0; i <= limit; i++) {
      DownArrow[i] = 0;
      UpArrow[i] = 0;
   if(High[i+2]>High[i+1] && Low[i+2]>Low[i+1] && High[i+2]>High[i+3] && Low[i+2]>Low[i+3])
      if( Open[i+1]>Close[i+1] && Close[i+2] > Close[i+1])
         if(FilterBullBearCandle)
            {
               if( Open[i+2]>Close[i+2])
                  DownArrow[i] = High[i+2] +0.0003;//Low[i+2] + (High[i+2]-Low[i+2]);
             }
         else
             DownArrow[i] = High[i+2] +0.0003;//Low[i+2] + (High[i+2]-Low[i+2]);
   if(High[i+2]<High[i+1] && Low[i+2]<Low[i+1] && High[i+2]<High[i+3] && Low[i+2]<Low[i+3])
      if( Open[i+1]<Close[i+1] && Close[i+2] < Close[i+1])
          if(FilterBullBearCandle)
            {
               if( Open[i+2]<Close[i+2] ) 
                  UpArrow[i] = Low[i+2] - 0.0003;//High[i+2] - (High[i+2]-Low[i+2]);
                  
            }
         else
            UpArrow[i] = Low[i+2] - 0.0003;//High[i+2] - (High[i+2]-Low[i+2]);
            
      }
//----
   return(0);
  }
Reason: