iBarShift returns 0 for unknown reason

 

Hey coders,

I experience a strange behavior of my EA at the moment. The EA is a simple range breakout that uses a range based on time. To calculate the range high and low I use this code block:

Print("Times... ",TimeToStr(startTime), " ", TimeToStr(endTime), " ", TimeToStr(deleteTime), " ", TimeToStr(closeTime));
   //calculate the number of bars between start and end time  
   int indexFirstCandle = iBarShift(Symbol(),PERIOD_M1,startTime,false);
   int indexLastCandle = iBarShift(Symbol(),PERIOD_M1,endTime,false);
   int candlesInBetween = indexFirstCandle-indexLastCandle+1;
PrintFormat("iFC %d iLC %d cIB %d",indexFirstCandle,indexLastCandle,candlesInBetween);
   //find the highest and lowest bar 
   int candleHighest = iHighest(Symbol(),PERIOD_M1,MODE_HIGH,candlesInBetween,indexLastCandle);
   int candleLowest = iLowest(Symbol(),PERIOD_M1,MODE_LOW,candlesInBetween,indexLastCandle);
PrintFormat("cH %d cL %d",candleHighest,candleLowest);
   //find the highest and lowest price and calculate range pips 
   rHigh = NormalizeDouble(iHigh(Symbol(),PERIOD_M1,candleHighest),Digits());
   rLow = NormalizeDouble(iLow(Symbol(),PERIOD_M1,candleLowest),Digits());
   rTicks = NormalizeDouble((rHigh-rLow),Digits());

The code is part of the calculateRange() function. The following code calls the function once as soon as the endTime is reached:

   if(!isRange){
      calcRange();
      isRange = true;
      Print("Range created... High: "+DoubleToStr(rHigh,Digits)," Low: ",DoubleToStr(rLow,Digits));
   }

Before I used this structure I calculated the range with every tick between the start and the end time. Everything worked fine back then but clearly was a waste of recources. Since I am using the new structure it happens that the iBarShift returns 0. I am running the chart in the m30 timeframe. If I start the Expert again to repeat the error the calculations are done just fine. Anyone experienced a similar problem?

I would be super happy if someone could assist me here.

Greetings,

René

 

Hallo René,

nice to meet you here, hier wird deutsch gesprochen, also bitte!

Ich dachte du bist auf MT5 umgestiegen!? Im MT5 gibst's kein iBarShift, also kann ich dir hier leider nicht weiterhelfen.

Und meine Tips, die ich dir via Skype gesendet habe hast du leider auch ignoriert.

https://www.youtube.com/watch?v=dfx5iSYh6rI

Schade.

 
bmtrading:

Hey coders,

I experience a strange behavior of my EA at the moment. The EA is a simple range breakout that uses a range based on time. To calculate the range high and low I use this code block:

The code is part of the calculateRange() function. The following code calls the function once as soon as the endTime is reached:

Before I used this structure I calculated the range with every tick between the start and the end time. Everything worked fine back then but clearly was a waste of recources. Since I am using the new structure it happens that the iBarShift returns 0. I am running the chart in the m30 timeframe. If I start the Expert again to repeat the error the calculations are done just fine. Anyone experienced a similar problem?

I would be super happy if someone could assist me here.

Greetings,

René

Das kann passieren, wenn beim UMstellen auf einen anderen Zeitrahmen, die Kurse noch nicht da sind!

Bei so etwas fragt man eigentlich als erstes _LastError ab, hast Du? Es kann aber sein, dass trotzdem kein Fehler gesetzt wurde!

Entweder (Indikator) returm und auf neuen Tick warten, da ein Indi. nicht 'schlafen' kann, ein EA kann warten und die Abfrage wiederholen.

 
Carl Schreiber:

Das kann passieren, wenn beim UMstellen auf einen anderen Zeitrahmen, die Kurse noch nicht da sind!

Bei so etwas fragt man eigentlich als erstes _LastError ab, hast Du? Es kann aber sein, dass trotzdem kein Fehler gesetzt wurde!

Entweder (Indikator) returm und auf neuen Tick warten, da ein Indi. nicht 'schlafen' kann, ein EA kann warten und die Abfrage wiederholen.

Hi, danke für die Rückmeldung. Guter Tipp mit _LastError. Also können es tatsächlich die Kurse sein... Ich hatte auch versucht vorher mit RefreshRates() alles zu aktualisieren. Aber scheinbar bezieht sich das nicht auf die Bars der unterschiedlichen Timeframes? Dann werde ich so machen, wie Du vorgeschlagen hast.

Danke! :)

 
Otto Pauser:

Hallo René,

nice to meet you here, hier wird deutsch gesprochen, also bitte!

Ich dachte du bist auf MT5 umgestiegen!? Im MT5 gibst's kein iBarShift, also kann ich dir hier leider nicht weiterhelfen.

Und meine Tips, die ich dir via Skype gesendet habe hast du leider auch ignoriert.

https://www.youtube.com/watch?v=dfx5iSYh6rI

Schade.

Hi Otto,

MT5 schließt ja MT4 nicht aus. Da würde ich ganz dreist zweigleisig fahren. Zu den Skype Tipps hatte ich Dir ja etwas geschrieben.. Da wurde nichts ignoriert :D

VG

Grund der Beschwerde: