Navigation:Home > Content >

[[_Lock_ProfiT_]].mq4

Time: 2011-06-20 | Download file:[[_Lock_ProfiT_]].mq4

//+------------------------------------------------------------------+
//|                                                  Lock Profit.mq4 |
//|                                      Copyright © 2007, FIREDAVE. |
//|                                         http://www.fx-review.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, FIREDAVE."
#property link      "http://www.fx-review.com"

//+------------------------------------------------------------------+
//| INCLUDES FILES                                                   |
//+------------------------------------------------------------------+
#include 

//+------------------------------------------------------------------+
//| EXPERT ADVISOR EXTERN VARIABLE                                   |
//+------------------------------------------------------------------+
extern string     Expert_Name       = "-----------------------[[ Lock ProfiT ]]-----------------------";
extern int        Target1           = 15,
                  LockProfiT1         = 4,
                  Target2           = 30,
                  LockProfiT2         = 20,
                  Target3           = 60,
                  LockProfiT3         = 40;
extern string     Order_Setting     = "---------------------< Order Setting >---------------------";
extern int        NumberOfTries     = 10,
                  Slippage          = 3;
extern string     Testing_Parameters= "---------------< Back Test Parameter >---------------";
extern bool       PrintControl      = true;         

//+------------------------------------------------------------------+
//| EXPERT ADVISOR PROGRAM SETTING AND GLOBAL VARIABLES              |
//+------------------------------------------------------------------+
string            TicketComment     = "Lock ProfiT";
bool              bTarget1          = true,
                  bTarget2          = false,
                  bTarget3          = false;

//+------------------------------------------------------------------+
//| EXPERT ADVISOR ADDITIONAL GLOBAL VARIABLES                       |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| INITIALIZATION FUNCTION                                          |
//+------------------------------------------------------------------+
int init()
{
}

//+------------------------------------------------------------------+
//| DE-INITIALIZATION FUNCTION                                       |
//+------------------------------------------------------------------+
int deinit()
{
}


//+------------------------------------------------------------------+
//| EXPERT ADVISOR START                                             |
//+------------------------------------------------------------------+
int start()
{

//+------------------------------------------------------------------+
//| EXPERT ADVISOR LOCAL VARIABLES                                   |
//+------------------------------------------------------------------+
   int   
         cnt,
         ticket,
         total;

//+------------------------------------------------------------------+
//| CHECK CHART NEED MORE THAN 100 BARS                              |
//+------------------------------------------------------------------+
   if(Bars<100)
   {
      Print("bars less than 100");
      return(0);  
   }

//+------------------------------------------------------------------+
//| CHECK SETTING STOPLOSS AND TARGET                                      |
//+------------------------------------------------------------------+
   if(LockProfiT1>Target1 ||
      LockProfiT2>Target2 ||
      LockProfiT3>Target3)
      Comment("Setting Target and StopLoss Error !");

//+------------------------------------------------------------------+
//|                                          |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| LOCK PROFIT                                                    |
//+------------------------------------------------------------------+
   if(Target1>0 &&
      subOrdersTotal()>0 &&
      (bTarget1 || bTarget2 || bTarget3))
   {

      total = OrdersTotal();
      for(cnt=0;cnt=Point*Target1 &&
                     OrderStopLoss()0) bTarget2 = true;
                     return(0);
                  }
               }

               if(bTarget2)
               {
                  if(Bid-OrderOpenPrice()>=Point*Target2 &&
                     OrderStopLoss()0) bTarget3 = true;
                     return(0);
                  }
               }

               if(bTarget3)
               {
                  if(Bid-OrderOpenPrice()>=Point*Target3 &&
                     OrderStopLoss()=Point*Target1 &&
                     (OrderStopLoss()>OrderOpenPrice()-Point*LockProfiT1 || OrderStopLoss()==0))
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*LockProfiT1,OrderTakeProfit(),0,Red);
                     //bTarget1 = false;
                     if(Target2>0) bTarget2 = true;
                     return(0);
                  }
               }

               if(bTarget2)
               {
                  if(OrderOpenPrice()-Ask>=Point*Target2 &&
                     OrderStopLoss()>OrderOpenPrice()-Point*LockProfiT2)
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*LockProfiT2,OrderTakeProfit(),0,Red);
                     //bTarget2 = false;
                     if(Target3>0) bTarget3 = true;
                     return(0);
                  }
               }

               if(bTarget3)
               {
                  if(OrderOpenPrice()-Ask>=Point*Target3 &&
                     OrderStopLoss()>OrderOpenPrice()-Point*LockProfiT3)
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-Point*LockProfiT3,OrderTakeProfit(),0,Red);
                     //bTarget3 = false;
                     return(0);
                  }
               }
            }
         }
      }               
   }                  

   return(0);
}

//+------------------------------------------------------------------+
//| END PROGRAM                                                      |
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
//| FUNCTION DEFINITIONS                                             |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| FUNCTION : NUMBER OF ORDER BASE ON SYMBOL                        |
//| SOURCE   : n/a                                                   |
//| MODIFIED : FIREDAVE                                              |
//+------------------------------------------------------------------+
int subOrdersTotal()
{
   int
      cnt, 
      total,
      ordertotal;

   total = OrdersTotal();
   for(cnt=0;cnt        

Recommend