Problem with / division operation?

Back to topics list To post a new topic, please log in or register
avatar
52
renzbub 2015.09.22 00: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);
   }   
} 

 

avatar
Moderator
3404
GumRai 2015.09.22 01: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 

avatar
108
eddie 2015.09.22 10:54 #
 

Hi!

int / int will return int.

You have to cast one int to double.

double bullbearRatio = (double) bullCount / bearCount;
avatar
52
renzbub 2015.09.22 12: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. 

 

 

avatar
52
renzbub 2015.09.22 12: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! 
avatar
Moderator
3404
GumRai 2015.09.22 13: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

 

Back to topics list  

To add comments, please log in or register