Questions from Beginners MQL5 MT5 MetaTrader 5 - page 265

 
C-4:
What do you mean by 'align'? Normalize the mantissa by the number of decimal places? - That's what the NormalizeDouble function is for. If something else, describe it in more detail.

At input any positive double, at output rounded to the real price that can be at this instrument.

If the price step is 0.25, then round to 0.25. Sort of like this:

double RoundPrice(const double price)
{
   if(price<=0) return(-1);
   double tick_size=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE);
   double p=round(price/tick_size);
   return(NormalizeDouble(p*tick_size,_Digits));
}

But that said, if there is an offset (like 0.13; 0.38; 0.63; 0.88), then it counts. Then:

on input 1.0 on output 1.13;

1.25 as input and 1.38 as output;

1,5 ---> 1,63...

At the API level, this could be coded into a couple of assembly language commands and it's clearly a basic function. I thought there was one =/

 
how to make an update to the new build via Live update. Where is the Live update
 
Newalligator:
how to make an update to the new build via Live update. Where is this Live update
You should open a demo account on the MetaQuotes-Demo server and connect to it occasionally to check the updates. How to open a demo account on the MetaQuotes-Demo server
 
Thanks for the reply, I trade live and MT5 is always on. I'm not sure if it will update automatically, but if not, where is the live update?
 
Newalligator:
Thanks for the reply, I trade live and MT5 is always on. If the program itself prompts me to update, it's good, but if not, where is this Live update?
When you connect to your account at the MetaQuotes-Demo server, the MetaTrader will check for updates automatically. If there is an update, it will automatically download the new version.
 

Good day to you all! There is a problem - I can't use the readings of another custom indicator in a custom indicator. I am almost sure I am doing it wrong but I will paste the code anyway:

int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) {
   
   if(rates_total < iPeriod ) {
      return(0);
   }
   
   int first;
   
   if ( prev_calculated == 0 ) {
      first = iPeriod + begin;
   } else {
      first = prev_calculated - 1;
   }
      
   // Пользовательский индикатор ROC для EURUSD   
   double aRocRatesEURUSD[];
   int iRocHandleEURUSD = iCustom("EURUSD", 0, "Examples\\ROC");   
   CopyBuffer(iRocHandleEURUSD, 0, 0, rates_total, aRocRatesEURUSD);

   for(int bar = first; bar < rates_total; bar++) {

In this code, the buffer of the Rate Of Changes indicator(aRocRatesEURUSD) is not available. I don't understand how to connect this indicator correctly, please help me to understand it.

 
jommerbot:

Good day to you all! There is a problem - I can't use the readings of another custom indicator in a custom indicator. I am almost sure I am doing it wrong but I will paste the code anyway:

In this code, the buffer of the Rate Of Changes indicator(aRocRatesEURUSD) is not available. I cannot understand how to connect this indicator correctly, please help me to understand it.

Indicator handles must be declared in OnInit():

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
// Пользовательский индикатор ROC для EURUSD   
   double aRocRatesEURUSD[];
   int iRocHandleEURUSD = iCustom("EURUSD", 0, "Examples\\ROC");   
  }
Otherwise, it turns out that you create a new custom indicator each time you call OnCalculate().
 
barabashkakvn:

Indicator handles should be declared in OnInit():

This doesn't work either. The buffer array ends up either empty or full of left-handed values.
 
jommerbot:
This does not work either. As a result, the array with the buffer is either empty or full of left values.
Nevertheless, it is correct to declare the indicators handles in OnInit(). Another matter is why do you need to write each time a new tick comes (the OnCalculate() function)
rates_total,      // размер входных таймсерий

to the buffer

aRocRatesEURUSD

? This can really slow down the terminal. And besides, this is a very deep story.

I think you will find it interesting to read the articleThe Principles of Economical Recalculation of Indicators

And also read the help on the OnCalculate() function.

 

OK, even in the simplest case it doesn't work:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  Red

double ExtLineBuffer[];   
int iRocHandleEURUSD;  
int iPlotShift = 0;
int iPeriod = 6;
 
void OnInit() {
   SetIndexBuffer(0, ExtLineBuffer, INDICATOR_DATA);
   PlotIndexSetInteger(0, PLOT_SHIFT, iPlotShift);
   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, iPeriod - 1);
   
   int iRocHandleEURUSD = iCustom("EURUSD", 0, "Examples\\ROC");    
   if( iRocHandleEURUSD == INVALID_HANDLE )
   {
      Print("Не удалось получить хендл индикатора ROC EURUSD");  
   }
}

int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) {
   
   if(rates_total < iPeriod ) {
      return(0);
   }
   
   int first;
   double aRocRatesEURUSD[]; 
   
   if ( prev_calculated == 0 ) {
      first = iPeriod + begin;
   } else {
      first = prev_calculated - 1;
   }
   
   for(int bar = first; bar < rates_total; bar++) {
      CopyBuffer(iRocHandleEURUSD, 0, bar, 1, aRocRatesEURUSD);
      Print(aRocRatesEURUSD[ 0 ]);   
      ExtLineBuffer[ bar ] = NormalizeDouble(aRocRatesEURUSD[ 0 ], SYMBOL_DIGITS);
   }
     
   return(rates_total);
}

I don't understand where my mistake is. Copying the same indicator buffer in EA and script works, but not in indicator. The indicator handle is initialised without error.

Reason: