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 }
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 }
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.
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.
#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(); } } }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I need to get if is candle bear and bull.
I found some code but not works.
I need to find if candle is white is bearish and if is black is in bullish
Check attachment.![]()