새 막대 표시

 

나는 새로운 막대가 하루의 빛을 볼 때 표시하는 방법에 상처를 입었습니다.
저는 주로 성능에 대해 걱정합니다. 일부 기호에서는 20ms마다 틱을 보았습니다. 대응할 시간이 많지 않습니다.

한 가지 아이디어는 Rates.tick_volume입니다.

Mqlrates rates[1];

OnInit()
    {
    if(CopyRates(_Symbol,_Period,0,1,rates) < 1)
       if(rates[0].tick_volume == 1)
          {
          ... deal with new bar ...
          }

또 다른 아이디어 는 막대 수가 증가했는지 확인하는 것입니다.

OnInit()
  {
  if(BarsOld < Bars ( _Symbol , _Period ))
     {
     BarsOld = Bars ( _Symbol , _Period );
     ... deal with new bar ...
     }

OnChartEvent도 확인했지만 새 막대를 다른 것과 구별할 방법을 찾지 못했습니다.

평가해주셔서 감사합니다.

윌버

 

막대 및 볼륨은 새 막대를 감지할 수 없습니다.

컴퓨터는 나노초 안에 작동하므로 잘 코딩된 EA는 20ms 안에 많은 일을 할 수 있습니다.

The "New Bar" Event Handler
The "New Bar" Event Handler
  • 2010.10.11
  • Konstantin Gruzdev
  • www.mql5.com
MQL5 programming language is capable of solving problems on a brand new level. Even those tasks, that already have such solutions, thanks to object oriented programming can rise to a higher level. In this article we take a specially simple example of checking new bar on a chart, that was transformed into rather powerful and versatile tool. What tool? Find out in this article.
 
이 항목을 참조하십시오.
Improve your time execution by removing Bars function calls
Improve your time execution by removing Bars function calls
  • www.mql5.com
After a basic profiling I get the following results :. - - Category: trading systems
 

Alain님, 감사합니다.

매우 흥미로운 ... 정확히 내가 추측하는 것입니다. . . 10배 더 빠릅니다. .. 흠.

의미: TimeCurrent()는 빠르고 막대 테두리와 동기화되어 있습니까?

왜 .... 흠 ...

그것에 대해 얘기할 시간이 필요합니다.

윌버

 

Ok - 이와 같은 것을 좋아하는 사람들을 위해: 이 문제에 대한 나의 연구.

모든 "OnTick" 이벤트에서 파일에 문장을 썼습니다.

TimeLocal(PC CLock), TimeCurrent(), SymbolInfoTick()을 사용하여 마지막 틱에 대한 일부 정보 및 - CopyRates()를 사용하여 - 현재 막대에 대한 일부 정보.


"USD/JPY"의 예 - 기간은 "M1"입니다.

PC 시계의 19시 43분 1초, 43분의 첫 번째 틱이 들어왔을 때, 동시에 새로운 막대가 생겼습니다.
사실 외에는 tick-volume이 1이 아닙니다. 이것은 정상적인 사물의 흐름입니다.



때로는 그렇게 쉽지 않습니다 - 이 경우와 같이:

PC는 41분 막대의 틱이 세 번 더 들어왔을 때 이미 19:42:00을 표시합니다. 여전히 19:41:59의 타임스탬프가 있습니다.

이제 세상은 심호흡을 합니다. 8.150밀리초의 완전한 고요함입니다.

그런 다음 - PC는 이미 19:42:09를 표시합니다. - 새 막대의 첫 번째 눈금인 42분 막대가 들어왔습니다.
눈금은 19:42:07로 표시되고 - 함께 제공된 19:42 막대이기 때문에 막대 타임스탬프는 19:42:00입니다.


이제 .... 흠 ....

1. TimeCurrent()는 항상 틱의 타임스탬프와 같습니까?

나는 40.000 레코드를 확인했고 마지막 틱의 타임 스탬프가 아닌 동안 TimeCurrent가 이미 전환된 5개의 경우만 발견했습니다.

2. last_tick은 항상 새 막대가 열리기 전에 있습니까?

(계속)

 

TimeCurrent()는 서버의 마지막 틱 시간이며 차트 기호에서 가져온 것인지 여부는 코드에 따라 다릅니다.

귀하의 "마지막 틱" 문제를 이해할 수 없습니다. 이 출력을 생성한 코드를 표시해야 합니다.

 

안녕 알랭

OnTick()에서 TimeCurrent()를 확인 하여 내가 처리하는 기호에 속하는지 확인합니다.

글쎄, 이것은 작고 빠른 내 "새 막대 식별자"여야 합니다. 어떻게 생각하세요?

//---  New Bar           
bool   NewBar = false;
long   currPeriodSeconds;
double currPeriodProgress = 0;

int OnInit(void)  //-----------------------------------------------
{
      currPeriodSeconds = PeriodSeconds();
      return(INIT_SUCCEEDED);
}

void OnTick()  //--------------------------------------------------
{
      if(MathMod(TimeCurrent(),currPeriodSeconds) < currPeriodProgress)
           NewBar = true;
      else NewBar = false;
     

      currPeriodProgress = MathMod(TimeCurrent(),currPeriodSeconds);

이 시퀀스로 확인하겠습니다.

//---  Just for testing
int    ExtHdlFile1=0;
       MqlRates rates[1];
        
//---  New Bar           
bool   NewBar = false;
long   currPeriodSeconds;
double currPeriodProgress = 0;

int OnInit(void) // -------------------------------------------------------
{
      currPeriodSeconds = PeriodSeconds();

      ExtHdlFile1=FileOpen("NewBarTest.csv",FILE_READ|FILE_WRITE|FILE_CSV);
      FileSeek (ExtHdlFile1,0,SEEK_END); 
      FileWrite(ExtHdlFile1,  "TimeLocal",
                              "TimeCurrent",
                              "rates[0].time",
                              "rates[0].tick");
      return(INIT_SUCCEEDED);
}

void OnTick() // -----------------------------------------------------------
{
      if(MathMod(TimeCurrent(),currPeriodSeconds) < currPeriodProgress)
           NewBar = true;
      else NewBar = false;
     
      currPeriodProgress = MathMod(TimeCurrent(),currPeriodSeconds);

//--- lets check this

      if(NewBar)
         {
         // last Time Stamp of old Bar
         FileWrite(ExtHdlFile1, " ",
                                " ",
                                TimeToString(rates[0].time, TIME_MINUTES|TIME_SECONDS),
                                IntegerToString(rates[0].tick_volume));
         // get the new bar                     
         if(CopyRates(Symbol(),Period(),0,1,rates)!= 1) return;
         // first Time Stamp of new Bar       
         FileWrite(ExtHdlFile1,TimeToString(TimeLocal(),TIME_MINUTES|TIME_SECONDS),
                               TimeToString(TimeCurrent(), TIME_MINUTES|TIME_SECONDS),
                               TimeToString(rates[0].time, TIME_MINUTES|TIME_SECONDS),
                               IntegerToString(rates[0].tick_volume));
         }

      if(CopyRates(Symbol(),Period(),0,1,rates)!= 1) return; // != clean code - just a test
}

void OnDeinit(const int reason)
{
      FileClose(ExtHdlFile1);
      return;
}

 
Willbur :

안녕 알랭

OnTick()에서 TimeCurrent()를 확인하여 내가 처리하는 기호에 속하는지 확인합니다.

글쎄, 이것은 작고 빠른 내 "새 막대 식별자"여야 합니다. 어떻게 생각하세요?

흥미롭지 만 보편적이지 않다고 생각합니다 (모든 경우에 작동) ... 확인 하겠습니다. 현재 시간이 없습니다.
 
 

여기 내 최종 버전 이 있습니다.

사실 너무 쉬워서 조금 걱정입니다.

Alain: 축복을 내려주면 좋을 텐데.

// -----------------------------------------------------------------------
bool NewBar(void)
{
bool iNewBar = false;
static double currPeriodProgress = 0;

   if(MathMod(TimeCurrent(),PeriodSeconds()) < currPeriodProgress) iNewBar = true;

   currPeriodProgress = MathMod(TimeCurrent(),PeriodSeconds());

   return(iNewBar);
}
// ------------------------------------------------------------------------
void OnTick()
{
    if(NewBar())     PlaySound("tick.wav");


쾰른에서 인사드립니다
윌버

 

가장 쉬운 방법:

정적 날짜/시간 tlastbar=0;

날짜 시간 tnewbar=iTime(NULL,PERIOD_CURRENT,0);

bool isnewbar=tnewbar!=tlastbar;

tlastbar=tnewbar;

사유: