SonicStoIkEA





//+------------------------------------------------------------------+
//|                                                 SonicStoIkEA.mq4 |
//|                                              @2009 Desynced Tech |
//|                                     http://desynced.no-ip.org/fx |
//+------------------------------------------------------------------+
#property copyright "@2009 Desynced Tech"
#property link      "http://desynced.no-ip.org/fx"

int MAGIC = 41;



int iLastRegular;
double dLastAES;
double   ItrendLevel           = 0.0018;  //iTrend line must be above this level


extern int SMA_Filter_Period = 200;

extern int RSI_Filter_Period = 45;




double OzFX_AES;
  int OzFX_Regular;
  double Filter_SMA;
  double Filter_RSI;
  
  double iTredn1;
  double iTredn2;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

 int tik = getNumberTrades ();
 
 if ( tik > 0 ) {
 
  // trailingProfit(tik);
   return(0);
 }


decisionMaker();

  if (  OzFX_Regular == 1  &&  OzFX_AES == 0 && iTredn1 > 0.003 /*&& Filter_SMA == 1  /* && Filter_RSI == 1  */) {
  
    Print( OzFX_Regular , " " ,  OzFX_AES , " " ,Filter_SMA , " " ,Filter_RSI , " " , iTredn1 , " " , iTredn2);
    sendOrder(OP_BUY,0.1,65,0);
  }


if (  OzFX_Regular == -1 &&  OzFX_AES == -0.7 /*&& Filter_SMA == -1  /* && Filter_RSI == -1*/ ) {
  
  Print( OzFX_Regular , " " ,  OzFX_AES , " " ,Filter_SMA , " " ,Filter_RSI , " " , iTredn1 , " " , iTredn2);
      sendOrder(OP_SELL,0.1,65,0);
  }


   return(0);
  }
//+------------------------------------------------------------------+


int sendOrder(int type , double lots , int takeprofit , int stoploss ) {


   double tp;
   int ticket;
   if ( type == OP_SELL ) {
   
   if ( takeprofit > 0 ) tp = Bid-takeprofit*Point;
  
   else tp = 0;
   ticket =  OrderSend(Symbol(),OP_SELL, lots, Bid, 3, 0, tp,"", MAGIC, 0, Red); 
   
   
   return(ticket);
   }
   
   if ( type == OP_BUY ) {
   
        if ( takeprofit > 0 )  tp = Ask+takeprofit*Point;
        else tp = 0;

        ticket =  OrderSend(Symbol(),OP_BUY, lots, Ask, 3, 0, tp,"", MAGIC, 0, Red); 
         return (ticket);
   
   
   }
   
}



void trailingProfit(int tik) {

  
if ( tik != -1 ) {
   
   //if ( OrderProfit() > maxprofit ) maxprofit = OrderProfit();
   
   if ( OrderType() == OP_BUY && OrderProfit() > 0 ) {
         
       //  Print(" diff  " ,OrderProfit() , " = > " ,((OrderTakeProfit() - Ask)/Point));
         
         if ( ((OrderTakeProfit() - Ask)/Point) <= 6 ) OrderModify(tik,OrderOpenPrice(),OrderTakeProfit()/*Bid-65*Point*/,Ask+50*Point,0,Blue);
   
   }
   
   if ( OrderType() == OP_SELL && OrderProfit() > 0 ) {
   
  
   
   
            if ( (  (OrderTakeProfit()-Bid)/Point)*(-1) <= 6 ) OrderModify(tik,OrderOpenPrice(), Ask+65*Point,Bid-50*Point,0,Red);
   
   
           // Print(" diff sell " ,OrderProfit() , " = > " ,(  (OrderTakeProfit()-Bid)/Point)*(-1));
   }
   


}


}


int getNumberTrades()
{   
   int total = OrdersTotal();
   int numords = 0;
      
   for(int cnt=0; cnt<total; cnt++) 
   {        
   OrderSelect(cnt, SELECT_BY_POS);            
   if(OrderSymbol() == Symbol() &&  OrderMagicNumber() == MAGIC) 
      return (OrderTicket());
   }
   return(-1);
} 



void decisionMaker() {


   double sMain        = iStochastic(NULL,0,14,5,5,MODE_SMA,0,MODE_MAIN,0);
  double sSignal      = iStochastic(NULL,0,14,5,5,MODE_SMA,0,MODE_SIGNAL,0);
  
  double sMainprev        = iStochastic(NULL,0,14,5,5,MODE_SMA,0,MODE_MAIN,1);
  double sSignalprev      = iStochastic(NULL,0,14,5,5,MODE_SMA,0,MODE_SIGNAL,1);
  
  //--- i-Trend Index
 iTredn1      =iCustom(NULL, 0, "i_Trend", 0, 0, 0, 20, 2, 13, 300, 0,  0); //green
  iTredn2      =iCustom(NULL, 0, "i_Trend", 0, 0, 0, 20, 2, 13, 300, 1, 0); //red
  
  
  //--- RSI
  double sRSI         = iRSI(NULL,0,14,0,0); 
  double sRSIL1       = 51;
  double sRSIL2       = 49;
  
   //DeMaker and FI
  double  DEM  = iDeMarker(NULL, 0, 14, 0); 
  double  DEML = 0.5; 
  double  FI = iForce(NULL, 0, 14, 1, PRICE_CLOSE, 0);
  
  
  
  OzFX_Regular=0;
  
  /*---------------------*/            
/*  OZFX REGULAR CODE  */
/*---------------------*/
     
      if ((sMain>sSignal)&& (sMain>sMainprev)&&(iTredn1>ItrendLevel && iTredn1>iTredn2)&& (sRSI>=sRSIL1)&&(DEM>DEML)&&(FI>0)) // BUY
      {
         if (iLastRegular != 1) OzFX_Regular = 1;
         iLastRegular = 1;
      }   
      
     if ((sMain<sSignal)&&(sMain<sMainprev)&&(iTredn2>ItrendLevel && iTredn2>iTredn1)&& (sRSI<=sRSIL2)&&(DEM<DEML)&&(FI<0)) // SELL
       
      {   
         if (iLastRegular != -1) OzFX_Regular = -1;
         iLastRegular = -1;
      }   
      //if (Show_Sonic_Signals == false) OzFX_Regular[k] = 0.0;
      
/*-----------------*/            
/*  OZFX AES CODE  */
/*-----------------*/
       OzFX_AES = 0;
      if (/*iAC(Symbol(), 0, k) > 0 &&*/
          iAC(Symbol(), 0, 0) > iAC(Symbol(), 0, 1) &&
          iStochastic(Symbol(), 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0)
          > iStochastic(Symbol(), 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0) /*&&
          iStochastic(Symbol(), 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, k + 1)
          < iStochastic(Symbol(), 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, k + 1) &&
          iAO(Symbol(), 0, k) > iAO(Symbol(), 0, k + 1)*/)
      {
         if (dLastAES != 0.7) OzFX_AES = 0.7;
         dLastAES = 0.7;
      }   
      
      if (/*iAC(Symbol(), 0, k) < 0 &&*/
          iAC(Symbol(), 0, 0) < iAC(Symbol(), 0, 1) &&
          iStochastic(Symbol(), 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0)
          < iStochastic(Symbol(), 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, 0) /*&&
          iStochastic(Symbol(), 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, k + 1)
          > iStochastic(Symbol(), 0, 5, 3, 3, MODE_SMA, 0, MODE_SIGNAL, k + 1) &&
          iAO(Symbol(), 0, k) < iAO(Symbol(), 0, k + 1)*/)
      {
         if (dLastAES != -0.7) OzFX_AES = -0.7;
         dLastAES = -0.7;
      }   
      //if (Show_AES_Signals == false) OzFX_AES[k] = 0.0;             
/*-------------------*/            
/*  SMA FILTER CODE  */
/*-------------------*/            
      Filter_SMA = 0;
      if (Close[0] > iMA(Symbol(), 0, SMA_Filter_Period, 0, MODE_SMA, PRICE_CLOSE, 0))
         Filter_SMA = 1;
      if (Close[0] <= iMA(Symbol(), 0, SMA_Filter_Period, 0, MODE_SMA, PRICE_CLOSE, 0))
         Filter_SMA = -1;
      //if (Show_SMA_Filter == false) Filter_SMA[0] = EMPTY_VALUE;

/*-------------------*/            
/*  RSI FILTER CODE  */
/*-------------------*/            
       Filter_RSI = 0;
      if (50 > iRSI(Symbol(), 0, RSI_Filter_Period, PRICE_CLOSE, 0))
         Filter_RSI = -1;
      if (50 <= iRSI(Symbol(), 0, RSI_Filter_Period, PRICE_CLOSE, 0))
         Filter_RSI = 1;
     // if (Show_RSI_Filter == false) Filter_RSI[k] = EMPTY_VALUE;
  
  
       

}



Sample





Analysis



Market Information Used:

Series array that contains close prices for each bar


Indicator Curves created:


Indicators Used:

Stochastic oscillator

Relative strength index
DeMarker indicator
Force index
Bill Williams Accelerator/Decelerator oscillator
Bill Williams Awesome oscillator
Moving average indicator


Custom Indicators Used:
i_Trend

Order Management characteristics:
It automatically opens orders when conditions are reached

It can change open orders parameters, due to possible stepping strategy
Checks for the total of open orders

Other Features:

BackTest : EURUSD on H1

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

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:77.95

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.03 Total Net Profit:-911.80

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 SonicStoIkEA


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

Pair: Period: