# Problem with / division operation?

7794

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);
}
} ```
Moderator
10614

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

157

Hi!

int / int will return int.

You have to cast one int to double.

```double bullbearRatio = (double) bullCount / bearCount;
```
7794

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.

7794

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!
Moderator
10614

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