Description
This is an example for Heiken Ashi candles.
- Only uses pending orders (Buy-Limit & Sell-Limit).
- Hedging is possible (by using different magic numbers).
- Filter is possible (by two time frames as the code below).
see the main idea of this expert in these 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);   }
see the code below for detect buy:
//--- Trading   if(TotalOrdersCount(MagicNumberBuy)<1)       if(AshiUp(1440)==1 && AshiUp()==1)         BuyExecute();
In addition, it is not allowed to work with metals as you can see 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 only for coders/traders who are interested for free codes in order to learn/modify it in the future.
- Don’t use it on real money trading.
- Use it only in Demo or Strategy Tester.
- You can remove lines (from 55 to 70) in order to try it in metals.
Good Luck.