TSD-TR_0.2-GBP

Profit factor:
64.03

This script is designed to automatically place and manage trades in the Forex market based on a specific trading strategy. It uses a combination of technical indicators and price action to determine when to enter and exit trades. Here's a breakdown of the logic:

1. Initialization and Settings:

  • The script starts by defining several adjustable settings (called "external variables") that the user can customize, such as:
    • Lot Size: The amount of currency to trade per order, either fixed or calculated based on account risk.
    • Take Profit: The profit level at which an open trade will be automatically closed.
    • Stop Loss: The loss level at which an open trade will be automatically closed.
    • Trailing Stop: A feature that automatically adjusts the stop-loss order as the price moves in a favorable direction, locking in profits.
    • Slippage: Acceptable price difference between the requested price and the actual executed price.

2. Weekly Trend Analysis (Triple Screen System):

  • MACD Indicator: The script uses the MACD indicator on a weekly timeframe to assess the overall trend. It compares the MACD values from the previous two weeks to determine the direction of the trend (uptrend or downtrend).
  • OSMA Indicator: Another indicator named OSMA is used to confirm the trend detected by the MACD.
  • The combination of MACD and OSMA acts as a filter: The script will only consider trades in the direction of the prevailing weekly trend.

3. Daily Price Action Analysis:

  • Williams Percent Range: The script uses an Indicator called Williams to see if the price is bullish or bearish in the daily timeframe.
  • High/Low Price Comparison: The script analyzes the relationship between previous days' high and low prices to determine potential entry points.

4. Order Placement:

  • Pending Orders: The script places pending orders (Buy Stop or Sell Stop) based on the following conditions:
    • The weekly trend (determined by MACD/OSMA) must be in agreement.
    • The Williams Indicator must be bullish to BUY and Bearish to SELL.
    • The entry price must be a specified distance (in pips) away from the current price.
    • If all the above conditions are met, the script places a pending order to either buy or sell the currency pair.

5. Order Management:

  • Order Modification: The script checks if there are existing pending orders, if the weekly trend changes, pending orders are deleted.
  • If the daily high/low prices change for BUYSTOP and SELLSTOP orders respectively, the pending orders prices are moved to that price.
  • Stop Loss Adjustment (Trailing Stop): The script automatically adjusts the stop-loss level of open trades as the price moves in a favorable direction, locking in profits.

In Simple Terms:

The script is a trading robot that uses a combination of trend analysis and price action to identify and execute trades in the Forex market.

  • It first determines the overall trend direction using weekly MACD and OSMA indicators.
  • Then, it looks for specific price patterns on the daily chart to identify potential entry points.
  • If the trend and price action align, the script places a pending order to either buy or sell the currency pair.
  • Finally, the script manages open trades by automatically adjusting the stop-loss level as the price moves in a favorable direction.
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains the lowest prices of each barSeries array that contains open time of each bar
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 reached
Indicators Used
MACD HistogramMoving Average of OscillatorForce index
13 Views
0 Downloads
0 Favorites
TSD-TR_0.2-GBP
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

/*[[
	Name := TSD
	Author := Copyright © 2005 Bob O'Brien / Barcode, MT4 code by Jesse Breaker, modified by TR
	Link := 
	Notes := Based on Alexander Elder's Triple Screen system. To be run on ANY chart timeframe, but assumes that each daily bar starts at 00:00.
	Lots := 1
	Stop Loss := 0
	Take Profit := 100
	Trailing Stop := 60
]]*/
//+------------------------------------------------------------------+
//|  External Variables                                              |
//+------------------------------------------------------------------+

extern double LotsIfNoMM = 1.0;
extern int TakeProfit = 100;
extern int Stoploss = 0;
extern int TrailingStop = 60;	
extern int Slippage=5;			// Slippage
extern int MM_Mode=0,MM_Risk=20;

int cnt=0,total=0;

double MacdCurrent=0, MacdPrevious=0, MacdPrevious2=0, Direction=0, OsMAPrevious=0, OsMAPrevious2=0, OsMADirection=0;

double newbar=999,LastLogTime=0,PrevDay=0,PrevMonth=0,PrevYear=0,PrevCurtime=0;

double PriceOpen=0,Lots;								// Price Open


bool First=True,OperationSuccess;

double TradesThisSymbol=0;
double WilliamsBuy=0, WilliamsSell=0, ForcePos=0, ForceNeg=0, Force=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;

int start()
{

if (! IsTesting()) 
Comment("TSD for MT4 ver beta 0.3 - 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","Is Daily Williams Bullish = ",WilliamsBuy,
        "\n","Is Daily Williams Bearish = ",WilliamsSell,
        "\n",
        "\n","Total Orders = ",total,
        "\n","Trades this Symbol(",Symbol(),") = ",TradesThisSymbol,
        "\n",
        "\n","New Bar Time is ",TimeToStr(newbar),
        "\n",
        "\n","Daily High[1] = ",iHigh(Symbol(),PERIOD_D1, 1),
        "\n","Daily High[2] = ",iHigh(Symbol(),PERIOD_D1, 2),
        "\n","Daily Low[1] = ",iLow(Symbol(),PERIOD_D1, 1),
        "\n","Daily Low[2] = ",iLow(Symbol(),PERIOD_D1, 2),
        "\n",
        "\n","Current Ask Price + 16 pips = ",Ask+(16*Point),
        "\n","Current Bid Price - 16 pips = ",Bid-(16*Point));
        
        
        
   if (MM_Mode < 0)  {
   Lots = MathCeil(AccountBalance()*MM_Risk/10000)/10;
     if (Lots > 100) {  
     Lots = 100;  
     }
   } else {
   Lots = LotsIfNoMM;
   }
   if (MM_Mode > 0)  
    {
   Lots = MathCeil(AccountBalance()*MM_Risk/10000)/10;
    if (Lots > 1)  
    {
    Lots = MathCeil(Lots);
    }
    if (Lots < 1)  
    {
    Lots = 1;
    }
    if (Lots > 100)  
    {  
     Lots = 100;  
     }
   }
        

     
	            
/////////////////////////////////////////////////
//  Process the next bar details
/////////////////////////////////////////////////

if (newbar != TimeDayOfWeek(CurTime())) 
{
	 newbar        = TimeDayOfWeek(CurTime());
	 //Newbar will be reset to 999 if the once-a-day order operations below fail, to ensure that they are retried on the next tick.


	  MacdPrevious  = iMACD(NULL,10080,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
	  MacdPrevious2 = iMACD(NULL,10080,12,26,9,PRICE_CLOSE,MODE_MAIN,2);
	  
	  if (newbar<4) //Modify this to switch to using current week's OSMA on a specific day of the week (0-Sunday,1,2,3,4,5,6) 
         {
         OsMAPrevious  = iOsMA(NULL,10080,12,26,9,PRICE_CLOSE,1);
	      OsMAPrevious2 = iOsMA(NULL,10080,12,26,9,PRICE_CLOSE,2);
         }
         else
         {
         OsMAPrevious  = iOsMA(NULL,10080,12,26,9,PRICE_CLOSE,0);
	      OsMAPrevious2 = iOsMA(NULL,10080,12,26,9,PRICE_CLOSE,1);
         }
         
	  //OsMAPrevious  = iCustom(NULL,10080,"OsMAtestclone_0.5",12,26,9,0,1);
	  //OsMAPrevious2 = iCustom(NULL,10080,"OsMAtestclone_0.5",12,26,9,0,2);
	  //OsMAPrevious  = iCustom(NULL,PERIOD_D1,"OsMA_5_bar_rolling_0.4",12,26,9,0,1);
	  //OsMAPrevious2 = iCustom(NULL,PERIOD_D1,"OsMA_5_bar_rolling_0.4",12,26,9,0,2);

     /*
     Force = iForce(NULL,1440,2,MODE_EMA,PRICE_CLOSE,1); 
     ForcePos = iForce(NULL,1440,2,MODE_EMA,PRICE_CLOSE,1) > 0;
	  ForceNeg = iForce(NULL,1440,2,MODE_EMA,PRICE_CLOSE,1) < 0;
      */
      
	  WilliamsBuy = TRUE;
	  WilliamsSell = TRUE;


	  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;
	          
        
        

/////////////////////////////////////////////////
//  Pending Order Management
/////////////////////////////////////////////////

   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++)        

   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(OsMADirection == -1)
  				{ 
  				   OperationSuccess=OrderDelete(OrderTicket());
  				   if (OperationSuccess==FALSE)
  				      {
  				      newbar=999;
  				      return(0);
  				      }
				} // close for if(Direction == -1)
			} // close for if(OrderSymbol()==Symbol() && OrderType()==OP_BUYSTOP)

         if(OrderSymbol()==Symbol() && OrderType()==OP_SELLSTOP)
         {

				if(OsMADirection == 1)
  				{ 
  				   OperationSuccess=OrderDelete(OrderTicket());
  				   if (OperationSuccess==FALSE)
  				      {
  				      newbar=999;
  				      return(0);
  				      }
				} //close for if(Direction == 1)
			} //close for if(OrderSymbol()==Symbol() && OrderType()==OP_SELLSTOP)


         if(OrderSymbol()==Symbol() && OrderType()==OP_BUYSTOP)
   	   {
				if(iHigh(Symbol(),PERIOD_D1, 1) < iHigh(Symbol(),PERIOD_D1, 2))
	  			{ 
					if(iHigh(Symbol(),PERIOD_D1, 1) > (Ask + 16 * Point))
	  				{ 
	  	   		  OperationSuccess=OrderModify(OrderTicket(),iHigh(Symbol(),PERIOD_D1, 1) + 1 * Point,iLow(Symbol(),PERIOD_D1, 1) - 1 * Point,iHigh(Symbol(),PERIOD_D1, 1) + 1 * Point + TakeProfit * Point,0,Cyan);
  				      if (OperationSuccess==FALSE)
  				         {
  				         newbar=999;
  				         return(0);
  				         }
	  				} //close for if(iHigh(Symbol(),PERIOD_D1, 1) > (Ask + 16 * Point))
	  				else
	  				{
	  				  OperationSuccess=OrderModify(OrderTicket(),Ask + 16 * Point,iLow(Symbol(),PERIOD_D1, 1) - 1 * Point,Ask + 16 * Point + TakeProfit * Point,0,Cyan);
  				      if (OperationSuccess==FALSE)
  				         {
  				         newbar=999;
  				         return(0);
  				         }
	  				
	  				} //close for else statement
	  			} //close for if(iHigh(Symbol(),PERIOD_D1, 1) < iHigh(Symbol(),PERIOD_D1, 2))
	  		} //close for if(OrderSymbol()==Symbol() && OrderType()==OP_BUYSTOP)
	  
	      if(OrderSymbol()==Symbol() && OrderType()==OP_SELLSTOP)
   		{
				if(iLow(Symbol(),PERIOD_D1, 1) > iLow(Symbol(),PERIOD_D1, 2))
				{ 
					if(iLow(Symbol(),PERIOD_D1, 1) < (Bid - 16 * Point))
					{
		   		  OperationSuccess=OrderModify(OrderTicket(),iLow(Symbol(),PERIOD_D1, 1) - 1 * Point,iHigh(Symbol(),PERIOD_D1, 1) + 1 * Point,iLow(Symbol(),PERIOD_D1, 1) - 1 * Point - TakeProfit * Point,0,Cyan);
  				      if (OperationSuccess==FALSE)
  				         {
  				         newbar=999;
  				         return(0);
  				         }
					} // close for if(iLow(Symbol(),PERIOD_D1, 1) < (Bid - 16 * Point))
					else
					{
					  OperationSuccess=OrderModify(OrderTicket(),Bid - 16 * Point,iHigh(Symbol(),PERIOD_D1, 1) + 1 * Point,Bid - 16 * Point - TakeProfit * Point,0,Cyan);
  				      if (OperationSuccess==FALSE)
  				         {
  				         newbar=999;
  				         return(0);
  				         }
      
					} //close for else statement
				} //close for if(iLow(Symbol(),PERIOD_D1, 1) > iLow(Symbol(),PERIOD_D1, 2))
			} //close for if(OrderSymbol()==Symbol() && OrderType()==OP_SELLSTOP)
		} // close for for(cnt=0;cnt<total;cnt++)
	} // close for if(TradesThisSymbol > 0)


/////////////////////////////////////////////////
//  NEW Orders to Place
/////////////////////////////////////////////////


   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++)        

	 if(TradesThisSymbol < 1) 
	 {
	   
	   if(OsMADirection == 1 && WilliamsBuy)
		{
			PriceOpen = iHigh(Symbol(),PERIOD_D1, 1) + 1 * Point;		// Buy 1 point above high of previous candle
			if(PriceOpen > (Ask + 16 * Point))  // Check if buy price is a least 16 points > Ask
			{
				OperationSuccess=OrderSend(Symbol(),OP_BUYSTOP,Lots,PriceOpen,Slippage,iLow(Symbol(),PERIOD_D1, 1) - 1 * Point,PriceOpen + TakeProfit * Point,"Buy Entry Order placed at "+CurTime(),0,0,Green);
		      if (OperationSuccess==FALSE)
		         {
		         newbar=999;
		         return(0);
		         }
      
			} // close for if(PriceOpen > (Ask + 16 * Point))
			else
			{
			   NewPrice = Ask + 16 * Point;
				OperationSuccess=OrderSend(Symbol(),OP_BUYSTOP,Lots,NewPrice,Slippage,iLow(Symbol(),PERIOD_D1, 1) - 1 * Point,NewPrice + TakeProfit * Point,"Buy Entry Order placed at "+CurTime(),0,0,Green);
		      if (OperationSuccess==FALSE)
		         {
		         newbar=999;
		         return(0);
		         }
 			} // close for else statement
	   } // close for if(Direction == 1 && WilliamsSell)
     
     
     if(OsMADirection == -1 && WilliamsSell)
     {
         PriceOpen = iLow(Symbol(),PERIOD_D1, 1) - 1 * Point;
			if(PriceOpen < (Bid - 16 * Point)) // Check if buy price is a least 16 points < Bid
			{
				OperationSuccess=OrderSend(Symbol(),OP_SELLSTOP,Lots,PriceOpen,Slippage,iHigh(Symbol(),PERIOD_D1, 1) + 1 * Point,PriceOpen - TakeProfit * Point,"Sell Entry Order placed at "+CurTime(),0,0,Green);
		      if (OperationSuccess==FALSE)
		         {
		         newbar=999;
		         return(0);
		         }
			} // close for if(PriceOpen < (Bid - 16 * Point))
			else
			{
				NewPrice = Bid - 16 * Point;
				OperationSuccess=OrderSend(Symbol(),OP_SELLSTOP,Lots,NewPrice,Slippage,iHigh(Symbol(),PERIOD_D1, 1) + 1 * Point,NewPrice - TakeProfit * Point,"Sell Entry Order placed at "+CurTime(),0,0,Green);
		      if (OperationSuccess==FALSE)
		         {
		         newbar=999;
		         return(0);
		         }
			} // close for else statement

      } // close for if(Direction == -1 && WilliamsBuy)
    } //Close of if(TradesThisSymbol < 1)





} // close for if (newbar != Time[0]) 




/////////////////////////////////////////////////
//  Stop Loss Management
/////////////////////////////////////////////////

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++)        

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 (IsTesting() && LastLogTime != iTime(NULL,PERIOD_H1,1)) 
         {
            LastLogTime=iTime(NULL,PERIOD_H1,1);
            OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()+Point*1,0,Cyan);
         }


			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 (IsTesting() && LastLogTime != iTime(NULL,PERIOD_H1,1)) 
         {
            LastLogTime=iTime(NULL,PERIOD_H1,1);
            OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()-Point*1,0,Cyan);
         }


			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))
         //else if (IsTesting()) OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderTakeProfit()-Point*1,0,Cyan);
		 } // 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 Jul 2025 - Sep 2025
0.35
Total Trades 21
Won Trades 19
Lost trades 2
Win Rate 90.48 %
Expected payoff -39.53
Gross Profit 442.19
Gross Loss -1272.30
Total Net Profit -830.11
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
289.50
Total Trades 26
Won Trades 22
Lost trades 4
Win Rate 84.62 %
Expected payoff 40478.31
Gross Profit 1056084.00
Gross Loss -3648.00
Total Net Profit 1052436.00
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.13
Total Trades 26
Won Trades 23
Lost trades 3
Win Rate 88.46 %
Expected payoff 6.96
Gross Profit 1620.00
Gross Loss -1439.00
Total Net Profit 181.00
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.00
Total Trades 60
Won Trades 60
Lost trades 0
Win Rate 100.00 %
Expected payoff 44.39
Gross Profit 2663.36
Gross Loss 0.00
Total Net Profit 2663.36
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
1.28
Total Trades 54
Won Trades 51
Lost trades 3
Win Rate 94.44 %
Expected payoff 10.71
Gross Profit 2645.78
Gross Loss -2067.22
Total Net Profit 578.56
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
0.94
Total Trades 53
Won Trades 50
Lost trades 3
Win Rate 94.34 %
Expected payoff -2.76
Gross Profit 2453.40
Gross Loss -2599.62
Total Net Profit -146.22
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.29
Total Trades 58
Won Trades 49
Lost trades 9
Win Rate 84.48 %
Expected payoff -57.41
Gross Profit 1340.00
Gross Loss -4670.00
Total Net Profit -3330.00
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.21
Total Trades 59
Won Trades 51
Lost trades 8
Win Rate 86.44 %
Expected payoff -112.37
Gross Profit 1714.00
Gross Loss -8344.00
Total Net Profit -6630.00
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.36
Total Trades 60
Won Trades 53
Lost trades 7
Win Rate 88.33 %
Expected payoff -50.46
Gross Profit 1722.82
Gross Loss -4750.28
Total Net Profit -3027.46
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.39
Total Trades 58
Won Trades 53
Lost trades 5
Win Rate 91.38 %
Expected payoff -50.34
Gross Profit 1864.58
Gross Loss -4784.46
Total Net Profit -2919.88
-100%
-50%
0%
50%
100%

Comments