Nouf_Stochastic_20&80(2)





//+------------------------------------------------------------------+
//|                                              nouf stochastic.mq4 |
//|                                     Copyright © 2007 , dr_waleed |
//|                                                dr_waleed@msn.com |
//+------------------------------------------------------------------+
 
#property copyright   "Copyright © 2007, dr_waleed"
#property link        "dr_waleed@msn.com" 

//---- Trades Limits

extern int         TakeProfit            = 150;
extern int         StopLoss              = 100;      
extern int         TrailingStop          = 100;  
extern bool        SmartClose            = true; 
extern int         current               = 0;
 
//---- Stochastic

extern int         Kperiod1              = 5;
extern int         Kperiod2              = 125;
extern int         Kperiod3              = 14;
extern int         Dperiod               = 3;
extern int         slowing               = 3; 

extern int         Sto5Buy               = 20;
extern int         Sto5Sell              = 80;

extern int         Sto125Buy             = 50;
extern int         Sto125Sell            = 50;

extern int         CloseBuy              = 80;
extern int         CloseSell             = 20;

 
//---- Money Monagement

extern bool        MoneyManagment        = false;
extern int         Risk                  = 5;
extern double      Lots                  = 1;
extern int         MaxTrades             = 1;

//---- Hour Trades

extern bool        UseHourTrade          = false;
extern int         FromHourTrade         = 0;
extern int         ToHourTrade           = 0;

//---- Global variables

extern int         Magic                 = 0;
string             eaComment             = "nouf stochastic";

//+------------------------------------------------------------------+
//|    Initialation function                                         |
//+------------------------------------------------------------------+

int init()
   {
    return(0);
   }

int orderscnt()
   {
    int cnt=0;
    for(int i =0;i<OrdersTotal();i++)
       {
        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
          {
           if(OrderSymbol()== Symbol() && Magic==OrderMagicNumber())
             {
              cnt++;
             }
          }
       }
     return(cnt);
   }

//+------------------------------------------------------------------+
//|    Start function                                                |
//+------------------------------------------------------------------+

int start()
   {    
       
      if (UseHourTrade)
       {
       if(!(Hour()>=FromHourTrade&&Hour()<=ToHourTrade))
         {
          Comment("Non-Trading Hours!");
               return(0);   // Use Hour Trade
         }
       }
     
    if(Bars<100)
      {
       Print("bars less than 100");
          return(0);   // check Bars
      }
      
    if(TakeProfit < 10)
      {
        Print("TakeProfit less than 10");
        return(0);   // check Take Profit
      }
      
         
    double Stop, Limit;
    int cnt, total;
    
    if(MoneyManagment) Lots = subLotSize();
 

      double   stoM1, stoM2, stoM3, stoM4, stoM5;
      
             stoM1 = iStochastic( NULL, 0, Kperiod1, Dperiod, slowing, 0, 0, MODE_MAIN, current);
             stoM2 = iStochastic( NULL, 0, Kperiod1, Dperiod, slowing, 0, 0, MODE_MAIN, current+1); 
             stoM3 = iStochastic( NULL, 0, Kperiod2, Dperiod, slowing, 0, 0, MODE_MAIN, current);  
             stoM4 = iStochastic( NULL, 0, Kperiod3, Dperiod, slowing, 0, 0, MODE_MAIN, current);       
             stoM5 = iStochastic( NULL, 0, Kperiod3, Dperiod, slowing, 0, 0, MODE_MAIN, current+1);
                                                   
                       
    total=OrdersTotal();
    
    if(total<1) 
      {    
       if(AccountFreeMargin()<(1000*Lots))
         {
          Print("We have no money. Free Margin = ",AccountFreeMargin());
             return(0);  
         }    
            
//+------------------------------------------------------------------+
//|    Buy & Sell                                                    |
//+------------------------------------------------------------------+
            
       if    ( stoM1>Sto5Buy && stoM2<Sto5Buy && stoM3>Sto125Buy)   //------------------ Buy
         {
          if(orderscnt()<MaxTrades)
            {
             if(StopLoss==0)
               {Stop=0;TrailingStop=0;}
             else
               {Stop=Ask-StopLoss*Point;}
             if(TakeProfit==0)
               {Limit=0;}
             else
               {Limit=Ask+TakeProfit*Point;}
                OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Stop,Limit,eaComment,Magic,0,Green);
                PlaySound("Alert.wav");
               } 
             }
                          
       if    ( stoM1<Sto5Sell && stoM2>Sto5Sell && stoM3<Sto125Sell)   //------------------ Sell
         {
          if(orderscnt()<MaxTrades)
            {
             if(StopLoss==0)
               {Stop=0;TrailingStop=0;}
             else
               {Stop=Bid+StopLoss*Point;}
             if(TakeProfit==0)
               {Limit=0;}
             else
               {Limit=Bid-TakeProfit*Point;}
                OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Stop,Limit,eaComment,Magic,0,Red); 
                PlaySound("Alert.wav");
               }  
            }
        return(0);
      }
            
//+------------------------------------------------------------------+
//|    Trailing Stop                                                 |
//+------------------------------------------------------------------+ 

for(cnt=0;cnt<total;cnt++)
  {               
   OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
     {
      if(OrderType()==OP_BUY)
        {
         if(TrailingStop>0)  
           {                 
            if(Bid-OrderOpenPrice()>Point*TrailingStop)
              {
               if(OrderStopLoss()<Bid-Point*TrailingStop && OrderStopLoss()<OrderOpenPrice())
                 {
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()+Point*TrailingStop,OrderTakeProfit(),0,Green);
                           return(0);
                 }
              }
           }
        }
      if(OrderType()==OP_SELL)
        {
         if(TrailingStop>0)  
           {                 
            if(OrderOpenPrice()-Ask>Point*TrailingStop)
              {
               if(OrderStopLoss()>Ask+Point*TrailingStop && OrderStopLoss()>OrderOpenPrice())
                 {
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()-Point*TrailingStop,OrderTakeProfit(),0,Red);
                        return(0);
                 }
              }
           }
        }
     }
  }
  
//+------------------------------------------------------------------+
//|    Smart Close                                                   |
//+------------------------------------------------------------------+ 

if (SmartClose)
  {      
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) 
        {
         if(OrderType()==OP_BUY)
           {
            if    ( stoM4<CloseBuy && stoM5>CloseBuy )   //-------------------------------Cloes Buy
              {
               OrderClose(OrderTicket(),OrderLots(),Bid,3,Yellow);
                       return(0);
              }
           }
         else
           {
            if    ( stoM4>CloseSell && stoM5<CloseSell )   //-------------------------------Close Sell
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Yellow);
                       return(0);
              }
           }
        }
     }
  }
    return(0);
   }
   
//+------------------------------------------------------------------+
//|    Money Management                                              |
//+------------------------------------------------------------------+
  
double subLotSize()
    {
     double lotMM = MathCeil(AccountFreeMargin() *  Risk / 1000) / 100; 
	    {
	     if(lotMM < 0.01)                 lotMM = Lots;
	     if(lotMM > 1.0)                  lotMM = MathCeil(lotMM);
	     if(lotMM > 100)                  lotMM = 100;
	      return (lotMM);
       }
    }
    
//------------------------------------------------------------------------- The End.



Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:

Stochastic oscillator


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:

It plays sound alerts

BackTest : EURUSD on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.48 Total Net Profit:-1600.10

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.60 Total Net Profit:-448.13

BackTest : EURUSD on H1

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

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.54 Total Net Profit:-3554.00

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.81 Total Net Profit:-1036.30

BackTest : EURUSD on H1

From 2010-03-01 to 2010-03-27 Profit Factor:0.43 Total Net Profit:-1602.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 Nouf_Stochastic_20&80(2)


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

Pair: Period: