Phoenix_EA_v2_1

Author: Copyright � 2006, Hendrick.
Price Data Components
Series array that contains open time of each bar
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategyIt Closes Orders by itself
Indicators Used
Moving average indicatorBears Power indicatorBulls Power indicator
1 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
52.00 %
Total Trades 2639
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -3.11
Gross Profit 9016.05
Gross Loss -17217.75
Total Net Profit -8201.70
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
46.00 %
Total Trades 1765
Won Trades 845
Lost trades 920
Win Rate 0.48 %
Expected payoff -4.65
Gross Profit 6868.05
Gross Loss -15071.10
Total Net Profit -8203.05
-100%
-50%
0%
50%
100%
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);
}

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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---