- январь 2, 2014
- Опубликовано: Команда Форекс Вики
- Категория: Советник
Имя: |
|
||
Автор: | лето (2011.07.01 16:45) | ||
Рейтинг: | 5 | ||
Скачано: | 2839 | ||
Скачать: |
|
||
So many people wants:
Как определить наличие нового бара. Это так просто, особенно если вы хотите обнаружить новый бар в текущем таймфрейме., недействительный старт(){
статическая дата и время tmp;
если (температура!= Время[0]) {
tmp = время[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. Until the D1 timeframe its more difficult because the week starting at eg.: Воскресенье 20:45 (Broker specific) and the start of the month can start in the middle of the week... и т. д.. 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(Период()); раз[curIndex] = Время[0]; для(int i=curIndex+1; я<MAX; я++) раз[я] = times[curIndex]- MathMod(раз[curIndex],utils.periodIndexToPeriod(я)*60); and in the start function u checked is there enough time elapsed now, then execute the event если (раз[curIndex] != Время[0]) { раз[curIndex] = Время[0]; onBar(Период()); для(int i=curIndex+1; я<MAX; я++) { int period = utils.periodIndexToPeriod(я), seconds = period*60, time0 = times[curIndex] - MathMod(раз[curIndex],секунды); если (раз[я] != time0) { раз[я] = time0; onBar(период); } } }
Write ur code in void onTick() {
}
и void onBar(int period) { } That's all folks.
Обновлять 1.1: Thx to WHRoeder for clear code |
|||
5 Комментарии Чтобы опубликовать новый комментарий, пожалуйста авторизоваться или регистр
Why don't you just use the iTime function?
http://docs.mql4.com/series/itime 27.11.2012 10:48 Master.Aurora
Why not use iTime("EURUSD",PERIOD_M1,0) например. если(New_Time_M1 != iTime("EURUSD",PERIOD_M1,0)) // Compare time --> new bar is born }
07.07.2011 22:44 alexander_zde
WHRoeder:
Thanks for this I am trying with custom timerames, if I set it up for a 3 hour candle for example eg 180 минуты. When does this time start to count? eg form midnight every 3 hours or does it depend when the indicatoe is placed on the chart?
thanks again 05.07.2011 17:04 manuel_fx
Привет. thx for this ideas, ur right. 1. Accessing the arrays is more faster than use switch - case element. (in this example 4 раз), some test: start = GetTickCount(); для(test=0; тест<10000000; test++) для(я=0; я<MAX; я++) int value1 = utils.periodIndexToPeriod[я]; log("Elapsed : " + (GetTickCount()-начинать)); // 2100 ms start = GetTickCount(); для(test=0; тест<10000000; test++) для(я=0; я<MAX; я++) int value2 = utils2.periodIndexToPeriod(я); log("Elapsed : " + (GetTickCount()-начинать)); // 8000 РС but how accsess this 10.000.000*MAX in a row? 😀 and i think much more readble switch - case options beacuse it is more similar the other rutins. Easily readable by someone who not a coder. 2. use local variable in loop save some times but not so much i think so test it: in half year backtest, where do some loop in onBar event, ur code done in 6006ms, my 5990ms on ~ 72Kbar event so its same 3. Время[0] / iTime(НУЛЕВОЙ,0,0) does not affect the result. So i change the loop code for ur versions (more readable), but not change the array access rutin. btw thx a lot, i swear i will not publish a code, после 2 являюсь, when i am too tired 😛 01.07.2011 20:27 лето
|