Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1515

 
AkaEdie #:

... and the result, what does red and dark green mean?

It's probably just a colour scale for sets of parameters based on good - bad results. The greener and darker the better.

 

I've been sitting for over an hour and I can't solve the puzzle.

Is the terminal broken, or do I have a problem?


Doesn't get data from any other timeframe, only from the one specified when creating the MA

int OnInit()
{
  hMA1=iMA(Symbol(), PERIOD_H1, 5, 0, MODE_EMA, PRICE_CLOSE);
  if(hMA1<0) {
    Alert("ERROR handle MA");
    return(INIT_FAILED);
  }
  return(INIT_SUCCEEDED);
}
int hMA1=-1;
double buf[1];
--
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[])

{
  Print(  CopyBuffer(hMA1,0,10,1,buf),"=", buf[0]  );
 ...

--

Printing on any other timeframe

--

Printing onH1, no problems


 

Which helps get the data from the MA

No ticks, it's the weekend, so that's the only way

--

Now the question arises?

How to get data from another timeframe not on the next ticks, but on the first one, as the native timeframe, on which the indicator is created, gets it?

 

I've done it this way

when no data is received, update the chart

ChartSetSymbolPeriod(0,Symbol(),PERIOD_CURRENT);

But this is not even a crutch solution, but a complete amateurishness

How to make a normal solution, and why does it work like this?

Как получить данные с другого таймрейма не на следующих тиках, а на первом, как это получат родной таймфрейм, на котором создан индикатор?
 
Vitaly Muzichenko #:
Как получить данные с другого таймрейма не на следующих тиках, а на первом, как это получат родной таймфрейм, на котором создан индикатор?

How to make a normal solution, and why is this the case?

Perhaps, request this data in OnInit() so that it would be ready by the first tick.

 
Vitaly Muzichenko #:

I did it this way

when no data is received, update the chart

But this is not even a crutch solution, but a complete amateurishness

How to make a normal solution, and why is it like this?

Take a look at this one.

bool f = false;
/****************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[])

{
  if(!f)
  {
   f = true;
   return 0;
  }
 
Print(CopyBuffer(hMA1,0,10,1,buf),"=", buf[0]);
 return rates_total;
}/*****************************************************************/

It will probably be more expensive to run synchronisation.

 
Alexey Viktorov #:

Check this one out.

It will probably be more expensive to run synchronisation.

Thanks, but the question is about a closed market - there are no ticks, and OnCalculate triggers once when switching timeframe

I did it this way and it works, but it's not really a normal condition

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[])
{
  if(rates_total-prev_calculated==0)
    return(rates_total);
  int res=Start(rates_total); // если "0" - то данные от МА не получены
  if(fl && res==0) {
    ChartSetSymbolPeriod(0,Symbol(),PERIOD_CURRENT);
    ChartRedraw();
    fl=false;
    return(0);
  }
  return(rates_total);
}
 
Vitaly Muzichenko #:

Thanks, but the question is about a closed market - there are no ticks and OnCalculate is triggered once when switching timeframe

I did it this way and it works, but it's not really a normal condition

Vitaly, would it be more useful to check?

 
Alexey Viktorov #:

Vitaly, would it be more useful to check?

Checked.

Your design is identical to mine, but without ChartSetSymbolPeriod and checking that the MA did not return a result

It starts working only like this

bool f = false;
/****************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[])

{
  if(!f)
  {
   f = true;
   ChartSetSymbolPeriod(0,Symbol(),PERIOD_CURRENT);
   return 0;
  }
 
Print(CopyBuffer(hMA1,0,10,1,buf),"=", buf[0]);
 return rates_total;
}/*****************************************************************/
 

Check.

Your design is identical to mine, but without ChartSetSymbolPeriodand checking that the MA did not return a result

It only starts working like this

bool f = false;
/****************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[])

{
  if(!f)
  {
   f = true;
   ChartSetSymbolPeriod(0,Symbol(),PERIOD_CURRENT); // только так работает
   return 0;
  }
 
Print(CopyBuffer(hMA1,0,10,1,buf),"=", buf[0]);
 return rates_total;
}/*****************************************************************/