Hey guys!

This is my first post in this forum. I am new into Foreign Exchange trading - about 2 months maybe.

I study computer science so I've got some skills in programming - at least, I must have
When I read that it is likely to programm the MT4 with a C-style such as syntax, I wished to give it a try - so I started studying the MQL-API and analyzed those EAs that came together with MT4.

. . .that was yesterday. Today I wish to present my first EA.
Maybe it is usefull for some of you. Any feedback is welcome - wether it's coding conversation or style of the trading system.

So here's my first EA - very simple, very basic:

Inserted Code // ------------------------------------------------------------------ //| EA #1 | //| ===== | //| Date: 02.08.2008 | //| Author: AdamP | // ------------------------------------------------------------------ #define MAGICNUMBER 01082008 extern double Lots = 1.0; extern double TakeProfit = 80; extern double StopLoss = 60; // ------------------------------------------------------------------ //| 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 that are 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,12,26,9,PRICE_C LOSE,MODE_SIGNAL,0); double MacdCurrent=iMACD(NULL,PERIOD_D1,12,26,9,PRICE_CLO SE,MODE_MAIN,0); double MacdPrevious=iMACD(NULL,PERIOD_D1,12,26,9,PRICE_CL OSE,MODE_MAIN,1); double RsiCurrent = iRSI(Symbol(),PERIOD_W1,14,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,12,26,9,PRICE_C LOSE,MODE_SIGNAL,0); double MacdCurrent=iMACD(NULL,PERIOD_D1,12,26,9,PRICE_CLO SE,MODE_MAIN,0); double MacdPrevious=iMACD(NULL,PERIOD_D1,12,26,9,PRICE_CL OSE,MODE_MAIN,1); double RsiCurrent = iRSI(Symbol(),PERIOD_W1,14,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() IsTradeAllowed()==false) return; // If we have no open position check for opening one if(CalculateCurrentOrders()==0) CheckForOpen(); Some keynotes:Optimized for EURUSD Using daily charts and weekly charts
Only 1 Position opened at the Exact Same time Fixed TakeProfit and StopLoss
I have backtested it to the year 2008 and 2007 on the EURUSD chart.
But it's also feasible to use it together with other charts - in that case, you should change the TakeProfit and StopLoss variables.

The idea is quite simple. The following two indiors are used:MACD (12,26,9)
RSI (14) The following algorithm (oh, you call it trading system, right? ) Is used:Check if has opened? quit! Check if we are at the start of a new bar (daily chart) no? quit! Check wether we are in a bullish or a bearish trend A bullish fashion is indied that way:The RSI sign of the current week's bar has to be greater than 50, and the MACD daily value has to be smaller than the current MACD daily value, and the current MACD daily value has to be higher than the current MACD daily sign A bearish trend is indied the contrary direction:RSI sign of the current week Has to Be smaller than 50, and the precvious MACD daily value Has to Be higher than the current MACD daily value, and the current MACD daily value Has to Be smaller than the current MACD daily sign If we are in a bullish fashion, buy with TakeProfit 80 and StopLoss 60, in a bearish trend sell with same TakeProfit and StopLoss First attached picture is a backtest of the EURUSD out of 1st of january 2008 until today with a starting budget of $10.000 and a lot size of 1.0, TP 80 and SL 60.

Second pictures demones a buying and a selling signal. But this isn't 100% correct, since the RSI is on a daily basis, although this EA checks the worth.

Edit: I'm using a fixed lot size without any cash or risk management right now.

Any comments welcome!


https://www.cliqforex.com/attachment...1850390684.ex4