simple ea?

 

hi i created this simple ea with an eacreator .... http://sufx.core.t3-ism.net

it should buy when eurusd 5min crosses over eurusd 30min and sell when eurusd 5min crosses under eurusd 30min. should be very simple....

while compilating no errors where shown.

can anyone please advise?

many thanks!

regards

gts_sven

//+------------------------------------------------------------------+
//| This MQL is generated by Expert Advisor Builder                  |
//|                http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ |
//|                                                                  |
//|  In no event will author be liable for any damages whatsoever.   |
//|                      Use at your own risk.                       |
//|                                                                  |
//+------------------- DO NOT REMOVE THIS HEADER --------------------+

#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

#property copyright "Expert Advisor Builder"
#property link      "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

extern int MagicNumber = 0;
extern bool SignalMail = False;
extern bool EachTickMode = True;
extern double Lots = 1.0;
extern int Slippage = 3;
extern bool UseStopLoss = True;
extern int StopLoss = 30;
extern bool UseTakeProfit = True;
extern int TakeProfit = 60;
extern bool UseTrailingStop = True;
extern int TrailingStop = 30;

int BarCount;
int Current;
bool TickCheck = False;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   BarCount = Bars;

   if (EachTickMode) Current = 0; else Current = 1;

   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() {
   return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel, TakeProfitLevel;



   if (EachTickMode && Bars != BarCount) TickCheck = False;
   Total = OrdersTotal();
   Order = SIGNAL_NONE;

   //+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+


double Buy1_1 = iClose("EURUSD", PERIOD_M5, Current + 0);
double Buy1_2 = iOpen("EURUSD", PERIOD_M30, Current + 0);


double CloseBuy1_1 = iClose("EURUSD", PERIOD_M5, Current + 0);
double CloseBuy1_2 = iOpen("EURUSD", PERIOD_M30, Current + 0);


   
   //+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   //Check position
   bool IsTrade = False;

   for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+

                     if (CloseBuy1_1 < CloseBuy1_2) Order = SIGNAL_CLOSEBUY;


            //+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if(Bid - OrderOpenPrice() > Point * TrailingStop) {
                  if(OrderStopLoss() < Bid - Point * TrailingStop) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         } else {
            //Close

            //+------------------------------------------------------------------+
            //| Signal Begin(Exit Sell)                                          |
            //+------------------------------------------------------------------+

            

            //+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+

            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;
               IsTrade = False;
               continue;
            }
            //Trailing stop
            if(UseTrailingStop && TrailingStop > 0) {                 
               if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
                  if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         }
      }
   }

   //+------------------------------------------------------------------+
   //| Signal Begin(Entry)                                              |
   //+------------------------------------------------------------------+

   if (Buy1_1 > Buy1_2) Order = SIGNAL_BUY;

   

   //+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+

   //Buy
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                                Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
                        } else {
                                Print("Error opening BUY order : ", GetLastError());
                        }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }

   //Sell
   if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         //Check free margin
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                                Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
                        } else {
                                Print("Error opening SELL order : ", GetLastError());
                        }
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }

   if (!EachTickMode) BarCount = Bars;

   return(0);
}
//+------------------------------------------------------------------+
 
gts_sven:

hi i created this simple ea with an eacreator .... http://sufx.core.t3-ism.net

it should buy when eurusd 5min crosses over eurusd 30min and sell when eurusd 5min crosses under eurusd 30min. should be very simple....

while compilating no errors where shown.

can anyone please advise?

many thanks!

regards

gts_sven

gts_swen, I downloaded it, compiled it and ran it without alteration. It wiped out $3,838 in 134 trades. Some EA!

Bars in test 4177

Ticks modelled 805392
Modelling quality 90.00%
Mismatched charts errors 34
Initial deposit 5000.00
Total net profit -3686.00
Gross profit 152.00
Gross loss -3838.00
Profit factor 0.04
Expected payoff -27.51
Absolute drawdown 3686.00
Maximal drawdown 3686.00 (73.72%)
Relative drawdown 73.72% (3686.00)
Total trades 134
Short positions (won %) 0 (0.00%)
Long positions (won %) 134 (4.48%)
Profit trades (% of total) 6 (4.48%)
Loss trades (% of total) 128 (95.52%)
Largest
profit trade 60.00
loss trade -30.00
Average
profit trade 25.33
loss trade -29.98
Maximum
consecutive wins (profit in money) 2 (19.00)
consecutive losses (loss in money) 51 (-1528.00)
Maximal
consecutive profit (count of wins) 60.00 (1)
consecutive loss (count of losses) -1528.00 (51)
Average
consecutive wins 1
consecutive losses 21
 

Hi gts_sven,

What you expect people to comment ?

You shall try run it on mt4 1st before posting here.

 

@erekit

tried it on mt4 before posting- not working...

maybe sth. wrong with my testing settings!?

regards

sven

 
no clue why it is not working!? any tips?
 
Sven, if you engage a programmer to create software for you and it doesn't work, the thing to do is to contact the programmer. In this case the programmer is a piece of software. So, in the first instance you should take your troubles to the folks who provide that software. One of the first things they will ask is "what is being reported in the logs". Now you know where to begin. CB
 

cb many thanks for your response. there is nothing reported in the logs.

i was just wondering why encomp can run the system? maybe sth is wrong with my settings. i am using mt4 provided by fx pro...?

 

I suggest you direct your question to them Sven.

CB

 
gts_sven:
no clue why it is not working!? any tips?

My earlier test was without making changes to the code.

After it produced such a disastrous result, I had a closer look.

Firstly, it is based on 4-digit pricing, so I added this to init() and replaced all "Point" references in the code to "MyPoint".

   MyPoint = Point;
   if(Digits == 5 || Digits == 3) {
      MyPoint = MyPoint*10;
   }

Secondly, I noticed that the EA took no short positions (134 longs out of 134 trades).

So I added this line above //Sell

   if (Buy1_1 < Buy1_2) Order = SIGNAL_SELL; //was missing

Then I ran it again for the same period. It should be noted that previously it ran out of money after 134 trades.

This time it went for the full month 2010.05.01 to 2010.06.01.

On a static position size of 1 lot the EA grew $5,000 to $6,825.14, an outstanding result for one month trading.

The worry is the maximal drawdown of $6,801, 10 consecutive losses, and huge money flow +$57,051 -$55,225.

I think with a bit of filtering to reduce the total trades and loss trades percentage, this could be a great EA.

Here is the Report...

Bars in test 7086
Ticks modelled 1626869
Modelling quality 25.00%
Mismatched charts errors 0
Initial deposit 5000.00
Total net profit 1825.14
Gross profit 57051.07
Gross loss -55225.93
Profit factor 1.03
Expected payoff 3.71
Absolute drawdown 22.00
Maximal drawdown 6801.70 (51.73%)
Relative drawdown 51.73% (6801.70)
Total trades 492
Short positions (won %) 281 (51.25%)
Long positions (won %) 211 (32.23%)
Profit trades (% of total) 212 (43.09%)
Loss trades (% of total) 280 (56.91%)
Largest
profit trade 600.00
loss trade -301.14
Average
profit trade 269.11
loss trade -197.24
Maximum
consecutive wins (profit in money) 7 (2153.00)
consecutive losses (loss in money) 10 (-2402.00)
Maximal
consecutive profit (count of wins) 2400.00 (4)
consecutive loss (count of losses) -2402.00 (10)
Average
consecutive wins 2
consecutive losses 2

 
engcomp:

I think with a bit of filtering to reduce the total trades and loss trades percentage, this could be a great EA.


This is essentially a SMA(5),SMA(30) crossover strategy on a M1 chart. Simple SMA crossovers are sexy for backtesting, always have been, but forward testing not so much.
 
1005phillip:

This is essentially a SMA(5),SMA(30) crossover strategy on a M1 chart. Simple SMA crossovers are sexy for backtesting, always have been, but forward testing not so much.

Not quite, Phillip

Let's break down the code. Firstly, I suggest these changes...

double MyPoint, slip;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   BarCount = Bars; // original code

   if (EachTickMode) Current = 0; else Current = 1; // original code

   MyPoint = Point;
   slip = Slippage; // to prevent the extern value being multiplied with 10 again in case of reinitialization
   if(Digits == 5 || Digits == 3) {
      MyPoint = MyPoint*10;
      slip = slip*10;
   }

   return(0); // original code
}

Note that "Current" can be 0? Let's look where "Current" is used.

double Buy1_1 = iClose("EURUSD", PERIOD_M5, Current + 0);
double Buy1_2 = iOpen("EURUSD", PERIOD_M30, Current + 0);
double CloseBuy1_1 = iClose("EURUSD", PERIOD_M5, Current + 0);
double CloseBuy1_2 = iOpen("EURUSD", PERIOD_M30, Current + 0);

Am I correct to think that iClose of [0] is the current tick?

With M1, M5 and M30 side by side, all show the same current price, which I think is the current close.

Where are these values used?

if (Buy1_1 > Buy1_2) Order = SIGNAL_BUY;
if (Buy1_1 < Buy1_2) Order = SIGNAL_SELL; //was missing
if (CloseBuy1_1 < CloseBuy1_2) Order = SIGNAL_CLOSEBUY;

CloseBuy1_1 > CloseBuy1_2 is not used in the present code but is an } else {.

A buy signal is generated when the current tick crosses above the current M30 Open.

A sell signal is generated when the current tick crosses below the current M30 Open.

It seems to me you wouldn't need M1 or M5 to test this condition.

Therefore, the EA is not "essentially a SMA(5), SMA(30) crossover strategy on a M1 chart".

It strikes me as an approach that is so crazy it has never been tried before, but may have merit.

There is plenty of room for filtering, which hopefully won't destroy the crazy concept.