Questions from Beginners MQL5 MT5 MetaTrader 5 - page 515

 
-Aleks-:

Alternatively

if (StatTime==1)

 Time=iTime(NULL,1440,0);

 StatTime=0;

 }

       if(Time!=iTime(NULL,1440,0))

           {

  StatTime=1;

           } 

I think this would be more interesting

variant 1

bool NevDay()
  {
   static datetime StatTime;

   if(StatTime!=iTime(NULL,PERIOD_D1,0))
     {
      StatTime=iTime(NULL,PERIOD_D1,0);
      return(true);
     }
   return(false);
  }

version 2

bool NevDay()
  {
   static int den;

   if(den!=Day())
     {
      den=Day();
      return(true);
     }
   return(false);
  }
 

Hello!

There is a code of functions "newt" and "dlt" which solve some algorithm. Please tell me, what is this algorithm? What problem do these functions solve?

int    period=150;
int    shift_1=10;
double shift_2=3.0;
int    history=300;
double hpf[];
double HPF[];
//+------------------------------------------------------------------+
init()
  {
   SetIndexBuffer(0,HPF);
   ArrayResize(hpf,period);
   return(0);
  }
//+------------------------------------------------------------------+
start()
  {
   for(int bar=history; bar>=0; bar--)
     {
      for(int i=period-1;i>=0;i--)
         hpf[i]=Close[i];

      HPF[bar]=newt(hpf,shift_1,shift_2);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double newt(double x[],int pos,double n)
  {
   double r=x[pos],k=1;
   int l=MathCeil(n),i;
   if(pos+l>=ArraySize(x)) l=ArraySize(x)-pos-1;
   if(n==0) return(r);
   if(n<0) return(EMPTY_VALUE);
   for(i=1; i<=l; i++)
     {
      k*=n/i;
      r+=k*dlt(x,pos,i);
     }
   return(r);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double dlt(double x[],int pos,int d)
  {
   double r=0;
   int i, k=1, pod=pos+d, l=d>>1;
   if(pos>=ArraySize(x)) return(EMPTY_VALUE);
   if(pos+d>=ArraySize(x)) return(0);
   if(d%2>0)
      for(i=0; i<=l; i++,pos++,pod--)
        {
         r+=k*(x[pos]-x[pod]);
         k*=i-d;
         k/=i+1;
        }
   else
     {
      for(i=0; i<l; i++,pos++,pod--)
        {
         r+=k*(x[pos]+x[pod]);
         k*=i-d;
         k/=i+1;
        }
      r+=k*x[pos];
     }
   return(r);
  }
 

I'm asking for help from the community.

// MQL4
// Последняя известная цена продажи (запрашиваемая цена) текущего инструмента. Для обновления необходимо использовать функцию RefreshRates().
Ask 

// MQL5
// 1
Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK)      // Возвращает лучшее предложение на покупку (Так в справочнике MQL5)
// 2
SymbolInfoTick(_Symbol,last_tick))              // Возвращает текущие цены  для указанного символа в переменной типа MqlTick
Ask = last_tick.ask								

What is the difference between the Ask value obtained in two MQL5 functions?
Which of these functions returns a value similar to Ask from MQL4?

 
MikeZv:

I'm asking for help from the community.

What is the difference between the Ask value obtained in two MQL5 functions?
Which of these functions returns a value similar to Ask from MQL4 ?

Both examples work

 
MikeZv:

I'm asking for help from the community.

What is the difference between the Ask value obtained in two MQL5 functions?
Which of these functions returns a value similar to Ask from MQL4?

Before writing something (in terms of code), think about the most economical and correct way to solve the problem. In the first case, only the current Ask price is requested, while in the second case, the entire tick structure is requested. Most likely (we must measure it), the second case works much slower and if you need only ask price, there is no point in getting the structure.
 
Alexey Kozitsyn:
Before you write anything (in terms of code), think about the most resource-efficient and correct way to solve the problem. In the first case only current ask price is requested, in the second case the whole tick structure is requested. Most likely (it should be measured) the second case works much slower and if you need only ask price, there is no point in getting the structure.
I'm rewriting my Expert Advisor from MT4 to MT5. First of all, I need to know how to get the structure called Ask in MQL4. I will think about performance issues later. :)
 
MikeZv:
I'm currently rewriting my Expert Advisor from MT4 to MT5. First of all I need to know how to get an Ask in MQL4. I will think about performance issues later. :)
I'm sorry, I didn't understand your question straight away. I wrote that these two variants work in MT4, while in MT5 they are analogs of ask and MarketInfo(_Symbol,SYMBOL_ASK); from old MT4
 
Sergey Gritsay:
Oh sorry I didn't understand your question right away, I wrote that both of these variants work in MT4, and in MT5 they are analogs of ask and MarketInfo(_Symbol,SYMBOL_ASK); from old MT4

There were two variants from MQL5 ...
And they are analogues of "ask and MarketInfo(_Symbol,SYMBOL_ASK)from old MT4", did I understand you correctly ?

 
MikeZv:

There were two variants of MQL5 ...
And they are analogous to "ask and MarketInfo(_Symbol,SYMBOL_ASK)from old MT4", did I understand you correctly ?

Yes, that's right.

 
Sergey Gritsay:
Oh sorry didn't understand your question right away, I wrote that these both work in MT4, but in MT5 they are analogs of ask and MarketInfo(_Symbol,SYMBOL_ASK); from old MT4
SymbolInfoDouble(Symbol(),SYMBOL_ASK);

Reason: