Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1023

 

How do I get the data of iMA indicator on "zero bar", i.e. to get the indicator value on the current bar?

If I do so

int OnInit()
{handle.MA_CHART=iMA(_Symbol,_Period,period_MA_CHART,0,Signal_MA_Method,Signal_MA_Applied);}

void OnTick()
{CopyBuffer(handle.MA_CHART, 0, 0, 3, ind_date.MA_CHART);}


When calling

ind_date.MA_CHART[0]

I get the data of the previous bar, not the current one.

 
Yury Smagin:

How do I get the data of iMA indicator on "zero bar", i.e. to get the indicator value on the current bar?

If I do so


When calling

I get the data of the previous bar, not the current one.

The array needs

ArraySetAsSeries(ind_date.MA_CHART,true);

and then the element with index "0" in the array will correspond to the RIGHT bar in the chart.

 
Vladimir Karputov:

The array must be

and then the element in the array with index "0" will correspond to the very RIGHT bar on the graph.

Thank you!
 
Yury Smagin:

How do I get the data of iMA indicator on "zero bar", i.e. to get the indicator value on the current bar?

If I do so


When calling

I get the data of the previous bar, not the current one.

As in that movie, "I have some doubts...". Aren't you using my Expert Advisor for studying?

You don't have to flip the array. It's enough to take the value of the second index of the array.

ind_date.MA_CHART[2]
 

OBJPROP_BACK

Tried it both ways. It doesn't work. I do not understand how it works at all.

Irrespective of the value, the objects are simply displayed in the order they were formed - the last one is higher.

And how do I adjust the level (layer) of an object if there are more than two of them? Maybe there are some other settings? Please, tell me if you know.

 
Alexey Viktorov:

As in that movie, "I have doubts..." Isn't that my advisor you're using to study:

You don't have to flip the array. Just take the value of the second index of the array.

Thank you!

 

Good day to you all))


Could you please tell me why there is a difference in results?

//+------------------------------------------------------------------+
//|  exponential moving average multytimeframes   ДЛЯ БУФЕРА         |
//+------------------------------------------------------------------+
void CalculateExponentialMA(int rates_total,int prev_calculated,int begin,const double &price[])
  {
   int    i,limit;
   double SmoothFactor=2.0/(1.0+period_ma);
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
     {
      limit=period_ma+begin;
      ExtLineBuffer[begin]=price[begin];
   for(i=begin+1;i<limit;i++)
         ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor);
     }
   else limit=prev_calculated-1;
//--- main loop
   for(i=limit;i<rates_total && !IsStopped();i++)
      ExtLineBuffer[i]=price[i]*SmoothFactor+ExtLineBuffer[i-1]*(1.0-SmoothFactor);
//---
  }
//+------------------------------------------------------------------+
//|  exponential moving average       ДЛЯ ТОЧКИ                      |
//+------------------------------------------------------------------+
void CalculateEMA(int periodMA,int bgn)
  {
 int i,lmt=periodMA+bgn+1;
 double SmoothFactor=2.0/(1.0+periodMA);
   for(i=0;i<lmt;i++)
              BufferPrice[i]=0.0;
   switch(AppliedPrice)
     {
      case 1: BufferPrice[lmt]=iClose(NULL,Timeframes,lmt); break;
      case 2: BufferPrice[lmt]=iOpen(NULL,Timeframes,lmt);  break;
      case 3: BufferPrice[lmt]=iHigh(NULL,Timeframes,lmt);  break;
      case 4: BufferPrice[lmt]=iLow(NULL,Timeframes,lmt);   break;
   default :  BufferPrice[lmt]=iClose(NULL,Timeframes,lmt); break;
     }
   for(i=lmt-1;i>=0;i--)
   switch(AppliedPrice)
     {
      case 1: BufferPrice[i]=iClose(NULL,Timeframes,i)*SmoothFactor+BufferPrice[i+1]*(1.0-SmoothFactor); break;
      case 2: BufferPrice[i]=iOpen(NULL,Timeframes,i)*SmoothFactor+BufferPrice[i+1]*(1.0-SmoothFactor);  break;
      case 3: BufferPrice[i]=iHigh(NULL,Timeframes,i)*SmoothFactor+BufferPrice[i+1]*(1.0-SmoothFactor);  break;
      case 4: BufferPrice[i]=iLow(NULL,Timeframes,i)*SmoothFactor+BufferPrice[i+1]*(1.0-SmoothFactor);   break;
   default :  BufferPrice[i]=iClose(NULL,Timeframes,i)*SmoothFactor+BufferPrice[i+1]*(1.0-SmoothFactor); break;
     }
      MA=NormalizeDouble(BufferPrice[bgn],_Digits);
  }
//+------------------------------------------------------------------+

QUESTION: what did I write wrong in the second version of the MA calculations ?

Thank you)))

 
When optimising, are graphical objects constructed so that they can be read off the graph?
 
Aleksey Vyazmikin:
When optimising, are graphical objects constructed so that they can be read from the graph?

No

 
Artyom Trishkin:

No

Badly...