Good evening to everyone, I'm desperate. I need to take the color of the candle (heikin ashi), how can I do?
Thank you in advance
- How can I capture the outputs from iCustom function against previous candlestick?
- Heiken Ashi close price in an EA
- Detect candle color change on heikin ashi
You should encapsulate your iCustom calls to make your code
self-documenting.
Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum
Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum
#define PRICE double // A PRICE //+------------------------------------------------------------------+ //| Heiken Ashi iCustom function | //+------------------------------------------------------------------+ enum HAbuffer{ HA_LOW_HIGH, HA_HIGH_LOW, HA_OPEN, HA_CLOSE, HA_BOTTOM, HA_TOP }; PRICE Heiken_Ashi(HAbuffer buf, INDEX iBar){ return Heiken_Ashi(_Symbol, ENUM_TIMEFRAMES(_Period), buf, iBar); } PRICE Heiken_Ashi(ENUM_TIMEFRAMES tf, HAbuffer buf, INDEX iBar){ return Heiken_Ashi(_Symbol, tf, buf, iBar); } PRICE Heiken_Ashi(SYMBOL sym, ENUM_TIMEFRAMES tf, HAbuffer buf, INDEX iBar){ #define HA "Heiken Ashi" if(buf < HA_BOTTOM) return iCustom(sym, tf, HA, // All four parameters are just colors buf, iBar); PRICE lh = iCustom(sym, tf, HA, HA_LOW_HIGH, iBar); PRICE hl = iCustom(sym, tf, HA, HA_HIGH_LOW, iBar); return HA_BOTTOM == buf ? MathMin(lh, hl) : MathMax(lh, hl); } PRICE haOpen = Heiken_Ashi(HA_OPEN, 1); PRICE haClose = Heiken_Ashi(HA_CLOSE, 1); bool upCandle = haClose > haOpen;
whroeder1:
You should encapsulate your iCustom calls to make your code
self-documenting.
Detailed explanation of iCustom -
MQL4 and MetaTrader 4 - MQL4 programming forum
with this code the color of the candle where it is stored?
There is no color. Only up and down candles.
Alessandro Iovine:
Please don't answer inside the quote.
okok thank you very much. so if I want to open an order when after a red candle there is a green candle, I can not do it?
There is no red candle or green candle. The colors can be changed to whatever you want. Stop thinking color. Think up or down. You've been answered three times.
Alessandro Iovine:
okok thank you very much. so if I want to open an order when after a red candle there is a green candle, I can not do it?
okok thank you very much. so if I want to open an order when after a red candle there is a green candle, I can not do it?
HA close > HA open -> "green"
HA close < HA open -> "red"
Same as #1 but made a class:
//+------------------------------------------------------------------+ //| Heiken Ashi class | //+------------------------------------------------------------------+ class HeikenAshi{ public: HeikenAshi(void) //[Ctor] : mTF(ENUM_TIMEFRAMES(_Period)), mSymbol(_Symbol){} HeikenAshi(ENUM_TIMEFRAMES aTF) // Ctor : mTF(aTF), mSymbol(_Symbol){} HeikenAshi(SYMBOL aSymbol, ENUM_TIMEFRAMES aTF) // Ctor : mTF(aTF), mSymbol(aSymbol){} public: // Methods enum HAbuffer{ HA_LOW_HIGH, HA_HIGH_LOW, HA_OPEN, HA_CLOSE, HA_BOTTOM, HA_TOP }; PRICE get(HAbuffer aBuffer, INDEX iBar){ static const string ha = "Heiken Ashi"; if(aBuffer < HA_BOTTOM) return iCustom(mSymbol, mTF, ha, // All four parameters are just colors aBuffer, iBar); PRICE lh = iCustom(mSymbol, mTF, ha, HA_LOW_HIGH, iBar); PRICE hl = iCustom(mSymbol, mTF, ha, HA_HIGH_LOW, iBar); return HA_BOTTOM == aBuffer ? MathMin(lh, hl) : MathMax(lh, hl); } private: // Data SYMBOL mSymbol; ENUM_TIMEFRAMES mTF; }; // class HeikenAshi
static HeikenAshi sHA; // Or globally declared double haOpen = sHA.get(HA_OPEN, iBar);
bool isUp(INDEX iBar){ PRICE lh = iCustom(mSymbol, mTF, ha, HA_LOW_HIGH, iBar); PRICE hl = iCustom(mSymbol, mTF, ha, HA_HIGH_LOW, iBar); return lh < hl; }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register