F
Code below is based on two EMA's - the GBPUSD EMA12 & EMA60 on H4.
Its not a professional EA but might make some money in a year - especially with a bit of tinkering with extern values...
Limitation is that this is a trend following system (as it uses MAs and MACD) & so does badly during range based price action.
But here it is and YES I am bored sitting in front of a PC, but here we all are anyway :D
FWIW
-BB-
#property copyright "bd@selectfx.net" #property link "http://www.selectfx.net" //+------------------------------------------------------------------+ extern double TakeProfit = 150; extern double StopLoss = 120; extern double Lots = 1.0; // 1.0 = Correct level for a 10000 account extern double TrailingStop = 100; //extern double ConfirmPips = 0; extern int iShift = 1; //extern int iMAPeriods = 2; extern int iSlippage = 3; extern int iMagic=1111111; // 101=EURUSD 103=GBPUSD 112=GBPJPY nnn11=Hour 1 nnnnn0001=Version extern bool EachTickMode = False; extern double RSI_Period=14; extern int MACDFast_EMA_Period=10; // Number of periods for fast moving average - original 12 extern int MACDSlow_EMA_Period=25; // Number of periods for fast moving average - original 26 extern int MACDSignal_Period=5; // Original 9 double dPivot, BuyLots, SellLots; int cnt, ticket, total, accounttotal; string strSymbol="GBPUSD"; // Hard coded for this symbol string strComment="BD EMA1260 GBPUSD H4"; int MaxNumOrders=1; int iPeriod = PERIOD_H4; int Current; //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- /* Max Profit !!! Max PF Min Drawdown */ // ========================================================================== // Check each tick section START if(Bars<4) { Print("bars less than 4"); return(0); } // when not back testing display chart info every tick if(IsTesting() == false) {Display_Info();} if(TrailingStop>0) CheckActiveTradesForStopLoss(); if (EachTickMode==True) Current=0; if (EachTickMode==False) Current=1; // Check each tick section END // ========================================================================== // ========================================================================== // Check once each bar section START //if ((Volume[0]>1) && (EachTickMode=False)) {return(0);} // Do nothing in here after first tick double EMA_D_5 = iMA(strSymbol,PERIOD_D1,5,0,MODE_EMA,PRICE_CLOSE,Current); double EMA_D_20 = iMA(strSymbol,PERIOD_D1,20,0,MODE_EMA,PRICE_CLOSE,Current); double EMA_H4_12 = iMA(strSymbol,PERIOD_H4,12,0,MODE_EMA,PRICE_CLOSE,Current); double EMA_H4_60 = iMA(strSymbol,PERIOD_H4,60,0,MODE_EMA,PRICE_CLOSE,Current); double RSI_Cur = iRSI(strSymbol,PERIOD_H4,RSI_Period,PRICE_CLOSE,Current); double CLOSE_Cur = Close[Current]; double MACD_Cur = iMACD(strSymbol, iPeriod , MACDFast_EMA_Period, MACDSlow_EMA_Period, MACDSignal_Period, PRICE_CLOSE, MODE_MAIN, Current); double MACD_Sig_Cur = iMACD(strSymbol, iPeriod , MACDFast_EMA_Period, MACDSlow_EMA_Period, MACDSignal_Period, PRICE_CLOSE, MODE_SIGNAL, Current); // Handle closure conditions if ((CLOSE_Cur>EMA_H4_60) || (CLOSE_Cur>EMA_H4_12) || (RSI_Cur > 50) || (MACD_Cur > MACD_Sig_Cur)) CloseAllSellOrders(); if ((CLOSE_Cur<EMA_H4_60) || (CLOSE_Cur<EMA_H4_12) || (RSI_Cur < 50) || (MACD_Cur < MACD_Sig_Cur)) CloseAllBuyOrders(); total=ActiveTradesForMagicNumber(strSymbol, iMagic); if (total == MaxNumOrders) {return(0);} // Enough orders already! BuyLots=Lots; SellLots=Lots; // check for long position (BUY) possibility if((CLOSE_Cur>EMA_H4_60) && (RSI_Cur > 50) && (MACD_Cur > MACD_Sig_Cur) && (MACD_Cur < 0)) { ticket=OrderSend(strSymbol,OP_BUY,BuyLots,Ask,iSlippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,strComment,iMagic,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return(0); } // check for short position (SELL) possibility if((CLOSE_Cur<EMA_H4_60) && (RSI_Cur < 50) && (MACD_Cur < MACD_Sig_Cur) && (MACD_Cur > 0)) { ticket=OrderSend(strSymbol,OP_SELL,SellLots,Bid,iSlippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,strComment,iMagic,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); return(0); } // Check once each bar section END //---- return(0); } //+------------------------------------------------------------------+ void CloseAllBuyOrders() { int i, iTotalOrders; iTotalOrders=OrdersTotal(); for (i=0; i<iTotalOrders; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderMagicNumber()==iMagic) { if (OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet); if (OrderType()==OP_BUYSTOP) OrderDelete(OrderTicket()); if (OrderType()==OP_BUYLIMIT) OrderDelete(OrderTicket()); } } } } void CloseAllSellOrders() { int i, iTotalOrders; iTotalOrders=OrdersTotal(); for (i=0; i<iTotalOrders; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderMagicNumber()==iMagic) { if (OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet); if (OrderType()==OP_SELLSTOP) OrderDelete(OrderTicket()); if (OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket()); } } } } double ActiveTradesForMagicNumber(string SymbolToCheck, int MagicNumberToCheck) { int icnt, itotal, retval; retval=0; itotal=OrdersTotal(); for(icnt=0;icnt<itotal;icnt++) { OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES); // check for opened position, symbol & MagicNumber if(OrderType()<=OP_SELL && OrderSymbol()==SymbolToCheck && OrderMagicNumber()==MagicNumberToCheck) { retval++; //Print("Orders opened : ",retval); } } return(retval); } void CheckActiveTradesForStopLoss() { int icnt, itotal; itotal=OrdersTotal(); for(icnt=0;icnt<itotal;icnt++) { // order loop boundary OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES); // check for opened position, symbol & MagicNumber if(OrderType()==OP_SELL && OrderSymbol()==strSymbol && OrderMagicNumber()==iMagic) { if (OrderStopLoss()==0) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); } if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if(OrderStopLoss()>(Ask+Point*TrailingStop)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); } } } if(OrderType()==OP_BUY && OrderSymbol()==strSymbol && OrderMagicNumber()==iMagic) { if (OrderStopLoss()==0) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green); } if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()<Bid-Point*TrailingStop) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green); } } } } // order loop boundary return(0); } void Display_Info() { Comment("SelectFX Expert Adviser\n", "Desc: ",strComment,"\n", "Magic Number: ", iMagic,"\n", "Forex Account Server:",AccountServer(),"\n", "Account Balance: $",AccountBalance(),"\n", "Lots: ",Lots,"\n", "Symbol: ", Symbol(),"\n", "Price: ",NormalizeDouble(Bid,4),"\n", "Pip Spread: ",MarketInfo(strSymbol,MODE_SPREAD),"\n", "Date: ",Month(),"-",Day(),"-",Year()," Server Time: ",Hour(),":",Minute(),":",Seconds(),"\n", "Minimum Lot Size: ",MarketInfo(Symbol(),MODE_MINLOT)); return(0); }
Thanks Barrowboy,
I'll try your EA.
It seems to be very sofisticaded to me with many parameters, but if it works...
thanks again
Lionel
CAN ANY BODY HELP ME TO MAKE ( 2 ) MOVING AVERAGES AN EXPIRT ADVISER
ANY BODY TIRED OF SITING FRONT OF THE PC
HME-7@HOTMAIL.COM
I am not bored of sitting in front of my pc. Then again I am a full time programmer by profession, so making my expert adviser is interesting to me.
Thanks Barrowboy,
I'll try your EA.
It seems to be very sofisticaded to me with many parameters, but if it works...
thanks again
Lionel
You are too kind :)
I regret to say that it is not very sophisticated - but it gives you an idea...
Even these http://www.selectfx.net/free_stuff1.htm
are not particularly sophisticated - but they do the job!
Good Luck
-BB-

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
ANY BODY TIRED OF SITING FRONT OF THE PC
HME-7@HOTMAIL.COM