ssb5_123





//+-------------------------------------------------------------------------+
//|                                                                SSB5.mq4 |
//|                Copyright © 2009, Yury V. Reshetov  http://ssb.bigfx.ru/ |
//|                                                    http://ssb.bigfx.ru/ |
//+-------------------------------------------------------------------------+
#property copyright "Copyright © 2009, Yury V. Reshetov http://ssb.bigfx.ru"
#property link      "http://ssb.bigfx.ru"

/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see http://www.gnu.org/licenses/
*/

extern double lots = 1;
extern int fastmacd = 47;
extern int slowmacd = 95;
extern int signalmacd = 74;
extern int psmma = 45;
extern int stochD = 12;
extern int stochK = 25;
extern int stochS = 56;
extern int magic = 888;
extern int slippage = 0;
static int prevtime = 0;

int init() {
   prevtime = Time[0];
   return(0);
}

int start() {

   if (! IsTradeAllowed()) {
      return(0);
   }

   if (Time[0] == prevtime) {
      return(0);
   }
   prevtime = Time[0];

   int ticket = -1;
   int total = OrdersTotal();
   for (int i = total - 1; i >= 0; i--) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == magic)) {
         int prevticket = OrderTicket();
         if (OrderType() == OP_BUY) {
            if (shortsignal()) {
               ticket = OrderSend(Symbol(), OP_SELL, 2.0 * lots, Bid, slippage, 0, 0, WindowExpertName(), magic, 0, Red);
               Sleep(30000);
               if (ticket < 0) {
                  prevtime = Time[1];
                  return(0);
               } else {
                  OrderCloseBy(ticket, prevticket, Red);
               }
            }
          } else {
            if (longsignal()) {
               ticket = OrderSend(Symbol(), OP_BUY, 2.0 * lots, Ask, slippage, 0, 0, WindowExpertName(), magic, 0, Blue);
               Sleep(30000);
               if (ticket < 0) {
                  prevtime = Time[1];
                  return(0);
               } else {
                  OrderCloseBy(ticket, prevticket, Blue);
               }
            }
          }
          return(0);
      }
   }

   if (longsignal()) {
      ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, slippage, 0, 0, WindowExpertName(), magic, 0, Blue);
      Sleep(30000);
      if (ticket < 0) {
         prevtime = Time[1];
      }
      return(0);
   }
   if (shortsignal()) {
      ticket = OrderSend(Symbol(), OP_SELL, lots, Bid, slippage, 0, 0, WindowExpertName(), magic, 0, Red);
      Sleep(30000);
      if (ticket < 0) {
         prevtime = Time[1];
      }
      return(0);
   }
   return(0);
}

bool longsignal() {
   if (fcandle() < 0) {
      return(false);
   }
   if (fao() < 0) {
      return(false);
   }
   if (fao1() < 0) {
      return(false);
   }
   if (fmacd() < 0) {
      return(false);
   }
   if (fmacd1() < 0) {
      return(false);
   }
   if (fosma1() < 0) {
      return(false);
   }
   if (fsmma() < 0) {
      return(false);
   }
   if (fstoch1() < 0) {
      return(false);
   }
   if (fstoch2() < 0) {
      return(false);
   }
   return(true);
}

bool shortsignal() {
   if (fcandle() > 0) {
      return(false);
   }
   if (fao() > 0) {
      return(false);
   }
   if (fao1() > 0) {
      return(false);
   }
   if (fmacd() > 0) {
      return(false);
   }
   if (fmacd1() > 0) {
      return(false);
   }
   if (fosma1() > 0) {
      return(false);
   }
   if (fsmma() > 0) {
      return(false);
   }
   if (fstoch1() > 0) {
      return(false);
   }
   if (fstoch2() > 0) {
      return(false);
   }
   return(true);
}
int fcandle() {
   int result = 0;
   if (Open[0] < Open[1]) {
      result = 1;
   }
   if (Open[0] > Open[1]) {
      result = -1;
   }
   return(result);
}



int fao() {
   int result = 0;
   double ind = iAO(Symbol(), 0, 0);
   if (ind > 0) {
      result = 1;
   }
   if (ind < 0) {
      result = -1;
   }
   return(result);
}

int fao1() {
   int result = 0;
   double ind = iAO(Symbol(), 0, 0);
   double ind1 = iAO(Symbol(), 0, 1);
   if ((ind - ind1) < 0) {
      result = 1;
   }
   if ((ind - ind1) > 0) {
      result = -1;
   }
   return(result);
}
int fmacd() {
   int result = 0;
   double ind = iMACD(Symbol(), 0, fastmacd, slowmacd, signalmacd, PRICE_OPEN, MODE_MAIN, 0);
   if (ind > 0) {
      result = 1;
   }
   if (ind < 0) {
      result = -1;
   }
   return(result);
}

int fmacd1() {
   int result = 0;
   double ind = iMACD(Symbol(), 0, fastmacd, slowmacd, signalmacd, PRICE_OPEN, MODE_MAIN, 0);
   double ind1 = iMACD(Symbol(), 0, fastmacd, slowmacd, signalmacd, PRICE_OPEN, MODE_MAIN, 1);
   if ((ind - ind1) > 0) {
      result = 1;
   }
   if ((ind - ind1) < 0) {
      result = -1;
   }
   return(result);
}

int fosma1() {
   int result = 0;
   double ind = iOsMA(Symbol(), 0, fastmacd, slowmacd, signalmacd, PRICE_OPEN, 0);
   double ind1 = iOsMA(Symbol(), 0, fastmacd, slowmacd, signalmacd, PRICE_OPEN, 1);
   if ((ind - ind1) < 0) {
      result = 1;
   }
   if ((ind - ind1) > 0) {
      result = -1;
   }
   return(result);
}







int fsmma() {
   int result = 0;
   double ind = Open[0] - iMA(Symbol(), 0, psmma, 0, MODE_SMMA, PRICE_OPEN, 0);
   if (ind > 0) {
      result = 1;
   }
   if (ind < 0) {
      result = -1;
   }
   return(result);
}



int fstoch1() {
   int result = 0;
   double ind = iStochastic(Symbol(), 0, stochK, stochD, stochS, MODE_SMMA, 0,MODE_MAIN, 0) - 50.0;
   if (ind > 0) {
      result = 1;
   }
   if (ind < 0) {
      result = -1;
   }
   return(result);
}

int fstoch2() {
   int result = 0;
   double ind = iStochastic(Symbol(), 0, stochK, stochD, stochS, MODE_SMMA, 0,MODE_SIGNAL, 0) - 50.0;
   if (ind > 0) {
      result = 1;
   }
   if (ind < 0) {
      result = -1;
   }
   return(result);
}




Sample





Analysis



Market Information Used:

Series array that contains open time of each bar
Series array that contains open prices of each bar


Indicator Curves created:


Indicators Used:

Bill Williams Awesome oscillator
MACD Histogram
Moving Average of Oscillator
Moving average indicator
Stochastic oscillator


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders

It automatically opens orders when conditions are reached

Other Features:

BackTest : EURUSD on H1

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

BackTest : EURUSD on H1

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

BackTest : EURUSD on H1

From 2010-03-01 to 2010-03-27 Profit Factor:0.67 Total Net Profit:-548.00

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:1.63 Total Net Profit:3137.90

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-04-16 Profit Factor:0.91 Total Net Profit:-1195.00

BackTest : USDCAD on H1

From 2009-01-01 to 2010-01-01 Profit Factor:1.87 Total Net Profit:15105.39

BackTest : USDCAD on H1

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

BackTest : USDCHF on H1

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

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:2.02 Total Net Profit:1495.93

Request Backtest for ssb5_123


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

Pair: Period: