Description
Let's dive into the world of Heiken Ashi candles. This example showcases how you can utilize them effectively in your trading strategy.
- Utilizes pending orders exclusively (Buy-Limit & Sell-Limit).
- Hedging is feasible (by using different magic numbers).
- Includes a filter that leverages two time frames, as illustrated in the code below.
Check out the core idea of this system in the following two functions:
int AshiUp(int TF=PERIOD_CURRENT) { double haLowHigh_1 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,0,1); double haOpen_1 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,2,1); double haClose_1 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,3,1); double haLowHigh_0 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,0,0); double haOpen_0 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,2,0); double haClose_0 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,3,0); if((haClose_0>haOpen_0 && haOpen_0==haLowHigh_0) && (haClose_1>haOpen_1 && haOpen_1!=haLowHigh_1)) return(1); else return(0); } int AshiDown(int TF=PERIOD_CURRENT) { double haLowHigh_1 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,0,1); double haOpen_1 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,2,1); double haClose_1 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,3,1); double haLowHigh_0 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,0,0); double haOpen_0 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,2,0); double haClose_0 = iCustom(Symbol(),TF,"Heiken Ashi",Red,White,Red,White,3,0); if((haClose_0<haOpen_0 && haOpen_0==haLowHigh_0) && (haClose_1<haOpen_1 && haOpen_1!=haLowHigh_1)) return(1); else return(0); }
Here’s the code for detecting a buy signal:
//--- Trading if(TotalOrdersCount(MagicNumberBuy)<1) if(AshiUp(1440)==1 && AshiUp()==1) BuyExecute();
Additionally, trading with metals is restricted, as shown below:
//+------------------------------------------------------------------+ //| Expert initialization function //+------------------------------------------------------------------+ int OnInit() { Comment(" "); if(Symbol()=="Gold" || Symbol()=="GOLD" || Symbol()=="gold" || Symbol()=="XAUUSD" || Symbol()=="AUCMDUSD" || Symbol() == "Silver" || Symbol() == "SILVER" || Symbol() == "silver" || Symbol() == "XAGUSD" || Symbol() == "E_SI" || Symbol() == "Copper" || Symbol() == "COPPER" || Symbol() == "copper" || Symbol() == "CUCMDUSD" || Symbol() == "XAUEUR" || Symbol() == "Gold.Euro" || Symbol() == "Gold.Eur" || Symbol() == "XAGEUR" || Symbol() == "Silver.Euro" || Symbol() == "Silver.Eur" || Symbol() == "USOil" || Symbol() == "USOIL" || Symbol() == "UKOil" || Symbol() == "UKOIL" || Symbol() == "NGAS" || Symbol() == "NGas" || Symbol() == "Bund" || Symbol() == "BUND" || Symbol() == "bund" || Symbol() == "Oil" || Symbol() == "Brent" || Symbol() == "BRENT" || Symbol() == "brent" || Symbol() == "Crude" || Symbol() == "COPPER" || Symbol() == "BRENTCMDUSD" || Symbol() == "WTI" || Symbol() == "Light" || Symbol() == "LIGHT" || Symbol() == "LIGHTCMDUSD" || Symbol() == "COPPER" || Symbol() == "Palladium" || Symbol() == "PALLADIUM" || Symbol() == "palladium" || Symbol() == "PDCMDUSD" || Symbol() == "Platinum" || Symbol() == "PLATINUM" || Symbol() == "platinum" || Symbol() == "PTCMDUSD" ) { Comment(SymbolErr); Alert(SymbolErr); return(INIT_FAILED); } . . . }
Image

Recommendations
- This example code is tailored for coders and traders who are eager to explore and modify it for learning purposes.
- Keep it on demo or strategy tester—avoid using it for real money trading.
- Feel free to remove lines (from 55 to 70) if you want to experiment with metals.
Good luck with your trading!
연관 포스트
- How to Fetch High Impact Events from Forex Factory for Your EA
- RRS Impulse: Your Go-To Scalping EA for MetaTrader 4
- Mastering Visual Order Processing with MetaTrader 4
- Unlocking the AK-47 Scalper EA: Your Ultimate MetaTrader 4 Companion
- Unlock Your Trading Potential with the Heiken Ashi Naive EA for MetaTrader 4