Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1363

 
Mikhail Toptunov #:

Can you tell me how to organise an analogue of calculation of prev_calculated, I can't figure it out. I'm having a hard time navigating classes.


BarsCalculated-1?
 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CNewBar::PrevCalculated(void)
  {
   int pc=(int)(this.RatesTotal()-this.m_rt);
   return(pc);
  }
//+------------------------------------------------------------------+
//| CNewBar IsNewBar Основная функция класса                         |
//+------------------------------------------------------------------+
bool CNewBar::IsNewBar(void)
  {
   datetime tm=this.Time();
   Print("this.m_time ",this.m_time," tm ",tm," this.m_pc ",this.m_pc," this.m_rt ",this.m_rt);
   if(tm==0)
      return false;
   if(tm!=this.m_time)
     {
      //--- определяем время
      this.m_time=tm;
      //--- определяем кол-во
      this.m_pc=this.PrevCalculated();
      this.m_rt=(int)this.RatesTotal();
      return true;
     }
   this.m_pc=(int)this.m_rt;
   return false;
  }

That's how I did it, if you can suggest a more sensible method, that would be lovely!!!

 
Fast235 #:

It's more resource intensive for the system, but more efficient than I did, I think, in terms of sustainability.

 
Mikhail Toptunov #:

That's how I did it, if you can suggest a more sensible method, that would be wonderful!!!

Bullshit the logic is broken. The below is more correct.




class CNewBar : public CObject
  {
private:
   string            m_symbol;
   ENUM_TIMEFRAMES   m_timeframe;
   datetime          m_time;
   int               m_rt;
   int               m_pc;
   datetime          Time(void);
   int               PrevCalculated(void);
   int               RatesTotal(void);
   string            Symbol(void)         { return this.m_symbol;    }
public:
   ENUM_TIMEFRAMES   Timeframe(void)      { return this.m_timeframe; }
   datetime          GetTime(void)        { return this.m_time;      } //  Возвращает время последнего обращения
   int               GetRatesTotal(void)  { return this.m_rt;        }
   int               GetPrevCalculated(void) {return this.m_pc;       }
   bool              IsNewBar(void);                                   //  Основная функция класса
                     CNewBar(const string symbol,const ENUM_TIMEFRAMES timeframe);
                    ~CNewBar(void) {;}
  };
//+------------------------------------------------------------------+
//| Кол-во отработанных                                              |
//+------------------------------------------------------------------+
int CNewBar::PrevCalculated(void)
  {
  int _rt=this.RatesTotal();
  int rt=_rt-(_rt-this.m_rt);
   return(rt < 0 ? 0 : rt);
  }
//+------------------------------------------------------------------+
//| CNewBar IsNewBar Основная функция класса                         |
//+------------------------------------------------------------------+
bool CNewBar::IsNewBar(void)
  {
   datetime tm=this.Time();
   int      rt=this.RatesTotal();
   if(tm==0)
      return false;
   if(tm!=this.m_time)
     {
      //--- определяем время
      this.m_time=tm;
      //--- определяем кол-во
      this.m_pc=this.PrevCalculated();
      this.m_rt=rt;
      return true;
     }
     this.m_pc=rt<0 ? 0 : rt;
   return false;
  }

But here's why the values are zero at startup, marked with a yellow bar.

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   for(int i=1; i<2; i++)
     {
      ENUM_TIMEFRAMES n_period=(ENUM_TIMEFRAMES)GetPeriodEnumerator((uchar)i);
      CNewBar *nb = new CNewBar(Symbol(), n_period);
      if(nb==NULL)
         continue;
      if(!list_new_bar.Add(nb))
        {
         delete nb;
         continue;
        }
      Print(nb.IsNewBar(), " ***** ", Symbol(), " ***** ", nb.Timeframe()," RatesTotal ",nb.GetRatesTotal()," Calculated ",nb.GetPrevCalculated());
     }
//--- create timer
   EventSetTimer(1);

//---
   return(INIT_SUCCEEDED);
  }
 
Mikhail Toptunov #:

Bullshit logic is broken. The following is more correct.

But here's why the values are zero at startup, marked with a yellow bar.

are you just the New Bar?

 
Fast235 #:

are you just the New Bar?

I need the parameters to implement the strategy

RatesTotal
PrevCalculated

And the new bar is like a bonus with the ability to go through all the TFs

I also need to calculate the price for each bar

//+------------------------------------------------------------------+
//| Расчет цены                                                      |
//+------------------------------------------------------------------+
int CNewBar::PriceHL2(void)
  {
   int res=ArrayResize(this.m_pr_hl2,this.m_rt);
   for(int b=this.m_pc; b<this.m_rt; b++)
      m_pr_hl2[b]=MathAbs((iHigh(this.m_symbol,this.m_timeframe,b) + iLow(this.m_symbol,this.m_timeframe,b))/2);
   return(res);
  }

I cannot pull the array out of the Expert Advisor, although the values appear during debugging



How to correctly fill it in the Expert Advisor? I need it for calculation


 
Hi all, can you please tell me the difference between a trading robot and a trading advisor?
 
Daniil Osipov #:
Hi all, can you please tell me the difference between a trading robot and a trading advisor?

A play on words.

 
How can an indicator know its subwindow number?
For example, to write or draw something in its subwindow.
I couldn't find an explicit function like "IndicatorGetInteger".
 
Evgeny Dyuka #:
How can an indicator know its subwindow number?
For example, to write or draw something in its subwindow.
I haven't found any explicit function like "IndicatorGetInteger".
ChartWindowFind
Документация по MQL5: Операции с графиками / ChartWindowFind
Документация по MQL5: Операции с графиками / ChartWindowFind
  • www.mql5.com
ChartWindowFind - Операции с графиками - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
Reason: