isNewBar() не выдает правильное значение стохастика по времени в тике MQL5

Проверьте эту программу, я пытаюсь получить значения Stochastic

#include <Lib CisNewBar.mqh>

CisNewBar current_chart; // instance of the CisNewBar class:
                         //                 detect new tick candlestick

void OnTick()
{
     if (  current_chart.isNewBar() >  0 )
     {
           int stoch = iStochastic(_Symbol,PERIOD_M1,5,3,3,MODE_SMA,STO_LOWHIGH);
           double K[],D[];
           ArraySetAsSeries(K,true);
           ArraySetAsSeries(D,true);
           CopyBuffer(stoch,0,0,5,K);
           CopyBuffer(stoch,1,0,5,D);
           ArrayPrint(K);
     }
}

Вот что я получил:

95.97315 90.40000 74.11765 49.25373 25.00000
73.68421 81.87919 90.40000 74.11765 49.25373
74.34211 80.70175 81.87919 90.40000 74.11765
90.24390 78.94737 80.70175 81.87919 90.40000
78.33333 84.05797 78.94737 80.70175 81.87919

Приведенные выше значения представляют элементы массива как 0th, 1st,2nd,3rd & 4th
То, что 0th в исходной печати, станет предыдущим для следующего и будет помещено в позицию 1st в следующей печати.
Но я вижу, что значения изменились и резко.

Раньше iStochastic() давал правильные и правильные значения. Но он работал OnTick() и, следовательно, выдавал результат при каждом изменении. Мне нужны только значения, когда полоса заполнена или через минуту. Итак, я попробовал решение от сообщества. Вот ссылка: решение для новой панели

Но выход находится впереди и меняет уравнение моей торговли, поэтому я его теряю.

Помогите мне, пожалуйста. Как я могу заставить его работать на меня?

Вот необходимые файлы: Lib CisNewBar.mqh

//+------------------------------------------------------------------+
//| Lib CisNewBar.mqh |
//| Copyright 2010, Lizar |
//| [email protected] |
//| Revision 2010.09.27 |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Class CisNewBar. |
//| Appointment: Class with methods of detecting new bars |
//+------------------------------------------------------------------+

class CisNewBar
{
protected:
datetime m_lastbar_time; // Time of opening last bar

string m_symbol; // Symbol name
ENUM_TIMEFRAMES m_period; // Chart period

uint m_retcode; // Result code of detecting new bar
int m_new_bars; // Number of new bars
string m_comment; // Comment of execution

public:
void CisNewBar(); // CisNewBar constructor
//--- Methods of access to protected data:
uint GetRetCode() const {return(m_retcode); } // Result code of detecting new bar
datetime GetLastBarTime() const {return(m_lastbar_time);} // Time of opening new bar
int GetNewBars() const {return(m_new_bars); } // Number of new bars
string GetComment() const {return(m_comment); } // Comment of execution
string GetSymbol() const {return(m_symbol); } // Symbol name
ENUM_TIMEFRAMES GetPeriod() const {return(m_period); } // Chart period
//--- Methods of initializing protected data:
void SetLastBarTime(datetime lastbar_time){m_lastbar_time=lastbar_time; }
void SetSymbol(string symbol) {m_symbol=(symbol==NULL || symbol=="")?Symbol():symbol; }
void SetPeriod(ENUM_TIMEFRAMES period) {m_period=(period==PERIOD_CURRENT)?Period():period; }
//--- Methods of detecting new bars:
bool isNewBar(datetime new_Time); // First type of request for new bar
int isNewBar(); // Second type of request for new bar
};

//+------------------------------------------------------------------+
//| CisNewBar constructor. |
//| INPUT: no. |
//| OUTPUT: no. |
//| REMARK: no. |
//+------------------------------------------------------------------+
void CisNewBar::CisNewBar()
{
m_retcode=0; // Result code of detecting new bar
m_lastbar_time=0; // Time of opening last bar
m_new_bars=0; // Number of new bars
m_comment=""; // Comment of execution
m_symbol=Symbol(); // Symbol name, by default - symbol of current chart
m_period=Period(); // Chart period, by default - period of current chart
}

//+------------------------------------------------------------------+
//| First type of request for new bar |
//| INPUT: newbar_time - time of opening (hypothetically) new bar|
//| OUTPUT: true - if new bar(s) has(ve) appeared |
//| false - if there is no new bar or in case of error |
//| REMARK: no. |
//+------------------------------------------------------------------+
bool CisNewBar::isNewBar(datetime newbar_time)
{
//--- Initialization of protected variables
m_new_bars = 0; // Number of new bars
m_retcode = 0; // Result code of detecting new bar: 0 - no error
m_comment =__FUNCTION__+" Successful check for new bar";
//---

//--- Just to be sure, check: is the time of (hypothetically) new bar m_newbar_time less than time of last bar m_lastbar_time?
if(m_lastbar_time>newbar_time)
{ // If new bar is older than last bar, print error message
m_comment=__FUNCTION__+" Synchronization error: time of previous bar "+TimeToString(m_lastbar_time)+
", time of new bar request "+TimeToString(newbar_time);
m_retcode=-1; // Result code of detecting new bar: return -1 - synchronization error
return(false);
}
//---

//--- if it's the first call
if(m_lastbar_time==0)
{
m_lastbar_time=newbar_time; //--- set time of last bar and exit
m_comment =__FUNCTION__+" Initialization of lastbar_time = "+TimeToString(m_lastbar_time);
return(false);
}
//---

//--- Check for new bar:
if(m_lastbar_time<newbar_time)
{
m_new_bars=1; // Number of new bars
m_lastbar_time=newbar_time; // remember time of last bar
return(true);
}
//---

//--- if we've reached this line, then the bar is not new; return false
return(false);
}

//+------------------------------------------------------------------+
//| Second type of request for new bar |
//| INPUT: no. |
//| OUTPUT: m_new_bars - Number of new bars |
//| REMARK: no. |
//+------------------------------------------------------------------+
int CisNewBar::isNewBar()
{
datetime newbar_time;
datetime lastbar_time=m_lastbar_time;

//--- Request time of opening last bar:
ResetLastError(); // Set value of predefined variable _LastError as 0.
if(!SeriesInfoInteger(m_symbol,m_period,SERIES_LASTBAR_DATE,newbar_time))
{ // If request has failed, print error message:
m_retcode=GetLastError(); // Result code of detecting new bar: write value of variable _LastError
m_comment=__FUNCTION__+" Error when getting time of last bar opening: "+IntegerToString(m_retcode);
return(0);
}
//---

//---Next use first type of request for new bar, to complete analysis:
if(!isNewBar(newbar_time)) return(0);

//---Correct number of new bars:
m_new_bars=Bars(m_symbol,m_period,lastbar_time,newbar_time)-1;

//--- If we've reached this line - then there is(are) new bar(s), return their number:
return(m_new_bars);
}

person Jaffer Wilson    schedule 29.03.2018    source источник
comment
Как вы его инициализировали, что в OnInit() и какой таймфрейм,символ в тестере используется? Также похоже, что вы немного отредактировали код из статьи для новичков. Вы проверили исходный код newbar? Пробовали ли вы копироватьRates и сопоставлять time[i] с K[i] или D[i]?   -  person Daniel Kniaz    schedule 29.03.2018
comment
Я использую пару M1 и EURUSD в тестировании. В данный момент мне не нужны ставки, я пытаюсь получить значения стохастика. Значение в позиции 0th не соответствует действительности, как вы видите в выводе. В OnInit нет ничего, я делаю это OnTick(). Как вы видите в программе   -  person Jaffer Wilson    schedule 29.03.2018
comment
@DanielKniaz Где я могу найти исходный код для isnewBar? Можете ли вы дать мне ссылку на него для MQL5?   -  person Jaffer Wilson    schedule 29.03.2018
comment
Вы дали ссылку на статьи MQL5.com, исходный код там.   -  person Daniel Kniaz    schedule 29.03.2018
comment
Если у вас нет OnInit(), то ваш код не инициализирован, я боюсь. я считаю, что вы должны как-то инициализировать его, иначе он может неправильно понять поля. Если вы используете структуру ставок, вы сможете увидеть, какой стох относится к какому значению, и отладить проблему.   -  person Daniel Kniaz    schedule 29.03.2018
comment
Вы проверили ссылку, которой я поделился в вопросе? Я думаю, это то, что я использую.   -  person Jaffer Wilson    schedule 29.03.2018
comment
@DanielKniaz Можете ли вы показать мне способ отладки? Я пробовал много вещей, и то, что вы говорите, для меня что-то новое. Вы можете помочь мне с этим?   -  person Jaffer Wilson    schedule 29.03.2018