Phoenix_EA_v2_1





//+------------------------------------------------------------------+
//|                                                   Phoenix_v1.mq4 |
//|                                       Copyright © 2006, Hendrick |
//|A part of Phoenix is based on the EA Firebird made by TraderSeven |
//|Some parts of the code of Phoenix are made by others. If the maker| 
//|of the code was known I've mentioned their names.                 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Hendrick."



//---- input parameters
extern int        MA_Length        = 10;
extern int        MA_Timeframe     = 15;
extern double     Lots             = 1;
extern bool       MM               = true;
extern bool       RoundupLots      = false; 
extern bool       AccountIsMicro   = false;
extern bool       UseSafePips      = true;
extern int        SafePipsMinutes  = 240;
extern int        SafePipsDistance = 60;
extern double     Percent          = 0.05;
extern bool       UseSafeArea      = true;
extern double     SafeArea         = 40;
extern int        Risk             = 5; 
extern int        TakeProfit       = 60;
extern int        StopLoss         = 55;
extern int        TrailingStop     = 18;
extern bool       UseCloseSignal   = false;
extern int        TradeFrom1       = 8;
extern int        TradeUntil1      = 12;
extern int        TradeFrom2       = 13;
extern int        TradeUntil2      = 15;
extern int        TradeFrom3       = 16;
extern int        TradeUntil3      = 18;
extern int        TradeFrom4       = 19;
extern int        TradeUntil4      = 21;
extern bool       WantToGamble     = true;
extern int        GambleFrom       = 16;
extern int        GambleUntil      = 17;
extern int        GambleFactor     = 2;
extern int        P_EMA_Long       = 120;
extern int        P_EMA_Short      = 12;
extern int        P_EMA_TimeFrame  = 15;
extern int        P_EMA_Method     = 3;
extern int        P_EMA_Price      = 5;



//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {


   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {

   return(0);
  }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  
//=============== CHECK CHART NEED MORE THAN 100 BARS
   if(Bars<100)
   {
      Print("bars less than 100");
      return(0);  
   }
   
      
//=============== ADJUST LOTS IF MM=TRUE/

   if(MM) 
   {
      Lots = subLotSize();
      if(AccountIsMicro)
      {
         Lots=Lots/10;
      }
   }
//=============== ADJUST LOTS IF YOU WANT TO GAMBLE (IDEA MarvinSK)

   if(WantToGamble==true)
      {
         int ht=TimeHour(LocalTime());
         if((ht >= GambleFrom) && (ht <= (GambleUntil-1)))
            {
            Lots = (GambleFactor*Lots);
            }
      }
      
//===============  START SAFEPIPDISTANCE
  
   bool SafeTotalPips = false;
   double valTOT;

   int k=(SafePipsMinutes/MA_Timeframe);
   valTOT=(High[Highest(NULL,0,MODE_HIGH,k,0)]) - (Low[Lowest(NULL,0,MODE_LOW,k,0)]);

   if(Point==0.01) 
      valTOT=MathAbs(valTOT)*100;
   if(Point==0.0001) 
      valTOT=MathAbs(valTOT)*10000;
   if(valTOT<=SafePipsDistance)
      SafeTotalPips = true;
   if(UseSafePips == false)
      SafeTotalPips = true;


//=============== START VALID TRADE TIME

   int iHour=TimeHour(LocalTime());
   int ValidTradeTime = F_ValidTradeTime(iHour);
   
   
//=============== START REGULAR SELL/BUY SIGNALS   

   int    TE  = 0;
   double MA  = 0, AdMA = 0, iTE = 0;
   bool   AdBUYSignal = false, AdSELLSignal = false, AdBUYSELLSignal = false; 
   string SortOrder;
   
   MA =iMA(NULL,MA_Timeframe,MA_Length,0,MODE_SMA,PRICE_OPEN,0);
   
   AdMA=(iMA(NULL,P_EMA_TimeFrame,P_EMA_Long,0,P_EMA_Method,P_EMA_Price,1) - iMA(NULL,P_EMA_TimeFrame,P_EMA_Short,0,P_EMA_Method,P_EMA_Price,1));
   if(Point==0.0001) {AdMA=AdMA*1000;}
   if(Point==0.01) {AdMA=AdMA*10;}
   if(AdMA > 0.5)
      {
      AdSELLSignal = true;
      SortOrder = "SELLSignal";
      }
   if(AdMA < -0.5) 
      {
      AdBUYSignal = true;
      SortOrder = "BUYSignal";
      }
   if((AdMA > -0.5) && (AdMA < 0.5)) 
      {
      AdBUYSELLSignal = true;
      SortOrder = "BUYSELLSignal";
      }
   


   iTE=iBullsPower(NULL,0,13,6,0)+iBearsPower(NULL,0,13,6,0);
   if(Point == 0.01)   iTE = iTE*100;
   if(Point == 0.0001) iTE = iTE*10000;
   if((iTE >- SafeArea) && (iTE < SafeArea)) 
      TE=1;
   if(UseSafeArea == false)
      TE=1;

   bool SellOk, BuyOk;
   if((MA*(1+Percent/100))<Bid && ((AdSELLSignal == true)  || (AdBUYSELLSignal == true)) && TE==1 && ValidTradeTime==1 && SafeTotalPips==true) SellOk=true;
   if((MA*(1-Percent/100))>Ask && ((AdBUYSignal == true) || (AdBUYSELLSignal == true))  && TE==1 && ValidTradeTime==1 && SafeTotalPips==true) BuyOk=true;



   
//=============== START CLOSE SIGNALS

   bool CLOSEBuyOrder=false;
   bool CLOSESellOrder=false;
   if((MA*(1+Percent/100))<Bid && (AdSELLSignal == true)) CLOSEBuyOrder=true;
   if((MA*(1-Percent/100))>Ask && (AdBUYSignal == true)) CLOSESellOrder=true;
        

     
//=================== START REGULAR ORDERS ========================================================   

   int cnt, ticket, total, OrderIsOpen=0;
   total  = OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if((OrderSymbol()==Symbol())&& (OrderMagicNumber()==12345))
         {
         OrderIsOpen=1;
         break;
         }
      else
         continue; 
      }  
    if(OrderIsOpen==0) 
      {
      if(BuyOk==true) 
         {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,SortOrder,12345,0,GreenYellow);
         if(ticket>0)
            {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
            }
            else Print("Error opening BUY order : ",GetLastError()); 
            return(0);
         }

      if(SellOk==true)
         {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,SortOrder,12345,0,Red);
         if(ticket>0)
            {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
            }
            else Print("Error opening SELL order : ",GetLastError()); 
            return(0);
         }
      }
     
               
//=============== CHECK CLOSE/TRAILING STOP REGULAR ORDERS  
   total = OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if((OrderType() <= OP_SELL) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == 12345))
         {
         if(OrderType() == OP_BUY)
            {
            if(TrailingStop > 0)
               {
               if((Bid-OrderOpenPrice()) > (Point*TrailingStop))
                  {
                  if((OrderStopLoss()) < (Bid-Point*TrailingStop))
                     {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,GreenYellow);
                     return(0);
                     }
                  } 
               }                  
 
               if((UseCloseSignal == true) && (CLOSEBuyOrder == true))
                  {
                  OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); 
                  return(0); 
                  }
             }

            if(OrderType() == OP_SELL)
               {
               if(TrailingStop > 0)
                  {
                  if(OrderOpenPrice()-Ask>Point*TrailingStop)
                     {
                     if(OrderStopLoss()>Ask+Point*TrailingStop)
                        {
                        OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                        return(0);              
                        }
                     }     
                  }
               if((UseCloseSignal == true) && (CLOSESellOrder == true))
                  {
                  OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); 
                  return(0); 
                  }

                }
             }
          }

          


Comment("\n","AdMA= ",AdMA,"\n","YOUR SafePip Distance= ",SafePipsDistance,"\n","SafePip Distance NOW= ",valTOT,"\n","YOUR SafeArea= ",SafeArea,"\n","SafeArea NOW= ",MathAbs(iTE));


//==================THIS IS THE END
}      

//+------------------------------------------------------------------+
//| expert functions                                                 |
//+------------------------------------------------------------------+


//=============== FUNCTION VALID TRADE TIME

int F_ValidTradeTime (int iHour)
   {
      if(((iHour >= TradeFrom1) && (iHour <= (TradeUntil1-1)))||((iHour>= TradeFrom2) && (iHour <= (TradeUntil2-1)))||((iHour >= TradeFrom3)&& (iHour <= (TradeUntil3-1)))||((iHour >= TradeFrom4) && (iHour <=(TradeUntil4-1))))
      {
       return (1);
      }
      else
       return (2);
   }  


//=============== FUNCTION MONEY FUNCTION (SOURCE : CODERSGURU)

double subLotSize()
{
     double lotMM = MathCeil(AccountFreeMargin() *  Risk / 1000) / 100;
	  
	  if(AccountIsMicro==false) //normal account
	  {
	     if(lotMM < 0.1)                  lotMM = Lots;
	     if((lotMM > 0.5) && (lotMM < 1)) lotMM = 0.5;
	     if(lotMM > 1.0)                  lotMM = MathCeil(lotMM);
	     if(lotMM > 100)                  lotMM = 100;
	  }
	  
	  if(RoundupLots==true) 
     {
         lotMM = MathRound(lotMM*10)/10;
     }
	  return (lotMM);
}

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





Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:


Indicators Used:

Moving average indicator
Bears Power indicator
Bulls Power indicator


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders

It automatically opens orders when conditions are reached
It can change open orders parameters, due to possible stepping strategy
It Closes Orders by itself

Other Features:

BackTest : EURUSD on H1

From 2009-08-01 to 2009-10-01 Profit Factor:0.52 Total Net Profit:-9725.00

BackTest : EURUSD on H1

From 2009-12-01 to 2010-01-17 Profit Factor:1.08 Total Net Profit:3690.00

BackTest : EURUSD on H1

From 2010-03-01 to 2010-03-27 Profit Factor:1.13 Total Net Profit:3875.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.94 Total Net Profit:-5405.00

BackTest : USDCAD on H1

From 2009-01-01 to 2010-01-01 Profit Factor:0.82 Total Net Profit:-9819.47

BackTest : USDCAD on H1

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

BackTest : USDCHF on H1

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

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.46 Total Net Profit:-9823.17

Request Backtest for Phoenix_EA_v2_1


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

Pair: Period: