거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Telegram에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
Experts

New bar event in EA - MetaTrader 4용 expert

조회수:
19414
평가:
(4)
게시됨:
2011.07.01 14:45
업데이트됨:
2015.03.10 15:05
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

So many people wants:

How to detect new bar present.

It is so simple especially if u want detect new bar in current timeframe,

void start(){
  static datetime tmp;
  if (tmp!= Time[0]) {
    tmp =  Time[0];
    //do ur code here
  }
}

but what about the other timeframe event? It is not too hard but it has some restriction:

MT4 is not support onBar event, but u can put the upward times into array and check the array times every tick, if it reached the right time, execute the new bar event.
That means if u run eg.: backtest on M5 timeframe u can catch the M6 M7...D1 events.
Why u can detect only upward trends? The answer is a question: how to generate tick data by metatrader? A1, A2, A3,...

Until the D1 timeframe its more difficult because the week starting at eg.: Sunday 20:45 (Broker specific) and the start of the month can start in the middle of the week... etc.
I think this info isnt too relevant, so i dont publish it...

So there is a topic for this Q, but i think so many people dont read the articles and forums, so i published this code.

Some explanation:

in the init function u fill the time array with the starter times :

  curIndex = utils.periodToPeriodIndex(Period());
  times[curIndex] = Time[0];
  for(int i=curIndex+1; i<MAX; i++)
    times[i] = times[curIndex]- MathMod(times[curIndex],utils.periodIndexToPeriod(i)*60);

and in the start function u checked is there enough time elapsed now, then execute the event

  if (times[curIndex] != Time[0]) {
    times[curIndex] = Time[0];
    onBar(Period());
    for(int i=curIndex+1; i<MAX; i++) {
      int period  = utils.periodIndexToPeriod(i),
          seconds = period*60,
          time0   = times[curIndex] - MathMod(times[curIndex],seconds);
      if (times[i] != time0) {
        times[i] = time0;
        onBar(period);
      }
    }
  }


Write ur code in

void onTick() { 
}

and

void onBar(int period) {
}

That's all folks.


Update 1.1: Thx to WHRoeder for clear code

LiveAlligator LiveAlligator

Based on Alligator and MA indicators.

MTF sar_rsi MTF sar_rsi

This EA capitalises on four timeframes SAR, RSI and BB to determine entry as well as time zone.

LiveRSI LiveRSI

Based on RSI with Parabolic SAR trailing...

Time Script Time Script

The script prints the week day and time.