TimeToStr()

 

I wrote this simple EA for someone else the other day, all it does is check each of the 4 timeframes for a new bar, if there is one it looks for if the last closed bar volume is lower than the previous 2 on any of the 4 timeframes and Alert() if it is.

void OnTick()
{
//---
  const int ichart[4]={5,15,30,60};
  static datetime time[4]={0};
  string bartime=NULL;
//---   
  for(int i=0; i<4; i++)
  {if(iTime(NULL,ichart[i],0) > time[i])
   {time[i] = iTime(NULL,ichart[i],0);
    if(iVolume(NULL,ichart[i],1) < iVolume(NULL,ichart[i],2))
    {if(iVolume(NULL,ichart[i],1) < iVolume(NULL,ichart[i],3))
     bartime = TimeToStr(iTime(NULL,ichart[i],0),TIME_MINUTES);
     Alert("Volume is Down: Chart: ",ichart[i],"m ",bartime);
}}}}

I left it running on my own terminal to test and it doesn't work correctly but I'm not sure why because the failure is inconsistant.

This is the output below, you can see sometimes the bar time on the 5 minute chart is printed and sometimes it is not.

The EA is running on the 5 minute chart so I am suprised it is doing this. Is there something about using iTime() on the current chart I didnt know about ? It seems to work correctly on the other timeframes.

2014.04.02 16:00:41.766 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 60m 00:00
2014.04.02 15:50:08.685 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m 23:50
2014.04.02 15:45:05.398 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m
2014.04.02 15:32:14.028 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 30m 23:30
2014.04.02 15:32:14.028 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 15m 23:30
2014.04.02 15:32:14.028 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m 23:30
2014.04.02 15:21:33.049 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m 23:20
2014.04.02 15:15:46.051 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 15m 23:15
2014.04.02 15:05:09.409 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m 23:05
2014.04.02 15:00:58.876 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 60m 23:00
2014.04.02 15:00:58.876 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 30m 23:00
2014.04.02 14:54:58.666 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m
2014.04.02 14:44:57.664 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 15m 22:45
2014.04.02 14:44:57.664 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m 22:45
2014.04.02 14:40:14.798 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m 22:40
2014.04.02 14:35:26.768 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m
2014.04.02 14:30:05.324 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 30m 22:30
2014.04.02 14:25:02.162 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m 22:25
2014.04.02 14:15:13.001 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 15m 22:15
2014.04.02 14:15:13.001 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m 22:15
2014.04.02 14:05:10.448 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 5m 22:05
2014.04.02 14:00:01.442 Volume Down Alert XAGUSD,M5: Alert: Volume is Down: Chart: 60m 22:00

 
SDC:

I wrote this simple EA for someone else the other day, all it does is check each of the 4 timeframes for a new bar, if there is one it looks for if the last closed bar volume is lower than the previous 2 on any of the 4 timeframes and Alert() if it is.

I left it running on my own terminal to test and it doesn't work correctly but I'm not sure why because the failure is inconsistant.

This is the output below, you can see sometimes the bar time on the 5 minute chart is printed and sometimes it is not.

The EA is running on the 5 minute chart so I am suprised it is doing this. Is there something about using iTime() on the current chart I didnt know about ? It seems to work correctly on the other timeframes.


You have to pay attention to your indenting, your Alert() statement is called independently of your second condition on iVolume, so sometimes bartime don't have a value :

            if(iVolume(NULL,ichart[i],1)<iVolume(NULL,ichart[i],3)) 
              {
               bartime=TimeToStr(iTime(NULL,ichart[i],0),TIME_MINUTES);
               Alert("Volume is Down: Chart: ",ichart[i],"m ",bartime);
              }
 

Damn I totaly missed that, thanks for pointing that out angevoyageur ... sometimes I make a stupid mistake and I look at every other possibility except the obvious one.

 
SDC:

Damn I totaly missed that, thanks for pointing that out angevoyageur ... sometimes I make a stupid mistake and I look at every other possibility except the obvious one.

This happens to everyone, don't worry.
Reason: