inpossibilium nulla obligatio est





//+------------------------------------------------------------------+
//|                                          supreme 1st version.mq4 |
//|             Huisman84Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Huisman84Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern double Prots = 20;
extern double StopLoss = 800;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  double MAFcurrent, MAFprevious;
  double MAScurrent, MASprevious;
  double Lots;
  int cnt, ticket, total;
  
//----
  if (Bars<100)
    {
   Print("bars less than 100");
   return(0);
    }
  
//----
   MAFcurrent=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,0);
   MAFprevious=iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,1);
   MAScurrent=iMA(NULL,0,25,0,MODE_SMA,PRICE_CLOSE,0);
   MASprevious=iMA(NULL,0,25,0,MODE_SMA,PRICE_CLOSE,1);
   Lots = 0.5;

   
   total=OrdersTotal();
   if(total<1) 
     {
      // no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // check for long position (BUY) possibility  
      if(MAFcurrent>MAScurrent && MAFprevious<MASprevious)
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,0,"supreme",16384,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("orderSend failed with error #", GetLastError());
         return(0);
        }
      // check for short position (SELL) possibility
      if(MAFcurrent<MAScurrent && MAFprevious>MASprevious)
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,0,"supreme",16384,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("orderSend failed with error #", GetLastError());
         return(0);
        }
      return(0);
     }  // exit market correctly...
       for(cnt=0;cnt<total;cnt++)
         {
          OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
          if(OrderType()<=OP_SELL &&   // check for opened position 
             OrderSymbol()==Symbol())  // check for symbol
            {
             if(OrderType()==OP_BUY)   // long position is opened
               {
                // should it be closed?  
                if(MAFcurrent<MAScurrent && MAFprevious>MASprevious)
                    {
                     OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                     return(0); // exit
                    }
               }
              else // go to short position
               {
                  // should it be closed?
                if(MAFcurrent>MAScurrent && MAFprevious<MASprevious)
                  {
                   OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
                   return(0); // exit
                  }
               }
            }         
         }         
       return(0);
  }








Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
It Closes Orders by itself

Other Features:


BackTest : EURUSD on H1

From 2009-08-01 to 2009-10-01 Profit Factor:0.49 Total Net Profit:-4409.00

BackTest : EURUSD on H1

From 2010-04-01 to 2010-04-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-05-01 to 2010-05-31 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

From 2010-06-01 to 2010-06-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.58 Total Net Profit:-4367.55

BackTest : USDCAD on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.59 Total Net Profit:-1273.74

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.88 Total Net Profit:-298.62

Request Backtest for inpossibilium nulla obligatio est


From : (yyyy/mm/dd) To: (yyyy/mm/dd)

Pair: Period: