How to get bull/bear candle?

 

Hi,

I need to get if is candle bear and bull. 

I found some code but not works.

  bool bullish = Close[1] > Open[1] && Open[1];
        bool bearish = Close[1] < Open[1] && Open[1]; 


I need to find if candle is white is bearish and if is black is in bullish

Check attachment.

Files:
 
bool bullish = Close[1] > Open[1] ? true : false;

The definition is simple, if the close price is larger than the open price. Then it's a bullish candle. Otherwise, it's bearish. 

the same as 

bool bullish;
if(Close[1]>Open[1])
{
        bullish = true;
}else{
        bullish = false; // this means bearish. No need to declare a bearish variable.
}

Close[1] means the second candle. The first(or active) candle is not closed yet.

Usage:

if(bullish)
{
        //do your business
}
else if(!bullish) //bearish
{
        //do your business

}
 
William William #:

The definition is simple, if the close price is larger than the open price. Then it's a bullish candle. Otherwise, it's bearish. 

simplify your code:

bool bullish=Close[1]>Open[1];
if(bullish) {
  //do your business
}
else { //bearish or doji
  //do your business
}
 
thanks very nice its works!
 
May I add, the code above also sees open equals close as bearish.

The correct definition would be open > close as bearish and open < close as bullish.

Open == close is considered a third type, neutral.

Isn't that so?
 
Hello 
Can I use for mql5 please,
If not how can I use it for mql5 please
Need help
 
@Mohammed Tijjani #: Can I use for mql5 please, If not how can I use it for mql5 please Need help
Your questions are unclear. Please explain in more detail please. What and how do you want to use for "mql5"?
 
Fernando Carreiro #:
Your questions are unclear. Please explain in more detail please. What and how do you want to use for "mql5"?
I use this code in mql5 but not work 
bool bullish=Close[1]>Open[1];
if(bullish) {
  //do your business
}
else { //bearish or doji
  //do your business
}
 
@Mohammed Tijjani #: I use this code in mql5 but not work 

That is MQL4 code, not MQL5. MQL5 does not support predefined array variables for timeseries rates data (Open[], Close[], etc.).

Those predefined variables don't exist in MQL5. You will have to convert all of your code into proper MQL5.

 
Fernando Carreiro #:

That is MQL4 code, not MQL5. MQL5 does not support predefined array variables for timeseries rates data (Open[], Close[], etc.).

Those predefined variables don't exist in MQL5. You will have to convert all of your code into proper MQL5.

I converted it like this 
It working on bullish but otherwise it's bearish is not work
Please I need help
        
 
#include <Trade\Trade.mqh>

bool bullish = iOpen(Symbol(),_Period,1) < iClose(Symbol(),_Period,1) ? true : false;

CTrade trade;

int barsTotal;

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

  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void sell()
  {

// if(OrdersTotal() == 0)
     {
      double bid =NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID),_Digits);
      trade.Sell(0.1,_Symbol,bid);
     }
  }



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void buy()
  {
// if(OrdersTotal() == 0)

     {
      double ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
      trade.Buy(0.1,_Symbol,ask);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   close_opration();


   int bars = iBars(_Symbol,PERIOD_CURRENT);
   if(barsTotal != bars)
     {
      barsTotal = bars;

      if(iOpen(Symbol(),_Period,1) < iClose(Symbol(),_Period,1))
        {
         bullish = true;
        }
      else
        {
         bullish = false;
        }


      if(bullish)
        {
          buy();
        }
      else
         if(bullish)
           {
            sell();
           }
     }
  }
Reason: