TDSGlobal 4

Profit factor:
0.87

This script is designed to automate trading based on a specific strategy called the "Triple Screen" system, developed by Alexander Elder. The script is intended to run on a daily chart for a given currency pair. Here's a breakdown of what it does:

1. Setup and Configuration:

  • External Variables: The script begins by defining several settings that you can adjust. These include:
    • Trade Size (Lots): How much of the currency to trade in each transaction.
    • Profit Target (TakeProfit): How many "points" (small price increments) the price needs to move in your favor to automatically close the trade and take profit.
    • Stop Loss (Stoploss): How many "points" the price needs to move against you to automatically close the trade and prevent further losses.
    • Trailing Stop (TrailingStop): A dynamic stop loss that adjusts as the price moves in your favor, locking in profits.
    • Slippage (Slippage): The acceptable difference between the requested price and the actual price the trade is executed at.
    • Stop Year (StopYear): A year to stop the script from running automatically.
    • Money Management Settings (MM, Leverage, AcctSize): Settings related to how much risk the script takes based on your account size and leverage.
    • Williams Percent Range (WilliamsP, WilliamsL, WilliamsH): Parameters for a technical indicator that helps identify overbought and oversold conditions.
  • Internal Variables: The script also sets up variables to store information it needs to run, such as:
    • Order details (ticket numbers)
    • Indicator values (MACD, OSMA, Williams Percent Range)
    • Price information (open price, high, low)
    • Time-related data (new bar time)
    • Flags (First).

2. Core Logic (The start() Function):

The start() function is the heart of the script, executed repeatedly. Here's what it does:

  • Trading Volume Calculation: calculates the trading volume based on the account balance.
  • Information Display (Comment): A section commented out that displays information about the indicators and trading state for debugging purposes. This section is never used by the script since it�s commented out.
  • Order Tracking: The script counts the number of open trades for the specific currency pair it's running on. This helps it avoid opening multiple trades when it shouldn't.
  • Indicator Calculation: The script calculates the values of several technical indicators using historical price data:
    • MACD (Moving Average Convergence Divergence): Helps identify the direction and strength of a trend.
    • OSMA (Moving Average of Oscillator): Measures the difference between the MACD and its signal line, highlighting momentum.
    • Williams Percent Range: Measures how overbought or oversold the market is.
  • Trend Determination:
    • Based on the MACD values, the script determines the overall market direction (upward, downward, or neutral).
    • It also determines the direction based on the OSMA indicator.
  • Time-Based Execution Restriction: The script defines specific time windows (minutes of the hour) during which it's allowed to place new orders. This is likely to avoid conflicts with other automated strategies or to focus on periods of higher market activity.
  • New Bar Detection: The script checks if a new daily bar has formed. This ensures that it only acts on new daily data, rather than reacting to intraday price fluctuations.

3. Trading Decisions:

  • Entry Conditions (Opening New Trades): If a new bar has formed and there are no existing trades for the currency pair, the script evaluates the following conditions to place a new order:
    • Buy Condition:
      • The MACD indicates an upward trend.
      • The Williams Percent Range indicates an oversold condition (potential for price to rise).
      • The script calculates a potential buy price slightly above the high price of the previous day.
      • It checks if this potential buy price is sufficiently above the current ask price (the price you'd pay to buy). This is probably to avoid placing orders too close to the current market price.
      • If all conditions are met, the script places a "Buy Stop" order. A buy stop order is an order to buy the currency if the price reaches a certain level above the current price. It also sets a stop loss and a take profit level for this order.
    • Sell Condition:
      • The MACD indicates a downward trend.
      • The Williams Percent Range indicates an overbought condition (potential for price to fall).
      • The script calculates a potential sell price slightly below the low price of the previous day.
      • It checks if this potential sell price is sufficiently below the current bid price (the price you'd receive if you sell).
      • If all conditions are met, the script places a "Sell Stop" order. A sell stop order is an order to sell the currency if the price reaches a certain level below the current price. It also sets a stop loss and a take profit level for this order.
  • Order Management (Adjusting Existing Orders):
    • Canceling Opposite Orders: If there is already a pending order and the MACD direction changes, the script cancels the pending order.
    • Modifying Pending Orders: If there's a pending "Buy Stop" or "Sell Stop" order, the script may adjust the order price based on the previous day's high/low prices and the current ask/bid prices. This is to ensure the orders are still valid and aligned with the current market conditions. It also takes into consideration the 16 points distance for the operation.
  • Stop Loss Management (Protecting Profits):
    • Trailing Stop: If there are open "Buy" or "Sell" trades, the script implements a trailing stop loss. This means the stop loss level is automatically adjusted upwards (for buy trades) or downwards (for sell trades) as the price moves in your favor. This helps to lock in profits while still allowing the trade to potentially gain further.

In Summary:

The script automates a trading strategy based on technical indicators. It looks for specific conditions based on the MACD and Williams Percent Range to identify potential buying or selling opportunities. It then places pending orders (Buy Stop or Sell Stop) and manages those orders, adjusting them or canceling them based on changing market conditions. Finally, it implements a trailing stop loss to protect profits. It operates only at the timeframe of a single day and at certain hours.

Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
Indicators Used
MACD HistogramMoving Average of OscillatorLarry William percent range indicator
9 Views
0 Downloads
0 Favorites
TDSGlobal 4
//+------------------------------------------------------------------+
//|                                                   TDSGlobal .mq4 |
//|                           Copyright © 2005 Bob O'Brien / Barcode |
//|                                       http://mak.tradersmind.com |
//+------------------------------------------------------------------+

// Expert based on Alexander Elder's Triple Screen system. 
// To be run only on a Daily chart.
//---- External Variables
extern int Lots = 1;
extern int TakeProfit = 999;
extern int Stoploss = 0;
extern int TrailingStop = 10;
extern int Slippage = 5; // Slippage
extern int StopYear = 2005;
extern int MM = 0, Leverage = 1, AcctSize = 10000;
extern int WilliamsP = 24, WilliamsL = -75, WilliamsH = -25;
//----
int BuyEntryOrderTicket = 0, SellEntryOrderTicket = 0, cnt = 0, total = 0;
double MacdCurrent = 0, MacdPrevious = 0, MacdPrevious2 = 0, Direction = 0, 
       OsMAPrevious = 0, OsMAPrevious2 = 0, OsMADirection = 0;
double newbar = 0, PrevDay = 0, PrevMonth = 0, PrevYear = 0, PrevCurtime = 0;
double PriceOpen = 0; // Price Open
bool First = True;
double TradesThisSymbol = 0;
double WilliamsSell = 0, WilliamsBuy = 0, Williams = 0,NewPrice = 0;
double StartMinute1 = 0, EndMinute1 = 0, StartMinute2 = 0, EndMinute2 = 0, 
      StartMinute3 = 0, EndMinute3 = 0;
double StartMinute4 = 0, EndMinute4 = 0, StartMinute5 = 0, EndMinute5 = 0, 
       StartMinute6 = 0, EndMinute6 = 0;
double StartMinute7 = 0, EndMinute7 = 0, DummyField = 0;
double Lotsf = 0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   Lotsf = MathRound(AccountBalance() / 10000);
/*   Comment("TSD for MT4 ver beta 0.2 - DO NOT USE WITH REAL MONEY YET",
           "\n",
           "\n","Weekly MacdPrevious = ", MacdPrevious, "    Weekly OsMAPrevious  = ",
           OsMAPrevious,
           "\n","Weekly MacdPrevious2 = ", MacdPrevious2, "    Weekly OsMAPrevious2 = ", 
           OsMAPrevious2,
           "\n","Weekly Direction = ", Direction, "    Weekly OsMADirection = ", OsMADirection,
           "\n",
           "\n","Lotsf = ", Lotsf,
           "\n",
           "\n","Daily Williams = ", Williams,
           "\n","Is Daily Williams Bullish = ", WilliamsSell,
           "\n","Is Daily Williams Bearish = ", WilliamsBuy,
           "\n",
           "\n","Total Orders = ", total,
           "\n","Trades this Symbol(",Symbol(), ") = ", TradesThisSymbol,
           "\n",
           "\n","New Bar Time is ", TimeToStr(newbar),
           "\n",
           "\n","Daily High[1] = ",High[1],
           "\n","Daily High[2] = ",High[2],
           "\n","Daily Low[1] = ",Low[1],
           "\n","Daily Low[2] = ",Low[2],
           "\n",
           "\n","Current Ask Price + 16 pips = ",Ask+(16*Point),
           "\n","Current Bid Price - 16 pips = ",Bid-(16*Point));*/
   total = OrdersTotal();
   TradesThisSymbol = 0;
   for(cnt = 0; cnt < total; cnt++)
     { 
       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
       if(OrderSymbol() == Symbol())
         {
           TradesThisSymbol++;
         } // close for if(OrderSymbol()==Symbol())
     } // close for for(cnt=0;cnt<total;cnt++)         
   MacdPrevious  = iMACD(NULL, 1440, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 1);
   MacdPrevious2 = iMACD(NULL, 1440, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, 2);
   OsMAPrevious  = iOsMA(NULL, 1440, 12, 26, 9, PRICE_CLOSE, 1);
   OsMAPrevious2 = iOsMA(NULL, 1440, 12, 26, 9, PRICE_CLOSE, 2);
   Williams = iWPR(NULL, 1440, WilliamsP, 1); 
   WilliamsSell = iWPR(NULL, 1440, 24, 1) > WilliamsL;
   WilliamsBuy  = iWPR(NULL, 1440, 24, 1) < WilliamsH;
   if(MacdPrevious > MacdPrevious2) 
       Direction = 1;
   if(MacdPrevious < MacdPrevious2) 
       Direction = -1;
   if(MacdPrevious == MacdPrevious2) 
       Direction = 0;
   if(OsMAPrevious > OsMAPrevious2) 
       OsMADirection = 1;
   if(OsMAPrevious < OsMAPrevious2) 
       OsMADirection = -1;
   if(OsMAPrevious == OsMAPrevious2) 
       OsMADirection = 0;
// Select a range of minutes in the day to start trading based on the currency pair.
// This is to stop collisions occurring when 2 or more currencies set orders at the same time.
   if(Symbol() == "USDCHF")
     {
       StartMinute1 = 0;
       EndMinute1   = 1;
       StartMinute2 = 8;
       EndMinute2   = 9;
       StartMinute3 = 16;
       EndMinute3   = 17;
       StartMinute4 = 24;
       EndMinute4   = 25;
       StartMinute5 = 32;
       EndMinute5   = 33;
       StartMinute6 = 40;
       EndMinute6   = 41;
       StartMinute7 = 48;
       EndMinute7   = 49;
     } // close for if(Symbol() == "USDCHF")
   if(Symbol() == "GBPUSD")
     {  
       StartMinute1 = 2;
       EndMinute1   = 3;
       StartMinute2 = 10;
       EndMinute2   = 11;
       StartMinute3 = 18;
       EndMinute3   = 19;
       StartMinute4 = 26;
       EndMinute4   = 27;
       StartMinute5 = 34;
       EndMinute5   = 35;
       StartMinute6 = 42;
       EndMinute6   = 43;
       StartMinute7 = 50;
       EndMinute7   = 51;
     } // close for if(Symbol() == "GBPUSD")
   if(Symbol() == "USDJPY")
     {
       StartMinute1 = 4;
       EndMinute1   = 5;
       StartMinute2 = 12;
       EndMinute2   = 13;
       StartMinute3 = 20;
       EndMinute3   = 21;
       StartMinute4 = 28;
       EndMinute4   = 29;
       StartMinute5 = 36;
       EndMinute5   = 37;
       StartMinute6 = 44;
       EndMinute6   = 45;
       StartMinute7 = 52;
       EndMinute7   = 53;
     } //close for if(Symbol() == "USDJPY")
   if(Symbol() == "EURUSD")
     {
       StartMinute1 = 6;
       EndMinute1   = 7;
       StartMinute2 = 14;
       EndMinute2   = 15;
       StartMinute3 = 22;
       EndMinute3   = 23;
       StartMinute4 = 30;
       EndMinute4   = 31;
       StartMinute5 = 38;
       EndMinute5   = 39;
       StartMinute6 = 46;
       EndMinute6   = 47;
       StartMinute7 = 54;
       EndMinute7   = 59;
     } // close for if(Symbol() == "EURUSD")
   if((Minute() >= StartMinute1 && Minute() <= EndMinute1) ||
      (Minute() >= StartMinute2 && Minute() <= EndMinute2) ||
      (Minute() >= StartMinute3 && Minute() <= EndMinute3) ||
      (Minute() >= StartMinute4 && Minute() <= EndMinute4) ||
      (Minute() >= StartMinute5 && Minute() <= EndMinute5) ||
      (Minute() >= StartMinute6 && Minute() <= EndMinute6) ||
      (Minute() >= StartMinute7 && Minute() <= EndMinute7))
     {
       // dummy statement because MT will not allow me to use a continue statement
       DummyField = 0;
     } // close for LARGE if statement
   else 
       return(0);
/////////////////////////////////////////////////
//  Process the next bar details
/////////////////////////////////////////////////
   if(newbar != Time[0]) 
     {
       newbar = Time[0];
       if(TradesThisSymbol < 1) 
         {
           if(Direction == 1 && WilliamsBuy)
             {
               // Buy 1 point above high of previous candle
               PriceOpen = High[1] + 1 * Point; 
               // Check if buy price is a least 16 points > Ask
               if(PriceOpen > (Ask + 16 * Point))  
                 {
                   BuyEntryOrderTicket = OrderSend(Symbol(), OP_BUYSTOP, Lotsf, PriceOpen, 
                                                   Slippage, Low[1] - 1 * Point, 
                                                   PriceOpen + TakeProfit * Point, 
                                                   "Buy Entry Order placed at " + CurTime(), 
                                                   0, 0, Green);
                   return(0);

                 } // close for if(PriceOpen > (Ask + 16 * Point))
               else
                 {
                   NewPrice = Ask + 16 * Point;
                   BuyEntryOrderTicket = OrderSend(Symbol(), OP_BUYSTOP, Lotsf, NewPrice, 
                                                   Slippage, Low[1] - 1 * Point, 
                                                   NewPrice + TakeProfit * Point, 
                                                   "Buy Entry Order placed at " + CurTime(), 
                                                   0, 0, Green);
                   return(0);
                 } // close for else statement
             } // close for if(Direction == 1 && WilliamsBuy)
           if(Direction == -1 && WilliamsSell)
             {
               PriceOpen = Low[1] - 1 * Point;
               // Check if buy price is a least 16 points < Bid
               if(PriceOpen < (Bid - 16 * Point)) 
                 {
                   SellEntryOrderTicket = OrderSend(Symbol(), OP_SELLSTOP, Lotsf, PriceOpen, 
                                                    Slippage, High[1] + 1 * Point, 
                                                    PriceOpen - TakeProfit * Point, 
                                                    "Sell Entry Order placed at " + CurTime(), 
                                                    0, 0, Green);
                   return(0);
                 } // close for if(PriceOpen < (Bid - 16 * Point))
               else
                 {
                   NewPrice = Bid - 16 * Point;
                   SellEntryOrderTicket = OrderSend(Symbol(), OP_SELLSTOP, Lotsf, NewPrice, 
                                                    Slippage, High[1] + 1 * Point, 
                                                    NewPrice - TakeProfit * Point, 
                                                    "Sell Entry Order placed at " + CurTime(), 
                                                    0, 0, Green);
                   return(0);
                 } // close for else statement

             } // close for if(Direction == -1 && WilliamsSell)
         } //Close of if(TradesThisSymbol < 1)
/////////////////////////////////////////////////
//  Pending Order Management
/////////////////////////////////////////////////
       if(TradesThisSymbol > 0)
         {
           total = OrdersTotal();
           for(cnt = 0; cnt < total; cnt++)
             { 
               OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
               if(OrderSymbol() == Symbol() && OrderType() == OP_BUYSTOP)
                 {
                   if(Direction == -1)
                     { 
                       OrderDelete(OrderTicket());
                       return(0); 
                     } // close for if(Direction == -1)
                 } // close for if(OrderSymbol()==Symbol() && OrderType()==OP_BUYSTOP)
               if(OrderSymbol() == Symbol() && OrderType() == OP_SELLSTOP)
                 {
                   if(Direction == 1)
                     { 
                       OrderDelete(OrderTicket());
                       return(0); 
                     } //close for if(Direction == 1)
                 } //close for if(OrderSymbol()==Symbol() && OrderType()==OP_SELLSTOP)
               if(OrderSymbol() == Symbol() && OrderType() == OP_BUYSTOP)
                 {
                   if(High[1] < High[2])
                     { 
                       if(High[1] > (Ask + 16 * Point))
                         { 
                           OrderModify(OrderTicket(), High[1] + 1 * Point, Low[1] - 1 * Point,
                                       OrderTakeProfit(), 0, Cyan);
                           return(0);
                         } //close for if(High[1] > (Ask + 16 * Point))
                       else
                         {
                           OrderModify(OrderTicket(), Ask + 16 * Point, Low[1] - 1 * Point,
                                       OrderTakeProfit(), 0, Cyan);
                           return(0);
  
                         } //close for else statement
                     } //close for if(High[1] < High[2])
                 } //close for if(OrderSymbol()==Symbol() && OrderType()==OP_BUYSTOP)
               if(OrderSymbol() == Symbol() && OrderType() == OP_SELLSTOP)
                 {
                   if(Low[1] > Low[2])
                     { 
                       if(Low[1] < (Bid - 16 * Point))
                         {
                           OrderModify(OrderTicket(), Low[1] - 1 * Point, High[1] + 1 * Point,
                                       OrderTakeProfit(), 0, Cyan);
                           return(0);
                         } // close for if(Low[1] < (Bid - 16 * Point))
                       else
                         {
                           OrderModify(OrderTicket(), Bid - 16 * Point, High[1] + 1 * Point, 
                                       OrderTakeProfit(), 0, Cyan);
                           return(0);
      
                         } //close for else statement
                     } //close for if(Low[1] > Low[2])
                 } //close for if(OrderSymbol()==Symbol() && OrderType()==OP_SELLSTOP)
             } // close for for(cnt=0;cnt<total;cnt++)
         } // close for if(TradesThisSymbol > 0)
     } // close for if (newbar != Time[0]) 
/////////////////////////////////////////////////
//  Stop Loss Management
/////////////////////////////////////////////////
   if(TradesThisSymbol > 0)
     {
       total = OrdersTotal();
       for(cnt = 0; cnt < total; cnt++)
         { 
           OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
           if(OrderSymbol() == Symbol() && OrderType() == OP_BUY)
             {
               if(Ask - OrderOpenPrice() > (TrailingStop * Point))
                 { 
                   if(OrderStopLoss() < (Ask - TrailingStop * Point))
                     { 
                       OrderModify(OrderTicket(), OrderOpenPrice(), Ask - TrailingStop * Point,
                                   Ask + TakeProfit * Point, 0, Cyan);
                       return(0);

                     } // close for if(OrderStopLoss() < (Ask - TrailingStop * Point))
                 } // close for if(Ask-OrderOpenPrice() > (TrailingStop * Point))
             } // close for if(OrderSymbol()==Symbol() && OrderType()==OP_BUY)
           if(OrderSymbol() == Symbol() && OrderType() == OP_SELL)
             {
               if(OrderOpenPrice() - Bid > (TrailingStop * Point))
                 { 
                   if(OrderStopLoss() > (Bid + TrailingStop * Point))
                     { 
                       OrderModify(OrderTicket(), OrderOpenPrice(), Bid + TrailingStop * Point,
                                   Bid - TakeProfit * Point, 0, Cyan);
                       return(0);

                     } // close for if(OrderStopLoss() > (Bid + TrailingStop * Point))
                 } // close for if(OrderOpenPrice() - Bid > (TrailingStop * Point))
             } // close for if(OrderSymbol()==Symbol() && OrderType()==OP_SELL)
         } // close for for(cnt=0;cnt<total;cnt++)
     } // close for if(TradesThisSymbol > 0)
//----
   return(0);
  } // close for start
//+------------------------------------------------------------------+

Profitability Reports

GBP/AUD Jan 2025 - Jul 2025
1.04
Total Trades 187
Won Trades 37
Lost trades 150
Win Rate 19.79 %
Expected payoff 6.10
Gross Profit 29318.29
Gross Loss -28177.89
Total Net Profit 1140.40
-100%
-50%
0%
50%
100%
EUR/USD Jan 2025 - Jul 2025
0.82
Total Trades 114
Won Trades 15
Lost trades 99
Win Rate 13.16 %
Expected payoff -30.44
Gross Profit 16005.00
Gross Loss -19475.00
Total Net Profit -3470.00
-100%
-50%
0%
50%
100%
AUD/USD Jan 2025 - Jul 2025
0.67
Total Trades 118
Won Trades 8
Lost trades 110
Win Rate 6.78 %
Expected payoff -38.23
Gross Profit 9208.00
Gross Loss -13719.00
Total Net Profit -4511.00
-100%
-50%
0%
50%
100%
USD/CAD Oct 2024 - Jan 2025
0.88
Total Trades 27
Won Trades 3
Lost trades 24
Win Rate 11.11 %
Expected payoff -11.70
Gross Profit 2406.14
Gross Loss -2722.03
Total Net Profit -315.89
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.87
Total Trades 25
Won Trades 3
Lost trades 22
Win Rate 12.00 %
Expected payoff -13.56
Gross Profit 2200.00
Gross Loss -2539.00
Total Net Profit -339.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
1.14
Total Trades 42
Won Trades 7
Lost trades 35
Win Rate 16.67 %
Expected payoff 21.60
Gross Profit 7625.00
Gross Loss -6718.00
Total Net Profit 907.00
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.70
Total Trades 32
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -33.00
Gross Profit 2466.00
Gross Loss -3522.00
Total Net Profit -1056.00
-100%
-50%
0%
50%
100%

Comments