10Points_4_Ind_v2e





//+------------------------------------------------------------------+
//|                                           10Points_4_Ind_v2e.mq4 |
//|                              Copyright © 2005, Alejandro Galindo |
//|                                              http://elCactus.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Alejandro Galindo"
#property link      "http://elCactus.com"

extern double Lots               = 0.1;
extern double TakeProfit         = 30;
extern int    Pips               = 20;
extern int    MaxTrades          = 15;
extern double Multiplier         = 2;
extern string Indicator          ="TURBO";
extern int    H_level            = 70;
extern int    L_level            = 30;
extern int    mm                 = 0;
extern int    risk               = 5;
extern int MinimumEquityForTrade = 300;//t_david 5/4/07
extern int    MaxAllowedDD       = 300;//t_david 5/4/07  This should be a positive value , the expert will convert it to a negative

bool FirstRun = True;//t_david 5/13/07
string opentrades;//t_david 5/13/07

int prevtime=0;//t_david 5/8/07
extern bool CloseAllTrades = false;//t_david 5/4/07
int AccountisNormal=0;
int SecureProfit=100;

int AccountProtection=1;
int OrderstoProtect=3;
double InitialStop = 0;
double TrailingStop = 15;
int  OpenOrders=0, cnt=0;
int  Slippage=5;
double sl=0, tp=0;
double BuyPrice=0, SellPrice=0;
double lotsi=0, mylotsi=0;
int mode=0, myOrderType=0, myBuyOrderType=0, mySellOrderType=0;
bool ContinueOpening=True;
double LastPrice=0;
int  PreviousOpenOrders=0;
double AllOrdersDD=0;//t_david 5/4/07
double Profit=0;
int LastTicket=0, LastType=0;
double LastClosePrice=0, LastLots=0;
double Pivot=0;
double PipValue=0;
string text="", text2="";

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//---- 
   
   if (FirstRun)//t_david 5/13/07
    {
     opentrades = AccountNumber()+"_10Points_4_Ind_v2e";
     if (!GlobalVariableCheck(opentrades)) { GlobalVariableSet(opentrades,0); }
     if (GlobalVariableCheck(opentrades) && GlobalVariableGet(opentrades) > 0) { GlobalVariableSet(opentrades,365); }
     FirstRun=False;
    }
   
   if (CloseAllTrades && prevtime < Time[0])//t_david 5/13/07
    { Alert(Symbol(),"CloseAllTrades Has Worked Re-Start Expert");
      GlobalVariableSet(opentrades,365);
      Comment("\n  GlobalVariableGet(opentrades) :  ",GlobalVariableGet(opentrades),
              "\n",
              "\n  1 - Remove Expert From All Charts",
              "\n",
              "\n  2 - F3 and Delete Global Variable",
              "\n",
              "\n  3 - Adjust MinimumEquityForTrade and MaxAllowedDD",
              "\n",
              "\n  4 - Attach Expert");
      prevtime = Time[0];
      return(0);
    }
   
   double ind;
   
   if (!CloseAllTrades && GlobalVariableGet(opentrades) == 0)//t_david 5/13/07
   {
   
   if (AccountisNormal==1)
   {
	  if (mm!=0) { lotsi=MathCeil(AccountBalance()*risk/10000); }
		else { lotsi=Lots; }
   } else {  // then is mini
    if (mm!=0) { lotsi=MathCeil(AccountBalance()*risk/10000)/100; }
		else { lotsi=Lots; }
   }

   if (lotsi>100){ lotsi=100; }
   
   OpenOrders=0;
   for(cnt=0;cnt<OrdersTotal();cnt++)   
   {
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  if (OrderSymbol()==Symbol())
	  {				
	  	  OpenOrders++;
	  }
   }     
   
   if (PipValue==0) { PipValue=9; }
   
   if (PreviousOpenOrders>OpenOrders) 
   {	  
	  for(cnt=OrdersTotal();cnt>=0;cnt--)
	  {
	     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  	  mode=OrderType();
		  if (OrderSymbol()==Symbol()) 
		  {
			if (mode==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Blue); }
			if (mode==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red); }
			return(0);
		 }
	  }
   }

   PreviousOpenOrders=OpenOrders;
   if (OpenOrders>=MaxTrades) 
   {
	  ContinueOpening=False;
   } else {
	  ContinueOpening=True;
   }

   if (LastPrice==0) 
   {
	  for(cnt=0;cnt<OrdersTotal();cnt++)
	  {	
	    OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
		 mode=OrderType();	
		 if (OrderSymbol()==Symbol()) 
		 {
			LastPrice=OrderOpenPrice();
			if (mode==OP_BUY) { myOrderType=2; }
			if (mode==OP_SELL) { myOrderType=1;	}
		 }
	  }
   }
   
   if (OpenOrders<1) 
   {
	  myOrderType=3;
	  if (Indicator=="RSI")
	    {
	        if(iRSI(NULL,Period(),14,PRICE_CLOSE,0)>H_level)
	           myOrderType=1;
	        if(iRSI(NULL,Period(),14,PRICE_CLOSE,0)<L_level)
	           myOrderType=2;
	        
	    }
	  if (Indicator=="MACD")
        {
            if (iMACD(Symbol(),Period(),14,26,9,PRICE_CLOSE,MODE_MAIN,0)>iMACD(Symbol(),0,14,26,9,PRICE_CLOSE,MODE_MAIN,1)) 
               myOrderType=2;
            if (iMACD(Symbol(),Period(),14,26,9,PRICE_CLOSE,MODE_MAIN,0)<iMACD(Symbol(),0,14,26,9,PRICE_CLOSE,MODE_MAIN,1)) 
               myOrderType=1;
        }
	  if (Indicator=="TURBO")
        {
          if (iCustom(Symbol(),Period(),"Turbo_JRSX",14,MODE_MAIN,0)>  H_level) 
               myOrderType=1;
          if (iCustom(Symbol(),Period(),"Turbo_JRSX",14,MODE_MAIN,0)<  L_level) 
               myOrderType=2;
        }
 	  if (Indicator=="TURBO2")
        {
          if (iCustom(Symbol(),Period(),"Turbo_JVEL",14,MODE_MAIN,0)>  0.10) 
               myOrderType=1;
          if (iCustom(Symbol(),Period(),"Turbo_JVEL",14,MODE_MAIN,0)< -0.10)  
               myOrderType=2;
        }
	  if (Indicator=="STOCH")
	    {
          if(iStochastic(Symbol(),Period(),5,3,9,MODE_SMA,0,MODE_MAIN,0)>H_level && iStochastic(Symbol(),0,5,3,3,MODE_SMA,0,MODE_SIGNAL,1)>H_level)
               myOrderType=1;
          if(iStochastic(Symbol(),Period(),5,3,9,MODE_SMA,0,MODE_MAIN,0)<L_level && iStochastic(Symbol(),0,5,3,3,MODE_SMA,0,MODE_SIGNAL,1)<L_level)
               myOrderType=2;
	    }
   }

   // if we have opened positions we take care of them
   for(cnt=OrdersTotal();cnt>=0;cnt--)
   {
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  if (OrderSymbol() == Symbol()) 
	  {	
	  	  if (OrderType()==OP_SELL) 
	  	  {			
	  	  	  if (TrailingStop>0) 
			  {
				  if (OrderOpenPrice()-Ask>=(TrailingStop+Pips)*Point) 
				  {						
					 if (OrderStopLoss()>(Ask+Point*TrailingStop))
					 {			
					    OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderClosePrice()-TakeProfit*Point-TrailingStop*Point,800,Purple);
	  					 return(0);	  					
	  				 }
	  			  }
			  }
	  	  }
   
	  	  if (OrderType()==OP_BUY)
	  	  {
	  		 if (TrailingStop>0) 
	  		 {
			   if (Bid-OrderOpenPrice()>=(TrailingStop+Pips)*Point) 
				{
					if (OrderStopLoss()<(Bid-Point*TrailingStop)) 
					{					   
					   OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderClosePrice()+TakeProfit*Point+TrailingStop*Point,800,Yellow);
                  return(0);
					}
  				}
			 }
	  	  }
   	}
   }
   
   AllOrdersDD=0;//t_david 5/4/07
   Profit=0;
   LastTicket=0;
   LastType=0;
	LastClosePrice=0;
	LastLots=0;	
	for(cnt=0;cnt<OrdersTotal();cnt++)
	{
	  OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  AllOrdersDD+=OrderProfit();//t_david 5/4/07
	  if (OrderSymbol()==Symbol()) 
	  {			
	  	   LastTicket=OrderTicket();
			if (OrderType()==OP_BUY) { LastType=OP_BUY; }
			if (OrderType()==OP_SELL) { LastType=OP_SELL; }
			LastClosePrice=OrderClosePrice();
			LastLots=OrderLots();
			if (LastType==OP_BUY) 
			{
				//Profit=Profit+(Ord(cnt,VAL_CLOSEPRICE)-Ord(cnt,VAL_OPENPRICE))*PipValue*Ord(cnt,VAL_LOTS);				
				if (OrderClosePrice()<OrderOpenPrice()) 
					{ Profit=Profit-(OrderOpenPrice()-OrderClosePrice())*OrderLots()/Point; }
				if (OrderClosePrice()>OrderOpenPrice()) 
					{ Profit=Profit+(OrderClosePrice()-OrderOpenPrice())*OrderLots()/Point; }
			}
			if (LastType==OP_SELL) 
			{
				//Profit=Profit+(Ord(cnt,VAL_OPENPRICE)-Ord(cnt,VAL_CLOSEPRICE))*PipValue*Ord(cnt,VAL_LOTS);
				if (OrderClosePrice()>OrderOpenPrice()) 
					{ Profit=Profit-(OrderClosePrice()-OrderOpenPrice())*OrderLots()/Point; }
				if (OrderClosePrice()<OrderOpenPrice()) 
					{ Profit=Profit+(OrderOpenPrice()-OrderClosePrice())*OrderLots()/Point; }
			}
			//Print(Symbol,":",Profit,",",LastLots);
	  }
   }
	
	Profit=Profit*PipValue;
	text2="Profit: $"+DoubleToStr(Profit,2)+" +/-";
   if (OpenOrders>=(MaxTrades-OrderstoProtect) && AccountProtection==1) 
   {	    
	     //Print(Symbol,":",Profit);
	     if (Profit>=SecureProfit) 
	     {
	        OrderClose(LastTicket,LastLots,LastClosePrice,Slippage,Yellow);
	        ContinueOpening=False;
	     }
   }

      if (!IsTesting()) 
      {
	     if (myOrderType==3) { text="No conditions to open trades"; }
	     else { text=""; }
	     Comment("\n","MaxAllowedDD :  ",MaxAllowedDD," ,  AllOrdersDD :  ",AllOrdersDD,//t_david 5/13/07
	             "\n","MinimumEquityForTrade :  ",MinimumEquityForTrade," ,  AccountEquity :  ",AccountEquity(),//t_david 5/8/07
	             "\nLastPrice=",LastPrice," Previous open orders=",PreviousOpenOrders,
	             "\nContinue opening=",ContinueOpening," OrderType=",myOrderType,
	             "\n",text2,
	             "\nLots=",lotsi,
	             "\n",text);
      }

      if (myOrderType==1 && ContinueOpening) 
      {	
	     if ((Bid-LastPrice)>=Pips*Point || OpenOrders<1) 
	     {		
		    SellPrice=Bid;				
		    LastPrice=0;
		    if (TakeProfit==0) { tp=0; }
		    else { tp=SellPrice-TakeProfit*Point; }	
		    if (InitialStop==0) { sl=0; }
		    else { sl=SellPrice+InitialStop*Point;  }
		    if (OpenOrders!=0) 
		    {
			      mylotsi=lotsi;			
			      for(cnt=1;cnt<=OpenOrders;cnt++)
			      {
				     mylotsi=NormalizeDouble(mylotsi*Multiplier,2);
				     Comment(mylotsi);
			      }
		    } else { mylotsi=lotsi; }
		    if (mylotsi>100) { mylotsi=100; }
		    if (mylotsi>1)
		       {
		          tp     =NormalizeDouble(tp+(tp*0.15),2);
		          mylotsi=NormalizeDouble(mylotsi-(mylotsi*0.15),2);
		       }
		    OrderSend(Symbol(),OP_SELL,mylotsi,SellPrice,Slippage,sl,tp,NULL,0,0,Red);		    		    
		    return(0);
	     }
      }
      
      if (myOrderType==2 && ContinueOpening)
      {
	     if ((LastPrice-Ask)>=Pips*Point || OpenOrders<1) 
	     {		
		    BuyPrice=Ask;
		    LastPrice=0;
		    if (TakeProfit==0) { tp=0; }
		    else { tp=BuyPrice+TakeProfit*Point; }	
		    if (InitialStop==0)  { sl=0; }
		    else { sl=BuyPrice-InitialStop*Point; }
		    if (OpenOrders!=0) {
			   mylotsi=lotsi;
			   for(cnt=1;cnt<=OpenOrders;cnt++)
			   {
				  mylotsi=NormalizeDouble(mylotsi*Multiplier,2);
				  Comment(mylotsi);
			   }
		    } else { mylotsi=lotsi; }
		    if (mylotsi>100) { mylotsi=100; }
		    if (mylotsi>1)
		       {
                tp     =NormalizeDouble(tp+(tp*0.15),2);
		          mylotsi=NormalizeDouble(mylotsi-(mylotsi*0.15),2);
		       }
		    OrderSend(Symbol(),OP_BUY,mylotsi,BuyPrice,Slippage,sl,tp,NULL,0,0,Blue);		    
		    return(0);
	     }
      } 
      
   } // if (!CloseAllTrades)//t_david 5/4/07
   
   if ( !CloseAllTrades && AllOrdersDD <= -MaxAllowedDD ) { Print("MaxAllowedDD Exceeded"); CloseAllTrades = true; GlobalVariableSet(opentrades,365); NowClose(); }//t_david 5/13/07
   if ( !CloseAllTrades && AccountEquity() <= MinimumEquityForTrade ) { Print("Account Equity Lower Than MinimumEquityForTrade"); CloseAllTrades = true; GlobalVariableSet(opentrades,365); NowClose(); }//t_david 5/13/07
   if ( GlobalVariableGet(opentrades) > 0 ) { CloseAllTrades = true; NowClose(); }//t_david 5/13/07
   if ( CloseAllTrades ) { GlobalVariableSet(opentrades,365); NowClose(); }//t_david 5/13/07

//----
   return(0);
  }
//+------------------------------------------------------------------+
 
void NowClose()//t_david 5/4/07 thanks go to Paul Hampton-Smith for the code
 {
   GlobalVariableSet(opentrades,365);//t_david 5/13/07
  while (OrdersTotal() > 0)
   {
     OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
    switch (OrderType())
     {
       case OP_BUY: OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Purple); break;
       case OP_SELL: OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Purple); break;
       //case OP_BUYSTOP:
       //case OP_SELLSTOP: 
       //case OP_BUYLIMIT:
       //case OP_SELLLIMIT: OrderDelete(OrderTicket());
     }
   }
 }



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar


Indicator Curves created:


Indicators Used:

Relative strength index
MACD Histogram

Stochastic oscillator


Custom Indicators Used:
Turbo_JRSX
Turbo_JVEL

Order Management characteristics:
Checks for the total of open orders
It Closes Orders by itself
It can change open orders parameters, due to possible stepping strategy
It automatically opens orders when conditions are reached

Other Features:


It issuies visual alerts to the screen

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 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 : EURUSD on H1

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

BackTest : USDCAD on H1

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

BackTest : EURUSD on H1

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

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.00 Total Net Profit:0.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

Request Backtest for 10Points_4_Ind_v2e


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

Pair: Period: