I have updated the EA a little bit. Have tested it using different MACD constants.
The best in a backtest of the year 2008 has been discovered with the following values:MACD fast MA interval: 8 MACD MA interval: 14 MACD signal interval: 2 Here's the altered code for those who want to try it for themselfs:
Inserted Code // ------------------------------------------------------------------ //| EA #1 | //| ===== | //| Date: 03.08.2008 | //| Author: AdamP | // ------------------------------------------------------------------ #define MAGICNUMBER 01082008 extern double Lots = 1.0; extern double TakeProfit = 200; extern double StopLoss = 50; extern int FastMA = 8; extern int SlowMA = 14; extern int Signal = 2; extern int RSIperiod = 14; // ------------------------------------------------------------------ //| Count open positions | // ------------------------------------------------------------------ int CalculateCurrentOrders() int buys=0,sells=0; // Go through all orders for(int I=0;ilt;OrdersTotal();I ) // We're only interested in trades in the trading pool // Closed or canceled orders are not interesting for us if(OrderSelect(I,SELECT_BY_POS,MODE_TRADES)==false ) break; // Count positions that were opened by us for the current currency if(OrderSymbol()==Symbol() OrderMagicNumber()==MAGICNUMBER) if(OrderType()==OP_BUY) buys ; if(OrderType()==OP_SELL) sells ; // Return open positions if(buysgt;0) return(buys); else return(-sells); // ------------------------------------------------------------------ //| Calculate optimal lot size | // ------------------------------------------------------------------ double LotsOptimized() return(Lots); // ------------------------------------------------------------------ //| Check for bullish market conditions | // ------------------------------------------------------------------ bool isBullishMarket() // Calculate current and previous MACD and and current signal line double SignalCurrent=iMACD(NULL,PERIOD_D1,FastMA,SlowMA,S ignal,PRICE_CLOSE,MODE_SIGNAL,0); double MacdCurrent=iMACD(NULL,PERIOD_D1,FastMA,SlowMA,Sig nal,PRICE_CLOSE,MODE_MAIN,0); double MacdPrevious=iMACD(NULL,PERIOD_D1,FastMA,SlowMA,Si gnal,PRICE_CLOSE,MODE_MAIN,1); double RsiCurrent = iRSI(Symbol(),PERIOD_W1,RSIperiod,PRICE_CLOSE,1); return ((RsiCurrent gt; 50.0) (MacdPrevious lt; MacdCurrent) (MacdCurrent gt; SignalCurrent)); // ------------------------------------------------------------------ //| Check for bearish market conditions | // ------------------------------------------------------------------ bool isBearishMarket() // Calculate current and previous MACD and and current signal line double SignalCurrent=iMACD(NULL,PERIOD_D1,FastMA,SlowMA,S ignal,PRICE_CLOSE,MODE_SIGNAL,0); double MacdCurrent=iMACD(NULL,PERIOD_D1,FastMA,SlowMA,Sig nal,PRICE_CLOSE,MODE_MAIN,0); double MacdPrevious=iMACD(NULL,PERIOD_D1,FastMA,SlowMA,Si gnal,PRICE_CLOSE,MODE_MAIN,1); double RsiCurrent = iRSI(Symbol(),PERIOD_W1,RSIperiod,PRICE_CLOSE,1); return ((RsiCurrent lt; 50.0) (MacdPrevious gt; MacdCurrent) (MacdCurrent lt; SignalCurrent)); // ------------------------------------------------------------------ //| Check for open order conditions | // ------------------------------------------------------------------ void CheckForOpen() double TP, SL; // Only trade on beginning of a new bar if (Volume#91;0#93; gt; 1) return; // Check for buy condition if (isBullishMarket()) OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,As k-StopLoss*Point,Ask TakeProfit*Point,,MAGICNUMBER,0,Green); // Check for sell condition if (isBearishMarket()) OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,B id StopLoss*Point,Bid-TakeProfit*Point,,MAGICNUMBER,0,Red); // ------------------------------------------------------------------ //| Start function | // ------------------------------------------------------------------ void start() I have changed the following variables:TakeProfit: 200 StopLoss: 50 Lot size: 5.0 The outcome is nice: From 1st of january until today, the initial deposit of $10.000 would be almost $100.000 (see attached picture)
Perhaps I need to add: if I do a backtest with exactly the very same values from january 2007 till today, then that EA would have halfed my bank account (discontinued out at 50 percent )
Having a lot size of 3.0 it would have been almost $90.000 although...