# Counting Bull and Bear candles in a range

29

Hi guys, got a question that you guys may help me with.

I am trying to make an EA to have a for loop to count the number of bull and bear candles in a range.

But it always count a zero as result. The following is my code.

Any idea?

```//+------------------------------------------------------------------+
//|                                             BullBear Counter.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property version   "1.00"
#property strict

input int CandlesToRetrace =50;
int Bull;
int Bear;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{

//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
for(int i=1; i<CandlesToRetrace;i++)
{
if(Close[i]>Open[i])
Bull++;
else(Bear++);
}

}

```
16304

 kei41202: But it always count a zero as result. The following is my code.```int Bull; int Bear;    for(int i=1; iOpen[i]) Bull++;       else                (Bear++);``` I doubt it's always zero. You never do anything with your results, so how can you know?Bull and Bear have random initial values.Then every tick you increase them more.
29

whroeder1:
 I doubt it's always zero. You never do anything with your results, so how can you know?Bull and Bear have random initial values.Then every tick you increase them more.
Right, I forgot to insert the comment statement. And I think it is adding up the correct values so it just keep getting larger. Is there anyway I can stop it from adding?

```//+------------------------------------------------------------------+
//|                                             BullBear Counter.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property version   "1.00"
#property strict

input int CandlesToRetrace =50;
int Bull;
int Bear;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{

//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
for(int i=1; i<CandlesToRetrace;i++)
{
if(Close[i]>Open[i])
Bull++;
else(Bear++);
Comment("The Bull and Bear are respectively "+(Bull)+" and"+ (Bear));
}

}
```
• www.mql5.com
16304

 kei41202:  Is there anyway I can stop it from adding? Why would you want to stop? When you start counting what number do you begin with?
29

whroeder1:
 Why would you want to stop? When you start counting what number do you begin with?

Because it adds up non-stop. Retracing 50 candles, 23 is bull and 27 is bear. However, it doesnt stop there. It just continue to roll to 46 and 54 and so on.

I want to have it static like. It will count again next candle comes. Before that it stays 23-27.

Moderator
10569

```Bull=0;
Bear=0;
for(int i=1; i<CandlesToRetrace;i++)
{
if(Close[i]>Open[i])
Bull++;
else(Bear++);
Comment("The Bull and Bear are respectively "+(Bull)+" and"+ (Bear));
}```
.
971

Keith Watford:
.

You can't add an integer to a string.

```Comment("The Bull and Bear are respectively "+(Bull)+" and"+ (Bear)); // adding string to int.
Comment("The Bull and Bear are respectively ",Bull," and ",Bear);
// or
Comment("The Bull and Bear are respectively "+IntegerToString(Bull)+" and "+IntegerToString(Bear)); ```
29

Guys, thanks for the tips. Gotta try it out tomorrow @v@
Moderator
10569

nicholishen:

You can't add an integer to a string.

That was not my code, so no need to quote me. I simply added the resetting of global-scope variables to zero.

You can add integers to a string but you will get a warning that it will be implicitly converted to a string.