5_8MACROSS2





/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                   5_8MACROSS.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern double Lots=0.1;
extern int StopLoss=0;
extern int TrailingStop=0;
extern int TakeProfit=0;

extern int mafastperiod=5;
extern int mafastshift=0;
extern int mafastmethod =MODE_EMA;
extern int mafastprice=PRICE_CLOSE;

extern int maslowperiod=8;
extern int maslowshift=0;
extern int maslowmethod =MODE_EMA;
extern int maslowprice=PRICE_OPEN;

datetime TimePrev=0;

//+-----------------------------------------------------------------+

int init()
   {
   return(0);
   }

//+-----------------------------------------------------------------+

int deinit()
   {
   return(0);
   }

//+-----------------------------------------------------------------+

int start()
   {
   //Trailing Stop
   TrailingAlls(TrailingStop);
   //close/Open
   if (TimePrev==Time[0])
      return(0);
   TimePrev=Time[0];
   
   //Caculate indicators
   double fast1=iMA(NULL,0,mafastperiod,mafastshift,mafastmethod,mafastprice,1);
   double fast2=iMA(NULL,0,mafastperiod,mafastshift,mafastmethod,mafastprice,2);
   double slow1=iMA(NULL,0,maslowperiod,maslowshift,maslowmethod,maslowprice,1);
   double slow2=iMA(NULL,0,maslowperiod,maslowshift,maslowmethod,maslowprice,2);

   //LONG
   if (fast1>slow1&&fast2<slow2)
      {
      closeshrts();
      OrderSend(Symbol(),OP_BUY,Lots,Ask,0,Stoplong(Ask,StopLoss),Takelong(Ask,TakeProfit),NULL,0,0,Blue);
      }//long

   //shrt
   if(fast1<slow1&&fast2>slow2)
      {
      closelongs();
      OrderSend(Symbol(),OP_SELL,Lots,Bid,0,Stopshrt(Bid,StopLoss),Takeshrt(Bid,TakeProfit),NULL,0,0,Red);
      }//shrt
   return(0);
   }
//+-----------------------------------------------------------------+

double Stoplong(double price,int stop)
   {
   if(stop==0)
      return (0.0);
   return(price-(stop*Point));
   }

//+-----------------------------------------------------------------+

double Stopshrt(double price,int stop)
   {
   if (stop==0)
      return(0.0);
   return(price+(stop*Point));
   }

//+-----------------------------------------------------------------+

double Takelong(double price,int Take)
   {
   if (Take==0)
      return(0.0);
   return(price+(Take*Point));
   }

//+-----------------------------------------------------------------+

double Takeshrt(double price,int Take)
   {
   if (Take==0)
      return(0.0);
   return(price-(Take*Point));
   }

//+-----------------------------------------------------------------+

void closelongs()
   {
   int trade;
   int trades=OrdersTotal();
   for (trade=0;trade<trades;trade++)
      {
      
      OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()!=Symbol())
         continue;
      
      if(OrderType()==OP_BUY)
         OrderClose(OrderTicket(),OrderLots(),Bid,0,Blue);
      }//for
   }

//+-----------------------------------------------------------------+

void closeshrts()
   {
   int trade;
   int trades=OrdersTotal();
   for (trade=0;trade<trades;trade++)
      {
      
      OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()!=Symbol())
         continue;
         
      if(OrderType()==OP_SELL)
         OrderClose(OrderTicket(),OrderLots(),Ask,0,Red);
      }//for
   }

//+-----------------------------------------------------------------+

void TrailingAlls(int trail)
   {
   if(trail==0)
      return;

   double stopcrnt;
   double stopcal;

   int trade;
   int trades=OrdersTotal();
   for(trade=0;trade<trades;trade++)
      {
      OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()!=Symbol())
         {
         //continue;
         }
      //LONG
      if(OrderType()==OP_BUY)
         {
         stopcrnt=OrderStopLoss();
         stopcal=Bid-(trail*Point);
         if (stopcrnt==0)
            {
            OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);
            }
         else
            if(stopcal>stopcrnt)
               {
               OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);
               }
         }//LONG
      //Shrt
      if(OrderType()==OP_SELL)
         {
         stopcrnt=OrderStopLoss();
         stopcal=Ask+(trail*Point);
         if (stopcrnt==0)
            {
            OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);
            }
         else
            if(stopcal<stopcrnt)
               {
               OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);
               }
         }//Shrt
      }
   }
  
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar


Indicator Curves created:


Indicators Used:

Moving average indicator


Custom Indicators Used:

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

It Closes Orders by itself
It can change open orders parameters, due to possible stepping strategy

Other Features:

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:1.09 Total Net Profit:63.40

BackTest : USDCHF on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.42 Total Net Profit:-718.68

BackTest : EURUSD on H1

From 2009-12-01 to 2010-01-17 Profit Factor:1.04 Total Net Profit:54.06

BackTest : USDCAD on H1

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

BackTest : EURUSD on H1

From 2009-08-01 to 2009-10-01 Profit Factor:0.62 Total Net Profit:-975.40

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.92 Total Net Profit:-168.63

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

Request Backtest for 5_8MACROSS2


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

Pair: Period: