Download MetaTrader 5
To add comments, please log in or register
Have you developed an application? Publish it in Code Base!
Stephen Reynolds
484
Stephen Reynolds 2015.09.21 22:34 

In the code below I'm trying to count upto 36 bars then find the ratio of bull candles to bear candles and returns to log. But, the code returns 1 all the time. Ive tried + and % they work the way they are supposed to but not /.

I cant see why this is?       

void OnTick()    
{
   static int barCount = TimeMinute(TimeCurrent());
   barCount++;

   static int bullCount = TimeMinute(TimeCurrent());   
   static int bearCount = TimeMinute(TimeCurrent());
   //double bullbearRatio = 0;

   // Bull/Bear Ratio         
   if(Close[1] > Open[1]) bullCount++;
   if(Close[1] < Open[1]) bearCount++;

   //There is something wrong with using / for division
     
   // Bull/Bear Ratio 
   if(barCount > 36) 
   {
      double bullbearRatio = bullCount / bearCount; // EG theres more bulls to bears or 10/7 = 1.4   thus > 1
      
      if(barCount > 36) Print(bullbearRatio);
   }   
} 
Keith Watford
Moderator
8007
Keith Watford 2015.09.21 23:28  

What is 

TimeMinute(TimeCurrent())

 supposed to do?

You are not counting bull and bear bars, you are counting the same bar every tick and then only if it is less than 36 minutes after the hour when the expert is attached to the chart 

peter.MT4Web
158
peter.MT4Web 2015.09.22 08:54  

Hi!

int / int will return int.

You have to cast one int to double.

double bullbearRatio = (double) bullCount / bearCount;
Stephen Reynolds
484
Stephen Reynolds 2015.09.22 10:51  
GumRai:

What is 

 supposed to do?

You are not counting bull and bear bars, you are counting the same bar every tick and then only if it is less than 36 minutes after the hour when the expert is attached to the chart 

GumRai:

What is 

 supposed to do?

You are not counting bull and bear bars, you are counting the same bar every tick and then only if it is less than 36 minutes after the hour when the expert is attached to the chart 

 

As far as I understand it TimeMinute() returns the minute of the specified time. TimeCurrent() returns the time of the received handled tick.

Ive used these functions to take one time from the bar in tick form and count it as one using the int data type. And then count along each new bar using static modifier.

You can check this here :

void OnTick()    
{      
   static int barCount = TimeMinute(TimeCurrent());
   barCount++;
   
   Print(barCount);
} 

 It always counts 1 bar whether its a 1m, 5m or 30m or more. It always only uses one bit of time and uses it to count with. Maybe im tricking the EA into counting a bar? Whatever, it appears to work for me. 

 

 

Stephen Reynolds
484
Stephen Reynolds 2015.09.22 10:53  
eddie:

Hi!

int / int will return int.

You have to cast one int to double.

Thanks eddie for reminding me to typecast this has worked! 
Keith Watford
Moderator
8007
Keith Watford 2015.09.22 11:35  
You can check this here :
void OnTick()    
{      
   static int barCount = TimeMinute(TimeCurrent());
   barCount++;
   
   Print(barCount);
} 

 It always counts 1 bar whether its a 1m, 5m or 30m or more. It always only uses one bit of time and uses it to count with. Maybe im tricking the EA into counting a bar? Whatever, it appears to work for me. 

 That will increase barCount every tick, not every bar

 

/
To add comments, please log in or register