Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 545

 
Forexman77:
If in the indicator itself in the Expert Advisor

how does the indicator code recognise the transmitted parameters and the names are different?

But everything is as you said. Checked again with the script)


The variable(s) in the calling program can be named as you want and its name is not related to the variable name in the indicator, they are different variables, and they are called from different terminal threads.

The indicator is called based on its name, the parameters are passed for it during each call from the 4th position and then the iCustom() parameters.

If the variable per1=9; is declared and iCustom() is on position 4, the indicator will be calculated with a period of 9, if you set another variable, its value will be used during the calculation. The variable that will be passed (its reference) as the first parameter of the indicator - in the fourth place iCustom() of the second one and so on.



 
GSB:

The variable(s) in the calling program can be named as you like, its name is not related to the variable name in the indicator, they are different variables, and they are called from different terminal threads.

The indicator is called by its name, the parameters are passed to it during each call from the 4th position, and then the iCustom() parameters.

If the variable per1=9 is declared and iCustom() is positioned at 4, the indicator will be calculated with a period of 9; if you set another variable, its value will be used during the calculation and this applies to all parameters of the indicator, the main thing is to set them in the right order, as in the indicator itself. The variable that will be passed (its reference) as the first parameter of the indicator - the fourth iCustom() of the second one and so on.



I got it. In the textbook, it seems to be called transferring cited values.
 

I thought I should not litter the forum and have a separate topic, but I really hope for a constructive feedback on my problem, I am not moving forward without it :(.
I have tried to write various indicators, everything seems to be OK, now I have imported everything to my EA using iCustom() function. The code in the Expert Advisor:

double ma=iCustom(NULL,0,"TestMA",0,1);

The indicator itself (I wrote it for testing)

//+------------------------------------------------------------------+
//|                                                       TestMA.mq4 |
//|                                  Copyright 2014, Semyon Polyakov |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Semyon Polyakov"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
 
   SetIndexStyle(0,DRAW_LINE,EMPTY,1,clrRed);
   SetIndexBuffer(0,ExtMapBuffer1);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 counted_bars=IndicatorCounted(),
       limit;
 
   if(counted_bars>0)
      counted_bars--;
   
   limit=Bars-counted_bars;
     
   for(int i=0;i<limit;i++)
   {
      ExtMapBuffer1[i]=SimpleMA(i,20,close);
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
  
  double SimpleMA(const int position,const int period,const double &price[])
  {
//---
   double result=0.0;
//--- check position
   if(position>=0 && period>0)
     {
      //--- calculate value
      for(int i=0;i<period;i++) result+=price[position+i];
      result/=period;
     }
//---
   return(result);
  }
//+------------------------------------------------------------------+

Next, the EMPTY_VALUE thing when testing.

I.e., when we start testing, we have the start date of the EA and everything before that date iCustom gives the correct indicator values, everything after that is directly tested - EMPTY_VALUE. :(
I'm already tired to google and forum, they write about "do not look into the future", but I do not see that in the code. Where am I a fool?)

 
Semionn:

I thought I should not litter the forum and have a separate topic, but I really hope for a constructive feedback on my problem, I am not moving forward without it :(.
I have tried to write various indicators, everything seems to be OK, now I have imported everything to my EA using iCustom() function. The code in the Expert Advisor:

The indicator itself (I wrote it for testing)

Next, the EMPTY_VALUE thing when testing.

I.e., when we start testing, we have the start date of the EA and everything before that date iCustom gives the correct indicator values, everything after that is directly tested - EMPTY_VALUE. :(
I'm already tired to google and forum, they write about "do not look into the future", but I do not see that in the code. Where am I a fool?)

The error seems to be in the Expert Advisor's code, why don't you use a debugger? Set checkpoints, see variable values, and see if the indicator is called, what is before and after your date
 
GSB:
The error seems to be in the Expert Advisor's code, why don't you use a debugger? Set checkpoints, see variable values, and see if the indicator is called, what is before and after your date

The debugger can only be used in demo account mode, not in testing, besides I wrote - the indicator is called, works and returns values, even correct, but only before the specified date (start date of testing). I output the values of the variables in the EA, that's why I say that everything is good at first, and then EMPTY_VALUE
 
Semionn:

The debugger can only be used in demo account mode, not in testing, besides I wrote - the indicator is called, works and returns values, even correct, but only until the specified date (testing start date). I output the values of the variables in the EA, that's why I say that everything is good at first, and then EMPTY_VALUE


Have you read carefully how to track new bars in custom indicators?

[QUOTE]The first rates_total parameter contains the number of bars available to the indicator for calculation and corresponds to the number of bars available in the chart.

Note the connection between the value returned by OnCalculate() and the second input parameter prev_calculated. The prev_calculated parameter in the function call contains a value returned by OnCalculate() on previous call. This allows for economical algorithms for calculating the custom indicator in order to avoid repeated calculations for those bars that haven't changed since the previous call of this function.

For this, it is usually enough to return the value of the rates_total parameter, which contains the number of bars in the current function call. If since the last call of OnCalculate() price data have changed (a deeper history has been pumped or history blanks have been filled), then the value of the input parameter prev_calculated will be set to zero by the terminal. [/QUOTE]

 

You need to find the average of the one-day moments over 20 days and then find the average of the 20-day moments over five days.

Finding the 20-day average was not a problem. But Idon't knowhow to getthe five-day averagefrom this average .

#property indicator_separate_window
#property indicator_buffers 1
#property  indicator_color1 Lime

//--- input parameters
extern int       Period_MA_1=1;
extern int       p          =20;
//--- buffers
double ExtMapBuffer1[];
double val20[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   IndicatorDigits(Digits+1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    int counted_bars=IndicatorCounted(),                      
    limit;
    double momentum20;
   if(counted_bars>0)
      counted_bars--;  
   limit=Bars-counted_bars;
    
   for(int i=0;i<limit;i++)
   {
      momentum20=0;
      ArrayInitialize(val20,0);      
      for(int k=p;k>=0;k--)
      {
      ArrayResize(val20,p);
      val20[k]=Close[i+k]-Close[i+k+Period_MA_1];
      momentum20=momentum20+val20[k];
      }
      momentum20=momentum20/p;
      ExtMapBuffer1[i]=momentum20;
   }
   return(0);
  }
 
Forexman77:

You need to find the average of the one-day moments over 20 days and then find the average of the 20-day moments over five days.

Finding the 20-day average was not a problem. But Idon't knowhow to getthe five-day averagefrom this average .



//+------------------------------------------------------------------+
//|                                                   ForexMan77.mq4 |
//|                                            Copyright 2014, Vinin |
//|                                                    vinin@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, Vinin"
#property link      "vinin@mail.ru"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 3
#property  indicator_color1 Lime
#property  indicator_color2 Yellow
#property  indicator_color3 Red

//--- input parameters
extern int       Period_MA_1=1;
extern int       p2          =20;
extern int       p3          =5;
//--- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted(),
   i,limit1,limit2,limit3;
   limit1=Bars-counted_bars-1;
   limit2=limit1;
   limit3=limit2;
   if(limit1>0) 
     {
      limit1=Bars-Period_MA_1-1;
      limit2=limit1-p2;
      limit3=limit2-p3;
     }

   for(i=limit1;i>=0;i--) ExtMapBuffer1[i]=iMomentum(NULL, 0, Period_MA_1, PRICE_CLOSE, i);
   for(i=limit2;i>=0;i--) ExtMapBuffer2[i]=iMAOnArray(ExtMapBuffer1, 0, p2, 0, MODE_SMA,i);
   for(i=limit3;i>=0;i--) ExtMapBuffer3[i]=iMAOnArray(ExtMapBuffer2, 0, p3, 0, MODE_SMA,i);

   return(0);
  }
//+------------------------------------------------------------------+
 

Help

int OnInit()
{
   EventSetTimer(60);
   Print(GetLastError());

   return(INIT_SUCCEEDED);
}

Timer doesn't work, returns fouls and error 4051

Or should it not work in the tester?

 

Dear GURU ! Help with the Expert, there are 2 compilation errors - 'MarketInfo' - syntax error and not all control paths return a value

I'm begging you - I don't have the brains for it.

int init() {
gd_348 = MarketInfo(Symbol(), MODE_SPREAD) * Point;
switch MarketInfo(Symbol(), MODE_MINLOT) {
case 0.001:
gd_256 = 3;
break;
case 0.01:
gd_256 = 2;
break;
case 0.1:
gd_256 = 1;
break;
case 1.0:
gd_256 = 0;
}
return (0);
}

int deinit() {
return (0);
}

Decompiled deleted
Reason: