Sweet_Spot_Extreme





/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+-----------------------------------------------------------------------------------------------------------+
//|                                                                                    Sweet_Spot_Extreme.mq4 |
//|Copyright © 2006, Safari Traders, http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/ |
//+-----------------------------------------------------------------------------------------------------------+
#property copyright "Copyright © 2006, Safari Traders , chopped and optimized by transport_david "
#property link      "http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/"

extern int    MAGIC_NUMBER       =  613;
extern int    MaxTradesPerSymbol =    3;
extern int    Slippage           =    2;
extern double Lots               =    1.00;
extern double MaximumRisk        =    0.05;
extern double DecreaseFactor     =    6;
extern double Stop               =   10;
extern double MAPeriod           =   85;
extern double CloseMa            =   70;
extern double MinLot             =    0.1;

extern double buyccilevel        = -200.00;
extern double sellccilevel       =  200.00;
extern int price                 =    0;
int init(){
   return(0);
}

int start(){
 
 double Alpha = iCCI(NULL, 30, 12, price, 0);  // links to 30 minutes chart
 
 double MA = iMA(NULL,15,MAPeriod,0,MODE_EMA,PRICE_MEDIAN,1); // Links to 15 minutes chart for shorttearm accuracy
 double MAprevious = iMA(NULL,15,MAPeriod,0,MODE_EMA,PRICE_MEDIAN,2); // Links to 15 minutes chart for shorttearm accuracy

 double MAClose0 = iMA(NULL,15,CloseMa,0,MODE_EMA,PRICE_MEDIAN,0); // Links to 15 minutes chart for shorttearm accuracy
 double MAClose1 = iMA(NULL,15,CloseMa,0,MODE_EMA,PRICE_MEDIAN,1); // Links to 15 minutes chart for shorttearm accuracy

  int trades = 0;
  for(int cnt1 = 0; cnt1 < OrdersTotal(); cnt1++){
   if(!OrderSelect(cnt1, SELECT_BY_POS, MODE_TRADES)) continue;
   if(OrderMagicNumber() != MAGIC_NUMBER) continue;

   if(StringFind(OrderSymbol(), Symbol(), 0) != -1) {
   //debugging
    Print("symbol "+Symbol());
    trades++;
    if(cnt1 == OrdersTotal()-1) Print("Trades: "+trades);
   }
  }
  
  // no opened orders identified
   if(AccountFreeMargin()<(100*Lots)){
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);  
   }
  
  if(trades < MaxTradesPerSymbol){  
  
   // no opened orders identified
   if(AccountFreeMargin()<(100*Lots)){
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);  
   }
  
   int ticket = -10;
   
   // Bull trending
   if((MA>MAprevious) && (MAClose0 > MAClose1)&&(Alpha < buyccilevel))
    ticket=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask, Slippage,0,0,"Sweet_Spot_Extreme", MAGIC_NUMBER,0,Aqua);
  
  // Bear trending
   if((MA<MAprevious) && (MAClose0 < MAClose1) && (Alpha > sellccilevel) )
    ticket=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid, Slippage, 0,0,"Sweet_Spot_Extreme", MAGIC_NUMBER,0,Coral);         
    
  }
     
     
     
 // EXIT POSITIONS
 for(int cnt=0; cnt<OrdersTotal(); cnt++){
  if(!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
  if(OrderMagicNumber() != MAGIC_NUMBER) continue;
  if(StringFind(OrderSymbol(), Symbol(), 0) == -1) continue;
     
  if(OrderType() <= OP_SELL)
  {   // opened position_Sell??
    
   if(OrderType() == OP_BUY)
    { // position is opened_buy??   
      // early take profit giving this strategy a scalping capability?
     if((MA <= MAprevious)&&(OrderMagicNumber() == MAGIC_NUMBER))
      {
       OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(), 0,Aqua); // close position
       //return(0);
      }   
     // check for stop
     if((Stop > 0)&&(OrderMagicNumber() == MAGIC_NUMBER))
      {
       if((OrderClosePrice()-OrderOpenPrice())>Stop*Point)
        {
         OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(), 0,Aqua); // close position
         //return(0);
        }
      }
    }
   else
    { // OrderType() == OP_SELL
     if(OrderType() == OP_SELL)
      {
       // should it be closed?
       if((MA >= MAprevious)&&(OrderMagicNumber() == MAGIC_NUMBER))
        {
         OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(), 0, Coral); // close position
         //return(0); // exit
        }
       // check for stop
      if((Stop > 0)&&(OrderMagicNumber() == MAGIC_NUMBER))
       {
        if((OrderOpenPrice()-OrderClosePrice())>Stop*Point)
         {
          OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(), 0, Coral); // close position
          //return(0);
         }
       }
    } 
  }
  } //close -->  if(OrderType() <= OP_SELL){ 
 } //close -->  if(OrderType() == OP_BUY){
 //Comment("");   
 return(0);
}


//////////////////////////////////////////////////////////////////////
// Calculate optimal lot size                                       
//////////////////////////////////////////////////////////////////////
double LotsOptimized()
  {
   double lot=Lots;
   int    orders=HistoryTotal();     // history orders total
   int    losses=0;                  // number of losses orders without a break
   
//---- select lot size
   lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/500, 1);
//---- calcuulate number of losses orders without a break
   if(DecreaseFactor>0)
     {
      for(int i=orders-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
         if(StringFind(OrderSymbol(), Symbol(), 0) == -1 || OrderType()>OP_SELL) continue;
         if(OrderMagicNumber() != MAGIC_NUMBER) continue;
         if(OrderProfit()>0) break;
         if(OrderProfit()<0) losses++;
        }
      if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
     }
//---- return lot size
   if(lot>50) lot=50;
   if(lot < MinLot) lot = MinLot;
   return(lot);
}



Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:

Commodity channel index
Moving average indicator


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders

It automatically opens orders when conditions are reached
It Closes Orders by itself

Other Features:

BackTest : EURUSD on H1

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

BackTest : EURUSD on H1

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

BackTest : EURUSD on H1

From 2010-03-01 to 2010-03-27 Profit Factor:1.81 Total Net Profit:249.10

BackTest : EURUSD on H1

From 2010-04-01 to 2010-04-30 Profit Factor:6.09 Total Net Profit:957.38

BackTest : EURUSD on H1

From 2010-05-01 to 2010-05-31 Profit Factor:17.55 Total Net Profit:1420.20

BackTest : EURUSD on H1

From 2010-06-01 to 2010-06-30 Profit Factor:9.45 Total Net Profit:1427.80

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.69 Total Net Profit:-398.20

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-04-16 Profit Factor:0.11 Total Net Profit:-6234.26

BackTest : USDCAD on H1

From 2009-01-01 to 2010-01-01 Profit Factor:0.18 Total Net Profit:-685.89

BackTest : USDCAD on H1

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

BackTest : USDCHF on H1

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

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.06 Total Net Profit:-218.47

Request Backtest for Sweet_Spot_Extreme


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

Pair: Period: