TrendStuffer-expert-ULTIMATE-ShortTermM15Assistant

Profit factor:
0.00

This script is designed to assist someone in manually trading GBP/USD on a 15-minute chart. It's not fully automatic; it provides signals and can manage trades based on those signals, but it seems designed to work with a trader, not replace them.

Here's a breakdown of its core functions:

  1. Setup & Customization: The script has many settings you can tweak. These control things like:

    • The identification number it uses to track its own trades (Magic Number).
    • The maximum acceptable slippage (price change) when placing orders.
    • The hours of the day when it's allowed to trade.
    • Parameters for indicators which it uses to generate trading signals.
    • How much of your account balance it should risk on each trade.
    • Take profit and stop loss levels (the price points where it automatically closes a trade for a profit or to limit losses).
    • Trailing stop parameters which aim to lock in profits as the trade moves in a favorable direction.
    • An option to use a "3-Positions" trading strategy (explained later).
  2. Risk Management: The script has functions to calculate how much of the currency to buy or sell (Lot Size) based on either a fixed amount or a percentage of your account balance that you're willing to risk.

  3. Order Tracking: It keeps track of how many buy and sell orders it has open at any given time, specifically those with its own unique "magic number."

  4. Signal Generation: This is a core component. The script uses custom indicators (TrendStuffer-base, TrendStuffer-base2, TrendStuffer-ManualSystem-ULTIMATE-TrialWeek-MTF) to determine potential buy or sell signals. These indicators likely analyze price patterns and trends. The script then compares current and previous prices against values calculated by these indicators to generate buy or sell signals. It also considers the output of other indicators on higher timeframes (FilterTF1, FilterTF2) as a filter to confirm the signals.

  5. Opening Trades: If the script identifies a buy or sell signal, and it's within the allowed trading hours, it will attempt to open a trade in the corresponding direction. The size of the trade (Lot Size) is determined by the risk management settings. Stop-loss and take-profit levels are also set automatically. The script will make multiple attempts to place the order if the first attempts fail.

  6. Closing Trades: The script checks to see if it should close open trades. Specifically:

    • It looks for conditions indicated by the custom indicators which suggest a trade should be closed for profit.
    • If the price has moved favorably, it may adjust the stop-loss price closer to the current price to protect profit ("break even").
  7. Trailing Stop: It has a trailing stop mechanism. This means that if a trade is profitable, the stop-loss price will automatically move up (for buy orders) or down (for sell orders) to lock in some of those profits.

  8. "Three Positions" Strategy: The script can optionally use a more complex trading strategy where it opens three separate positions with different lot sizes, take profit levels, and initial stop-loss levels. The idea is to scale out of the trade at different profit targets and potentially lock in profits as the trade moves favorably. It may use "break even" logic on these positions.

  9. Time-Based Closure: The script has a feature to close all open trades at a specific hour of the day. This can be useful for limiting exposure overnight or over the weekend.

In essence, this script provides tools to generate trading signals, automatically open and close trades based on those signals and pre-defined rules, and manage risk and profit. However, it appears to rely on the user to understand the signals and make final trading decisions, as suggested by the "ASSIST manual trading" description. The script also uses external indicators and is based on their performance.

Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Miscellaneous
It issuies visual alerts to the screen
9 Views
0 Downloads
0 Favorites
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());
            }
         }
      }
   }
}

Comments