TrendStuffer-expert-ULTIMATE-ShortTermM15Assistant





#property  copyright "Copyright c 2007, TrendStuffer.com"
#property  link "http://www.trendstuffer.com/"

#include   <stdlib.mqh>

extern   string   introone = "**TrendStuffer.com ShortTerm M15 Assistant(!) EA**";
extern   string   introtwo = "**Built for GBP/USD M15 chart to ASSIST manual trading**";
extern   string   texta = "-=[Expert's Settings Area]=-";
extern   int      TrendStufferMagic = 20070601;
extern   string   EAComment = "TrendStuffer Assistant GBPUSD M15";
extern   int      MaxSlippage = 2;
extern   int      OrderTriesNumber = 5;
extern   int      StartHour = 0;
extern   int      EndHour = 24;
extern   int      ExpirationHour = 24;
extern   int      FilterTF1 = 30;
extern   int      FilterTF2 = 60;
extern   string   textb = "-=[How much to trade with?]=-";
extern   bool     FixedLot = true;
extern   double   Lots = 0.1;
extern   double   MaximumRisk = 5;
extern   string   textc = "-=[Position's settings?]=-";
extern   double   TakeProfit = 200;
extern   double   StopLoss = 90;
extern   int      BEPips = 11;
extern   int      CurrentBarTrailingStart = 40;
extern   int      CurrentBarTrailingStop = 20;
extern   int      ClosedBarTrailingStart = 30;
extern   int      ClosedBarTrailingStop = 40;
extern   string   textd = "-=[Use the 3-Positions method?]=-";
extern   bool     UseThreeP = false;
extern   int      ThreePMagic = 320070611;
extern   double   Lot1 = 0.5;
extern   double   Lot2 = 0.3;
extern   double   Lot3 = 0.2;
extern   int      TakeProfit1 = 20;
extern   int      TakeProfit2 = 50;
extern   int      TakeProfit3 = 80;
extern   int      InitialSL1 = 50;
extern   int      InitialSL2 = 70;
extern   int      InitialSL3 = 100;
int      var_276 = 1;
int      var_280 = 1;
int      var_284 = 14;
double   var_288 = 2.824;
bool     var_296;
bool     var_300;
bool     var_304;
bool     var_308;
int      var_312;
int      Attempt;
int      var_320;
double   var_324;
double   var_332;
double   var_340;
double   var_348;
double   var_356;
double   var_364;
double   var_372;
int      var_380;
int      var_384;
double   var_388;

//+------------------------------------------------------------------+

double LotsRisk(int risk)
{
double lots = Lots;

if (!FixedLot)
   lots = NormalizeDouble(AccountFreeMargin() * MaximumRisk / 1000.0 / risk,1);
      else
   lots = Lots;

if (lots < 0.01) lots = 0.01;
return(lots);
}

//+------------------------------------------------------------------+

int CalculateCurrentOrders()
{
if (UseThreeP == false)
   {
   int buy_cnt = 0;
   int sell_cnt = 0;
   for (int i = 0; i < OrdersTotal(); i++)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) break;
      if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == TrendStufferMagic))
         {
         if (OrderType() == OP_BUY) buy_cnt++;
         if (OrderType() == OP_SELL) sell_cnt++;
         }
      }
   if (buy_cnt > 0) return(buy_cnt); else return(-sell_cnt);
   }

if (UseThreeP == true)
   {
   buy_cnt = 0;
   sell_cnt = 0;
   for (i = 0; i < OrdersTotal(); i++)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) break;
      if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == ThreePMagic))
         {
         if (OrderType() == OP_BUY) buy_cnt++;
         if (OrderType() == OP_SELL) sell_cnt++;
         }
      }
   if (buy_cnt > 0) return(buy_cnt); else return(-sell_cnt);
   }
}

//+------------------------------------------------------------------+

void CheckForSignals()
{
double cbts;
double ordprice;
int    ordtype;
int    i;
int    result;

if (var_320 != Time[0])
   {
   var_320 = Time[0];
   var_324 = iCustom(NULL,0,"TrendStuffer-base",0,40,var_284,var_288,0,var_276);
   var_332 = iCustom(NULL,0,"TrendStuffer-base",0,40,var_284,var_288,0,var_276 + 1);
   var_324 = NormalizeDouble(var_324,Digits);
   var_332 = NormalizeDouble(var_332,Digits);
   var_340 = iCustom(NULL,0,"TrendStuffer-base",1,ClosedBarTrailingStop,var_284,var_288,0,var_280);
   var_348 = iCustom(NULL,0,"TrendStuffer-base",1,ClosedBarTrailingStop,var_284,var_288,0,var_280 + 1);
   var_340 = NormalizeDouble(var_340,Digits);
   var_348 = NormalizeDouble(var_348,Digits);
   var_356 = iCustom(NULL,0,"TrendStuffer-base2",0,40,var_284,var_288,0,var_276);
   var_364 = iCustom(NULL,0,"TrendStuffer-base2",0,40,var_284,var_288,0,var_276 + 1);
   var_356 = NormalizeDouble(var_356,Digits);
   var_364 = NormalizeDouble(var_364,Digits);
   var_388 = iCustom(NULL,0,"TrendStuffer-ManualSystem-ULTIMATE-TrialWeek-MTF",FilterTF1,0,var_276);
   var_372 = iCustom(NULL,0,"TrendStuffer-ManualSystem-ULTIMATE-TrialWeek-MTF",FilterTF2,0,var_276);
   }

var_300 = false;
var_296 = false;
if (((Close[1] > var_324) && (Close[2] < var_332) && (var_388 == 1) && (var_372 == 1)) || ((Close[1] > var_324) && (Close[2] < var_364) && (Close[1] > var_356) && (var_388 == 1) && (var_372 == 1))) var_296 = true;
if (((Close[1] < var_324) && (Close[2] > var_332) && (var_388 != 1) && (var_372 != 1)) || ((Close[1] < var_324) && (Close[2] > var_364) && (Close[1] < var_356) && (var_388 != 1) && (var_372 != 1))) var_300 = true;

if (CalculateCurrentOrders() == 0) return;

for (i = 0; i < OrdersTotal(); i++)
   {
   if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) break;
   if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == TrendStufferMagic))
      {
      ordprice = OrderOpenPrice();
      ordtype = OrderType();
      }
   }

var_308 = false;
var_304 = false;
cbts = NormalizeDouble(ordprice + ClosedBarTrailingStart * Point,Digits);
if ((ordtype == OP_BUY) && (Close[var_280] >= cbts) && (Close[var_280] < var_340) && (Close[var_280 + 1] >= var_348)) var_304 = true;
cbts = NormalizeDouble(ordprice - ClosedBarTrailingStart * Point,Digits);
if ((ordtype == OP_SELL) && (Close[var_280] <= cbts) && (Close[var_280] > var_340) && (Close[var_280 + 1] <= var_348)) var_308 = true;

if ((ordtype == OP_BUY) && (Close[var_276 + 1] > var_364) && (Close[var_276] <= var_356)) var_304 = true;
if ((ordtype == OP_SELL) && (Close[var_276 + 1] < var_364) && (Close[var_276] >= var_356)) var_308 = true;

if ((ordtype == OP_BUY) && (Bid > OrderOpenPrice() + BEPips * Point))
   {
   result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + Point * 1.0,OrderTakeProfit(),0,Gold);
   }
if ((ordtype == OP_SELL) && (Ask < OrderOpenPrice() - BEPips * Point))
   {
   result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - Point * 1.0,OrderTakeProfit(),0,Gold);
   }
}

//+------------------------------------------------------------------+

void CheckForOpen()
{
int    ticket;
int    hour;
int    ticket1;
int    ticket2;
int    ticket3;
string comment;

if (UseThreeP == false)
   {
   hour = TimeHour(TimeCurrent());
   if ((StartHour < hour) && (EndHour > hour))
      {
      if (var_300)
         {
         ticket = 0;
         Attempt = 0;
         while ((ticket <= 0) && (Attempt < OrderTriesNumber))
            {
            while (!IsTradeAllowed()) Sleep(5000);
            RefreshRates();
            ticket = OrderSend(Symbol(),OP_SELL,LotsRisk(StopLoss),Bid,MaxSlippage,Bid + StopLoss * Point,(Bid - TakeProfit * Point),EAComment,TrendStufferMagic,0,Red);
            if (ticket < 0) Print("Error opening SELL order : ",ErrorDescription(GetLastError()));
            Attempt++;
            }
         var_312 = -1;
         return;
         }
      if (var_296)
         {
         ticket = 0;
         Attempt = 0;
         while ((ticket <= 0) && (Attempt < OrderTriesNumber))
            {
            while (!IsTradeAllowed()) Sleep(5000);
            RefreshRates();
            ticket = OrderSend(Symbol(),OP_BUY,LotsRisk(StopLoss),Ask,MaxSlippage,Ask - StopLoss * Point,Ask + TakeProfit * Point,EAComment,TrendStufferMagic,0,Blue);
            Attempt++;
            }
         var_312 = 1;
         return;
         }
      }
   }

if (UseThreeP == true)
   {
   comment = "TrendStuffer ThreeP " + Period() + " " + Symbol();
   if ((StartHour < hour) && (EndHour > hour))
      {
      if (var_300)
         {
         ticket1 = OrderSend(Symbol(),OP_SELL,Lot1,Bid,MaxSlippage,Bid + InitialSL1 * Point,Bid - TakeProfit1 * Point,comment,ThreePMagic,0,Red);
         ticket2 = OrderSend(Symbol(),OP_SELL,Lot2,Bid,MaxSlippage,Bid + InitialSL2 * Point,Bid - TakeProfit2 * Point,comment,ThreePMagic,0,Red);
         ticket3 = OrderSend(Symbol(),OP_SELL,Lot3,Bid,MaxSlippage,Bid + InitialSL3 * Point,Bid - TakeProfit3 * Point,comment,ThreePMagic,0,Red);
         var_312 = -1;
         }
            else
         {
         if (var_296)
            {
            ticket1 = OrderSend(Symbol(),OP_BUY,Lot1,Ask,MaxSlippage,Ask - InitialSL1 * Point,Ask + TakeProfit1 * Point,comment,ThreePMagic,0,Blue);
            ticket2 = OrderSend(Symbol(),OP_BUY,Lot2,Ask,MaxSlippage,Ask - InitialSL2 * Point,Ask + TakeProfit2 * Point,comment,ThreePMagic,0,Blue);
            ticket3 = OrderSend(Symbol(),OP_BUY,Lot3,Ask,MaxSlippage,Ask - InitialSL3 * Point,Ask + TakeProfit3 * Point,comment,ThreePMagic,0,Blue);
            var_312 = 1;
            }
         }
      }
   }
}

//+------------------------------------------------------------------+

void CheckForClose()
{
bool result;
int  i;

if (UseThreeP == false)
   {
   for (i = 0; i < OrdersTotal(); i++)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) break;
      if ((OrderMagicNumber() != TrendStufferMagic) || (OrderSymbol() != Symbol())) continue;
      if (OrderType() == OP_BUY)
         {
         if (var_304)
            {
            result = false;
            Attempt = 0;
            while (!result && (Attempt < OrderTriesNumber))
               {
               while (!IsTradeAllowed()) Sleep(5000);
               RefreshRates();
               result = OrderClose(OrderTicket(),OrderLots(),Bid,MaxSlippage,Gold);
               Sleep(3000);
               if (!result) Print("Error closing order : ",ErrorDescription(GetLastError()));
               Attempt++;
               }
            }
         break;
         }
      if (OrderType() == OP_SELL)
         {
         if (var_308)
            {
            result = false;
            Attempt = 0;
            while (!result && (Attempt < OrderTriesNumber))
               {
               while (!IsTradeAllowed()) Sleep(5000);
               RefreshRates();
               result = OrderClose(OrderTicket(),OrderLots(),Ask,MaxSlippage,Gold);
               Sleep(3000);
               if (!result) Print("Error closing order : ",ErrorDescription(GetLastError()));
               Attempt++;
               }
            }
         break;
         }
      }
   }

if (UseThreeP == true)
   {
   for (i = 0; i < OrdersTotal(); i++)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) break;
      if ((OrderMagicNumber() != ThreePMagic) || (OrderSymbol() != Symbol())) continue;
      if (OrderType() == OP_BUY)
         {
         if ((Bid > OrderOpenPrice() + TakeProfit1 * Point) && (Bid < OrderOpenPrice() + TakeProfit2 * Point) && (OrderStopLoss() != OrderOpenPrice() + Point * 1.0))
            {
            result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + Point * 1.0,OrderTakeProfit(),0,Gold);
            }
         if ((Bid > OrderOpenPrice() + TakeProfit2 * Point) && (Bid < OrderOpenPrice() + TakeProfit3 * Point) && (OrderStopLoss() != OrderOpenPrice() + TakeProfit1 * Point))
            {
            result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() + TakeProfit1 * Point,OrderTakeProfit(),0,Gold);
            }
         if (var_304)
            {
            result = OrderClose(OrderTicket(),OrderLots(),Bid,0,Gold);
            }
         }
      if (OrderType() == OP_SELL)
         {
         if ((Ask < OrderOpenPrice() - TakeProfit1 * Point) && (Ask > OrderOpenPrice() - TakeProfit2 * Point) && (OrderStopLoss() != OrderOpenPrice() - Point * 1.0))
            {
            result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - Point * 1.0,OrderTakeProfit(),0,Gold);
            }
         if ((Ask < OrderOpenPrice() - TakeProfit2 * Point) && (Ask > OrderOpenPrice() - TakeProfit3 * Point) && (OrderStopLoss() != OrderOpenPrice() - TakeProfit1 * Point))
            {
            result = OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - TakeProfit1 * Point,OrderTakeProfit(),0,Gold);
            }
         if (var_308)
            {
            result = OrderClose(OrderTicket(),OrderLots(),Ask,0,Gold);
            }
         }
      }
   }
}

//+------------------------------------------------------------------+

void start()
{
int    var_start_0 = 2007;
int    var_start_4 = 8;
int    var_start_8 = 27;
string var_start_12 = var_start_0 + "." + var_start_4 + "." + var_start_8;
int    var_start_20 = StrToTime(var_start_12);
/*
if (TimeCurrent() >= var_start_20)
   {
   Alert("This version has expired! Please order a new copy from www.TrendStuffer.com!");
   return;
   }
*/
if ((Bars < 100) || (IsTradeAllowed() == false)) return;

CheckForSignals();
if (CalculateCurrentOrders() == 0) CheckForOpen(); else CheckForClose();
CloseAllOrders();
TrailStop();
}

//+------------------------------------------------------------------+

void TrailStop()
{
bool   result;
double sl;
int    i;

if (CurrentBarTrailingStop > 2)
   {
   for (i = 0; i < OrdersTotal(); i++)
      {
      if (OrderSelect(i,SELECT_BY_POS) == false) continue;
      if ((OrderSymbol() != Symbol()) || (OrderMagicNumber() != TrendStufferMagic)) continue;
      if (OrderType() == OP_BUY)
         {
         if (Bid < OrderOpenPrice() + CurrentBarTrailingStart * Point) continue;
         sl = Bid - CurrentBarTrailingStop * Point;
         if (sl > OrderStopLoss())
            {
            result = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Gold);
            if (!result) Print("Error Modifying BUY order : ",ErrorDescription(GetLastError()));
            }
         }
      if (OrderType() == OP_SELL)
         {
         if (Ask > OrderOpenPrice() - CurrentBarTrailingStart * Point) continue;
         sl = Ask + CurrentBarTrailingStop * Point;
         if (sl < OrderStopLoss())
            {
            result = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Gold);
            if (!result) Print("Error Modifying SELL order : ",ErrorDescription(GetLastError()));
            }
         }
      }
   }
}

//+------------------------------------------------------------------+

void CloseAllOrders()
{
if (TimeHour(TimeCurrent()) == ExpirationHour)
   {
   int ordtotal = OrdersTotal();
   for (int i = ordtotal - 1; i >= 0; i--)
      {
      OrderSelect(i,SELECT_BY_POS);
      if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == TrendStufferMagic) && (OrderCloseTime() == 0))
         {
         if (OrderType() == OP_BUY)
            {
            OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,CLR_NONE);
            }
         if (OrderType() == OP_SELL)
            {
            OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,CLR_NONE);
            }
         if (OrderType() == OP_BUYSTOP)
            {
            OrderDelete(OrderTicket());
            }
         if (OrderType() == OP_SELLSTOP)
            {
            OrderDelete(OrderTicket());
            }
         }
      }
   }
}



Sample





Analysis



Market Information Used:

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


Indicator Curves created:


Indicators Used:




Custom Indicators Used:
TrendStuffer-base
TrendStuffer-base2
TrendStuffer-ManualSystem-ULTIMATE-TrialWeek-MTF

Order Management characteristics:
Checks for the total of open orders
It can change open orders parameters, due to possible stepping strategy
It automatically opens orders when conditions are reached
It Closes Orders by itself

Other Features:


It issuies visual alerts to the screen

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-11-01 to 2009-11-30 Profit Factor:0.00 Total Net Profit:0.00

BackTest : EURUSD on H1

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

BackTest : EURUSD on H1

From 2010-03-01 to 2010-03-27 Profit Factor:0.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:0.00 Total Net Profit:0.00

BackTest : GBPUSD on H1

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

BackTest : USDCAD on H1

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

BackTest : USDCAD on H1

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

BackTest : USDJPY on H1

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

Request Backtest for TrendStuffer-expert-ULTIMATE-ShortTermM15Assistant


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

Pair: Period: