初学者的问题 MQL5 MT5 MetaTrader 5 - 页 1363

 
Mikhail Toptunov #:

你能告诉我如何组织计算prev_calculated的类似物吗,我想不出来了。我在浏览课程时遇到了困难。


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;
  }

我就是这样做的,如果你能建议一个更合理的方法,那就太好了!!。

 
Fast235 #:

这对系统来说是更多的资源消耗,但比我做的更有效,我想,在可持续性方面。

 
Mikhail Toptunov #:

我就是这样做的,如果你能建议一个更合理的方法,那就太好了!!。

胡说八道,这个逻辑已经坏了。下面的说法更正确。




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;
  }

但这里是为什么在启动时数值为零,用黄条标记。

//+------------------------------------------------------------------+
//| 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 #:

胡说八道的逻辑被打破了。下面的说法更正确。

但这里是为什么在启动时数值为零,用黄条标记。

你只是新酒吧的人吗?

 
Fast235 #:

你只是新酒吧的人吗?

我需要参数来实现该策略

RatesTotal
PrevCalculated

而新的酒吧就像一个奖金,可以通过所有的TFs。

我还需要计算每条的价格

//+------------------------------------------------------------------+
//| Расчет цены                                                      |
//+------------------------------------------------------------------+
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);
  }

我无法从专家顾问中拉出数组,尽管在调试过程中出现了这些值



如何在专家顾问中正确填写它? 我需要它来计算


 
大家好,请告诉我交易机器人和交易顾问的区别?
 
Daniil Osipov #:
大家好,请告诉我交易机器人 和交易顾问区别

一个文字游戏。

 
一个指标怎样才能知道它的子窗口编号?
例如,在其子窗口中写或画东西。
我找不到像 "IndicatorGetInteger "这样明确的函数。
 
Evgeny Dyuka #:
一个指标怎样才能知道它的子窗口编号?例如,在其子窗口中写或画东西。我没有发现任何像 "IndicatorGetInteger "这样的显式函数。

查找图表窗口
Документация по MQL5: Операции с графиками / ChartWindowFind
Документация по MQL5: Операции с графиками / ChartWindowFind
  • www.mql5.com
ChartWindowFind - Операции с графиками - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5