ts-gbp-jpy_1t





/*
 * GBP/JPY strategy http://www.forexinvestimentos.com/forum/smf/index.php/topic,1029.0.html
 
 */

#property copyright "Felipe Schmitt"

// Universal settings

// Money management
extern double FixedLots = 0.3;   // if > 0.0 fixed lots used
extern double Risk = 0.01;       // per cent of free margin of a single offer

extern int StopLoss = 50;
extern int TakeProfit1 = 100;
//extern int TakeProfit2 = 70;
//extern int TakeProfit3 = 60;

extern int DayStartHour = 4;
extern int StopShift = 0;
extern int OrderExpirationHours = 20;



bool extremsSet = false;
double dayHigh = 0.0;
double dayLow = 0.0;

void CloseOpenPositions()
{
   //for(int i = 0; i < OrdersTotal(); i++)
   for(int i = OrdersTotal(); i>=0; i--)
   {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         if(OrderType() == OP_BUY || OrderType() == OP_SELL)
         {
            double price = Ask;
            if(OrderType() == OP_BUY)
               price = Bid;
            
            OrderClose(OrderTicket(), OrderLots(), price, 3);
         }
      }
   }
}

void SetPositions()
{
   // calculate lot size
   double lots;
   if(FixedLots > 0.0)
      lots = FixedLots;
   else
      lots = NormalizeDouble(AccountFreeMargin() * Risk / (StopLoss * MarketInfo(Symbol(), MODE_TICKVALUE)), 1);

   CloseOpenPositions();

   double price = Ask;
   int operation = OP_BUYSTOP;
  // if(Ask < dayHigh)
   {
      operation = OP_BUYSTOP;
      price = dayHigh + StopShift * Point;
   }
   
   OrderSend(Symbol(), OP_BUYSTOP, lots, price, 3, price - StopLoss * Point, price + TakeProfit1 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Blue);
   //OrderSend(Symbol(), OP_BUYSTOP, lots, price, 3, price - StopLoss * Point, price + TakeProfit2 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Blue);
  // OrderSend(Symbol(), OP_BUYSTOP, lots, price, 3, price - StopLoss * Point, price + TakeProfit3 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Blue);

   price = Bid;
   operation = OP_SELLSTOP;
  // if(Bid > dayLow)
   {
      operation = OP_SELLSTOP;
      price = dayLow - StopShift * Point;
   }
   
   OrderSend(Symbol(), OP_SELLSTOP, lots, price, 3, price + StopLoss * Point, price - TakeProfit1 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Red);
   //OrderSend(Symbol(), OP_SELLSTOP, lots, price, 3, price + StopLoss * Point, price - TakeProfit2 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Red);
  // OrderSend(Symbol(), OP_SELLSTOP, lots, price, 3, price + StopLoss * Point, price - TakeProfit3 * Point, NULL, 0, TimeCurrent() + D'1970.01.01 1' * OrderExpirationHours, Red);
}

void start()
{
   if(TimeHour(TimeCurrent()) == DayStartHour && !extremsSet)
   {
      dayHigh = High[iHighest(NULL, PERIOD_H1, MODE_HIGH, 8, 0)] ;
      dayLow = Low[iLowest(NULL, PERIOD_H1, MODE_LOW, 8, 0)];
      extremsSet = true;
      
      SetPositions();
   }
   else if(TimeHour(TimeCurrent()) != DayStartHour && extremsSet)
      extremsSet = false;
}





Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders

It Closes Orders by itself

Other Features:

BackTest : EURUSD on H1

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

BackTest : EURUSD on H1

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

BackTest : EURUSD on H1

From 2010-03-01 to 2010-03-27 Profit Factor:1.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

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:1.33 Total Net Profit:180.00

BackTest : USDCAD on H1

From 2009-01-01 to 2010-01-01 Profit Factor:1.02 Total Net Profit:58.76

BackTest : USDCAD on H1

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

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:1.21 Total Net Profit:51.97

Request Backtest for ts-gbp-jpy_1t


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

Pair: Period: