iBarShift와 유사함 - 페이지 15

 
Alexey Kozitsyn :
그건 그렇고, Bars() 함수에 대해. 아마도 이것이 클린치의 이유일 것입니다.
이것은 확인하기 쉽습니다. 모든 막대를 내 iBar로 변경합니다. 클린치가 사라지면 이 기능에 문제가 있는 것입니다. 또한 일부 지표가 정지된 이유를 이해할 수 없었습니다. 이 버그로 밝혀졌습니다. 이제 모든 것이 날아갑니다.
 
fxsaber :

따옴표는 관심 있는 기호를 제외한 모든 기호 뒤에 올 수 있습니다.

좋아, 나는 새로운 소스를 보았다. 논의된 내용이 수정되지 않았음을 확인했습니다. 내가 간다

시장 감시 창에서 요청한 기호를 사용할 수 없는 경우에만 SYMBOL_TIME을 사용하는 것이 좋습니다. 그러면 TimeCurrent 가 작업을 수행하지 않습니다. 그러나 Bars에 대한 이 사용 사례는 나에게 있을 것 같지 않습니다. 그러나 SymbolInfoInteger(symbol_name,SYMBOL_TIME)가 거의 10배 더 오래 걸리기 때문에 SYMBOL_TIME을 통해 현재 시간을 얻는 비용은 훨씬 더 높습니다. 물론 Market Watch에서 이러한 기호가 있는지 확인할 수 있으며 결과에 따라 TimeCurrent 또는 SYMBOL_TIME을 사용하지만 이 또한 무료가 아닙니다. 특히 새 기호가 있는지 여부를 항상 모니터링해야 하기 때문에 Market Watch에서 추가 또는 제거되었습니다. 따라서 iBars가 올바르게 작동하도록 예약하는 것이 더 쉽습니다. 요청한 기호가 시장 개요에 있는 것이 좋습니다.

SERIES_LASTBAR_DATE 정보 당신이 틀렸다고 생각합니다. SymbolInfoInteger(symbol_name,SYMBOL_TIME)는 덜 악의적입니다.

SeriesInfoInteger 함수는 기록 페이징을 일으키지 않습니다. 원인이 있는 경우 논리적인 Bar 요청입니다. 그리고 이 짧은 스크립트를 실행하면 브레이크의 소스를 볼 수 있습니다.

 void OnStart ()
  {
   Print ( "1" );
   Print ( Bars ( _Symbol , PERIOD_W1 , D'2020.01.01 00:00' , UINT_MAX ));
   Print ( "2" );
  }
 

실제로 매우 이상한 버그입니다. 다운로드 기록이 미치는 영향을 확인했는데 오늘 갑자기 EURUSD 기호 에 실제로 나타나지 않는다는 것을 발견했습니다.

전체 기록의 강제 다운로드. 그리고 버그가 다시 나타났습니다.

아마도 다운로드 기록은 이 버그에 영향을 미치지 않을 것입니다.

이 버그가 떠있는 이유를 이해하지 못합니다.

이 스크립트를 사용하여 다음을 테스트했습니다.

파일:
TestiBars.mq5  11 kb
 
Nikolai Semko :

이 버그가 떠있는 이유를 이해하지 못합니다.

SD는 이 전체 주제를 알고 있습니까?

 
일반적으로 데이터 로딩/업로드가 단말의 약점이라고 생각합니다.
 
Alexey Kozitsyn :

SD는 이 전체 주제를 알고 있습니까?

예, 저는 이미 2018년 3월 30일에 거기에 글을 썼습니다. 지금까지는 침묵입니다.

알렉세이 코지친 :
일반적으로 데이터 로딩/업로드가 단말의 약점이라고 생각합니다.

동의하지만 가장 어려운 작업 중 하나이기도 합니다.

 
Nikolai Semko :

iBars 기능이 매우 성가신 것으로 판명되었지만 MQ가 중단 버그를 수정할 때까지 일반 막대 대신 사용하는 것이 좋습니다.

iBar는 논리적으로 0을 반환해야 할 때 멈춥니다. 일반적으로 10초 이상 반환합니다. MQL4에는 그러한 버그가 없습니다.

대부분의 작업에서 iBars는 버그를 우회할 뿐만 아니라 이전 값을 보존하는 알고리즘 덕분에 가능한 한 Bars 및 SeriesInfoInteger 함수 를 사용하지 않으려고 하기 때문에 일반 Bars보다 빠르게 작동합니다.

이 기능을 위아래로 모두 테스트했습니다. 바를 완전히 반복하는 것 같습니다.

어쩌면 더 우아하게 할 수 있습니다. 욕망이 있는 사람 - 환영합니다. 오류를 찾으면 수정하겠습니다.

그래서...

그러면 iBarsShift 기능의 완전한 아날로그는 다음과 같이 보일 것입니다.

그리고 대부분의 경우에 사용되는 정확한 마지막 매개변수가 없는 옵션은 다음과 같습니다.

귀하의 코드 iBarsShift+iBars (및 기타 iBarsShift)를 사용하고 iBarsShift에서 0을 얻었지만 TF 차트 H1 및 H1 오류 계산 시

2018.04.21 14:38:01.059 SVA_LinearRegression_test (Si Splice,H1)        zero divide in 'SVA_LinearRegression_test.mq5' (176,44)

이 코드 줄에 해당하는

   if (timeframe< PERIOD_W1 ) TimeCur-=TimeCur % PerSec;

다음은 전체 표시기 코드입니다.

 #property version    "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots    3

//--- plot Label1
#property indicator_label1    "LR_line"
#property indicator_type1    DRAW_LINE
#property indicator_color1    clrGold
#property indicator_style1    STYLE_DOT
#property indicator_width1    1
//--- plot Label2
#property indicator_label2    "Sup_line"
#property indicator_type2    DRAW_LINE
#property indicator_color2    clrAquamarine
#property indicator_style2    STYLE_DOT
#property indicator_width2    1
//--- plot Label3
#property indicator_label3    "Res_line"
#property indicator_type3    DRAW_LINE
#property indicator_color3    clrOrangeRed
#property indicator_style3    STYLE_DOT
#property indicator_width3    1


//--- input parameters
input ENUM_TIMEFRAMES TF= PERIOD_D1 ;
input int Bar= 3 ;
input bool UseClose = true ;


//--- indicator buffers
double LR_line_Ind[];
double Sup_line_Ind[];
double Res_line_Ind[];

//---
int limit,start;

//Список переменных:
static datetime TimeN= 0 ;
int   barsToCount= 0 ;

int InpChannelPeriod= 1000 ;
double OpenI[];
double HighI[];
double LowI[];
double CloseI[];
double arr[];

double Calc_LR_line= 0.0 ;
double Calc_Sup_line= 0.0 ;
double Calc_Res_line= 0.0 ;


//////////////////////////////////////////////////////////////////////

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- indicator buffers mapping
   SetIndexBuffer ( 0 ,LR_line_Ind, INDICATOR_DATA );
   SetIndexBuffer ( 1 ,Sup_line_Ind, INDICATOR_DATA );
   SetIndexBuffer ( 2 ,Res_line_Ind, INDICATOR_DATA );   
//--- set accuracy
   IndicatorSetInteger ( INDICATOR_DIGITS , _Digits );
//--- set first bar from what index will be drawn
   PlotIndexSetInteger ( 0 , PLOT_DRAW_BEGIN ,InpChannelPeriod);
   PlotIndexSetInteger ( 1 , PLOT_DRAW_BEGIN ,InpChannelPeriod);
   PlotIndexSetInteger ( 2 , PLOT_DRAW_BEGIN ,InpChannelPeriod);   
//---
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                         |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
{


}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate ( const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[])
  {
   ArraySetAsSeries (LR_line_Ind, true ); 
   ArraySetAsSeries (Sup_line_Ind, true ); 
   ArraySetAsSeries (Res_line_Ind, true ); 
   ArraySetAsSeries (time, true ); 

//--- check for rates
   if (rates_total<InpChannelPeriod) return ( 0 );
//--- preliminary calculations
   if (prev_calculated== 0 ) limit=InpChannelPeriod;
   else limit=prev_calculated;
//--- the main loop of calculations
   for ( int C=limit;C<rates_total && ! IsStopped ();C++)
     {
       LRegrf(C);
       LR_line_Ind[C]=Calc_LR_line;
       Sup_line_Ind[C]=Calc_Sup_line;
       Res_line_Ind[C]=Calc_Res_line;    
     }
//--- return value of prev_calculated for next call
   return (rates_total);
  }
  
//+------------------------------------------------------------------+
double LRegrf( int index)
{
int Day_Shift= iBarShift ( _Symbol ,TF, iTime ( _Symbol , PERIOD_CURRENT ,index), false );

Print ( iTime ( _Symbol , PERIOD_CURRENT ,index));
Print (Day_Shift);

return ( 0 );
}
//-------------------------------------------------------------------
//==MQL4toMQL5
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
datetime iTime ( string symbol, ENUM_TIMEFRAMES tf, int index)
  {
   if (index < 0 ) return (- 1 );
//   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   //ENUM_TIMEFRAMES timeframe=PERIOD_CURRENT;
   datetime Arr[];
   if ( CopyTime (symbol,tf,index, 1 ,Arr)> 0 )
       return (Arr[ 0 ]);
   else return (- 1 );
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int iBarShift ( const string Symb, const ENUM_TIMEFRAMES TimeFrame, datetime time, bool exact= false )
  {
   int Res= iBars (Symb,TimeFrame,time+ 1 , UINT_MAX );
   if (exact) if ((TimeFrame!= PERIOD_MN1 || time> TimeCurrent ()) && Res== iBars (Symb,TimeFrame,time- PeriodSeconds (TimeFrame)+ 1 , UINT_MAX )) return (- 1 );
   return (Res);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int iBars ( string symbol_name, ENUM_TIMEFRAMES   timeframe, datetime start_time, datetime stop_time)
  {
   static string LastSymb= NULL ;
   static ENUM_TIMEFRAMES LastTimeFrame= 0 ;
   static datetime LastTime= 0 ;
   static datetime LastTime0= 0 ;
   static int PerSec= 0 ;
   static int PreBars= 0 ;
   static datetime LastBAR= 0 ;
   static datetime LastTimeCur= 0 ;
   datetime TimeCur;
   if (stop_time<start_time) {TimeCur=stop_time; stop_time=start_time; start_time=TimeCur; }
   TimeCur= TimeCurrent ();
   if (LastTimeFrame!=timeframe) if (timeframe== PERIOD_MN1 ) PerSec= 2419200 ; else PerSec=:: PeriodSeconds (timeframe);
   if (timeframe< PERIOD_W1 ) TimeCur-=TimeCur%PerSec;
   if (start_time>TimeCur) {LastSymb= NULL ; return ( 0 );}
   if (LastTimeFrame!=timeframe || LastSymb!=symbol_name || ((TimeCur-LastBAR)> 0 && TimeCur!=LastTimeCur))
      LastBAR=( datetime ) SeriesInfoInteger (symbol_name,timeframe, SERIES_LASTBAR_DATE );

   LastTimeCur=TimeCur;
   if (PerSec== 0 ) return ( 0 );
   if (start_time>LastBAR)
     {LastTimeFrame=timeframe; LastSymb=symbol_name; return ( 0 );}

   datetime tS,tF= 0 ;
   bool check= true ;
   if (timeframe< PERIOD_W1 ) tS=start_time-(start_time- 1 )%PerSec- 1 ;
   else if (timeframe== PERIOD_W1 ) tS=start_time-(start_time- 259201 )%PerSec- 1 ;
   else
     {
      PerSec= 2678400 ;
       MqlDateTime dt;
       TimeToStruct (start_time- 1 ,dt);
      tS=dt.year* 12 +dt.mon;
     }
   if (stop_time<=LastBAR)
     {
       if (timeframe< PERIOD_W1 ) tF=stop_time-(stop_time)%PerSec;
       else if (timeframe== PERIOD_W1 ) tF=stop_time-(stop_time- 259200 )%PerSec;
       else
        {
         MqlDateTime dt0;
         TimeToStruct (stop_time,dt0);
         tF=dt0.year* 12 +dt0.mon;
        }
       if (tS==tF) {PreBars= 0 ; check= false ;}
     }
   if ((LastTimeFrame!=timeframe || LastSymb!=symbol_name || tS!=LastTime || tF!=LastTime0) && check)
      PreBars= Bars (symbol_name,timeframe,start_time,stop_time);
   LastTime=tS; LastTime0=( datetime )tF;
   LastTimeFrame=timeframe;
   LastSymb=symbol_name;
   return (PreBars);
  }

시간과 날짜가 정확할 때 인쇄 (Day_Shift)가 항상 0을 반환하는 이유는 무엇입니까?

이것은 주말의 효과인 것 같습니다. 다른 날에는 모든 것이 올바르게 작동했기 때문입니다(다른 기능이 있지만 오늘 작동하지 않음).

 
Aleksey Vyazmikin :

귀하의 코드 iBarsShift+iBars (및 기타 iBarsShift)를 사용하고 iBarsShift에서 0을 얻었지만 TF 차트 H1 및 H1 오류 계산 시

이 코드 줄에 해당하는

다음은 전체 표시기 코드입니다.

시간과 날짜가 정확할 때 인쇄 (Day_Shift)가 항상 0을 반환하는 이유는 무엇입니까?

이것은 주말의 효과인 것 같습니다. 다른 날에는 모든 것이 올바르게 작동했기 때문입니다(다른 기능이 있지만 오늘 작동하지 않음).

잘못된 방식으로 코드를 남겨서 죄송합니다.

그때도 부정확한 작업을 알아차리고 거의 고칠 뻔 했지만, 간단히 해결할 수 있는 작은 문제가 있었습니다.
나는 지금 공부하고 있고 시험을 볼 시간이고 시간이 없다는 사실 때문에 코드를 포기했습니다. 4월 24일 마지막 시험.
그 후에 모든 것을 수정하고 CB에 게시합니다.

이미 포스팅을 시작했는데 보류중입니다.


 
Nikolai Semko :

잘못된 방식으로 코드를 남겨서 죄송합니다.

그때도 부정확한 작업을 알아차리고 거의 고칠 뻔 했지만, 간단히 해결할 수 있는 작은 문제가 있었습니다.
나는 지금 공부하고 있고 시험을 볼 시간이고 시간이 없다는 사실 때문에 코드를 포기했습니다. 4월 24일 마지막 시험.
그 후에 모든 것을 수정하고 CB에 게시합니다.

이미 포스팅을 시작했는데 보류중입니다.


최종 양식으로 수정될 때까지 기다리겠습니다. 답변 감사합니다.

시험 잘 치세요!

 
Aleksey Vyazmikin :

최종 양식으로 수정될 때까지 기다리겠습니다. 답변 감사합니다.

시험 잘 치세요!

감사해요))
사유: