MAB_TD_Sequential_v1

Download script
Author: Copyright � 2009, MetaQuotes Software Corp.
MAB_TD_Sequential_v1

This script is designed to identify specific price action patterns on a trading chart based on the "TD Sequential" methodology. It serves as a visual aid for traders to identify potential trend reversals and exhaustion points by tracking numerical sequences and structural levels.

The logic operates through four primary components:

1. The Sequential Counting System

The core of the script is a counting mechanism that monitors the relationship between current closing prices and prices from several bars back.

  • Buy/Sell Setups: The script looks for specific price movements to begin a count. If the price meets the criteria, it begins labeling numbers (1 through 9) on the chart. If the price movement breaks the required pattern before reaching "9," the sequence is automatically deleted.
  • Visual Differentiation: When a sequence reaches the number 9, the text style changes to indicate a completed setup, signaling that the trend may be reaching an exhaustion point.

2. Perfection and Completion Logic

Beyond just counting to 9, the script looks for "Perfected" signals.

  • Perfected Setup: After a count of 9 is achieved, the script monitors specific price highs and lows. If the price moves significantly in the opposite direction of the count (e.g., a new low is reached during a buy sequence), it triggers a "Perfected" signal. This is marked on the chart with a distinct arrow.
  • Alerts: The script can be configured to send an audible alert to the user specifically when these perfected setups occur.

3. The Countdown Mechanism

The script includes a secondary tracking system known as the "Countdown."

  • Once a setup is perfected, the logic begins a new countdown from 1 up to 13.
  • Symbolic Indicators: If the price remains at a specific threshold during this phase, it may display a "+" symbol rather than a number.
  • Completion: Upon reaching 13 in the countdown, the script places a final arrow on the chart and provides an alert, signaling a high-probability area of interest for traders.

4. Support and Resistance Lines (TDST)

In addition to the counting numbers, the script identifies and draws horizontal "TDST" lines on the chart.

  • Logic: These lines are not drawn randomly; they are generated only when a very specific set of price comparisons occurs over a multi-bar period.
  • Function: These act as dynamic support and resistance levels. The script ensures these lines persist across the chart until a new valid structural break occurs, helping traders visualize where price might stall or reverse.
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
5 Views
0 Downloads
0 Favorites
MAB_TD_Sequential_v1
//+------------------------------------------------------------------+
//|                        MAB_TD_Sequential                         |
//|                              v1.2                                |
//|                                                                  |
//|   Indicator based off of Tom DeMarks' TD Sequential indicator as |
//|   described in Jason Perl's book "DeMark Indicators"             |
//|                                                                  |
//|   05/22/2009 - Created Buy and Sell Setup along with TDST lines  |
//|               and set up criteria for arrow and alert to appear  |
//|               for a perfect setup.                               |
//|      issues:  TDST line starts updating before a full setup is   |
//|               made                                               |
//|      still needs:  Countdown criteria                            |
//|                                                                  |
//|   05/26/2009 - Added the Countdown criteria.  Countdown will also|
//|               create a "+" when 13 is reach but not perfected.   |
//|      still needs:  Countdown recycle criteria(currently recycles |
//|                  automatically when setup completed)             |   
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 MediumSpringGreen
#property indicator_color4 MediumSpringGreen
#property indicator_color5 Gold
#property indicator_color6 Gold

extern color Setup=MediumSpringGreen;
extern color Countdown=Gold;

extern int NumBars=1000;
extern int Space=50;    //space above or below high to place number

extern bool Alerts=false;

double Support[], Resistance[], bPerfected[], sPerfected[], Buy[], Sell[];

datetime last_alert = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   //TDST lines
   SetIndexBuffer(0,Support);
   SetIndexStyle(0,DRAW_LINE, STYLE_DOT, 1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexBuffer(1,Resistance);
   SetIndexStyle(1,DRAW_LINE, STYLE_DOT, 1);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   
   //Perfected Setup
   SetIndexBuffer(2,bPerfected);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,225);
   SetIndexBuffer(3,sPerfected);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,226);
   
   //Countdown
   SetIndexBuffer(4,Buy);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,225);
   SetIndexBuffer(5,Sell);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,226);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  for(int i=0;i<Bars;i++) 
  {
  ObjectDelete(""+i); 
  ObjectDelete("cd"+i);
  }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int bSetup, sSetup, bCountdown, sCountdown;
   int x;
   double tfm=Space*Point;
   double CountTest;
   bool bSetupInd, sSetupInd, bPerfect, sPerfect;
//----
   for(int i=NumBars; i>=0; i--)
      {
      ObjectDelete(""+i);
      ObjectDelete("cd"+i);
//+------------------------------------------------------------------+
//| Buy Setup                                                        |
//+------------------------------------------------------------------+
      if(Close[i]<=Close[i+4] && Close[i+1]>=Close[i+5] && bSetup==0)//start setup
         {  
         bSetup++;
         ObjectCreate(""+i,OBJ_TEXT,0,Time[i],Low[i]-tfm);
         ObjectSetText(""+i,""+bSetup,8,"Arial",Setup);
         }
      if(Close[i]<Close[i+4] && bSetup!=0 && ObjectFind(""+i)==-1) 
         {
         bSetup++;
         if(bSetup==9)
            {
            ObjectCreate(""+i,OBJ_TEXT,0,Time[i],Low[i]-tfm);
            ObjectSetText(""+i,""+bSetup,10,"Arial Black",Setup); 
            bSetup=0; 
            bSetupInd=true;
            sSetupInd=false;
            sCountdown=0;
            }
         else 
            {
            ObjectCreate(""+i,OBJ_TEXT,0,Time[i],Low[i]-tfm);
            ObjectSetText(""+i,""+bSetup,8,"Arial",Setup); 
            } 
         }
      //if setup is completed look for criteria for perfect setup
      if(bSetupInd==true)
         {
         if(Low[i+1]<=Low[i+3] || Low[i]<=Low[i+2])
            {
            bSetupInd=false;
            bPerfect=true;
            bPerfected[i]=Low[i]-tfm*2;
            bCountdown=1;
            }
          if(Alerts==True && last_alert!=Time[0])
            {
            last_alert = Time[0];
            Alert("TD Sequential - ", Symbol(), " Buy Signal Perfected");
            }  
          }         
      //Deletes numbers that were created if there is a break in sequence before 9 is reached
      else if(Close[i]>=Close[i+4] && bSetup!=0) 
         {
         for(x=i+1; x<=i+bSetup+1; x++) ObjectDelete(""+x);
         bSetup=0; 
         }
//+------------------------------------------------------------------+
//| Buy Countdown Setup                                              |
//+------------------------------------------------------------------+
      if(bCountdown==13 && Close[i]<=Close[i+1] && Close[i]>CountTest)
         {
         ObjectCreate("cd"+i,OBJ_TEXT,0,Time[i],Low[i]-tfm*2.5);
         ObjectSetText("cd"+i,"+",8,"Arial",Countdown); 
         }
      if(bCountdown==13 && Close[i]<=Close[i+1] && Close[i]<=CountTest)
         {
         ObjectCreate("cd"+i,OBJ_TEXT,0,Time[i],Low[i]-tfm*2.5);
         ObjectSetText("cd"+i,""+bCountdown,8,"Arial",Countdown);
         bCountdown=0;
         if(Alerts==True && last_alert!=Time[0])
            {
            last_alert = Time[0];
            Alert("TD Sequential - ", Symbol(), " Buy Countdown Completed");
            }
         Buy[i]=Low[i]-tfm*4;
         }
      if(bCountdown>=1 && bCountdown<13 && Close[i]<=Close[i+2])
         {
         if(bCountdown==8)CountTest=Close[i];
         ObjectCreate("cd"+i,OBJ_TEXT,0,Time[i],Low[i]-tfm*2.5);
         ObjectSetText("cd"+i,""+bCountdown,8,"Arial",Countdown); 
         bCountdown++;
         }  
//+------------------------------------------------------------------+
//| Sell Setup                                                       |
//+------------------------------------------------------------------+
      if(Close[i]>=Close[i+4] && Close[i+1]<=Close[i+5] && bSetup==0)//start setup
         {  
         sSetup++;
         ObjectCreate(""+i,OBJ_TEXT,0,Time[i],High[i]+tfm);
         ObjectSetText(""+i,""+sSetup,8,"Arial",Setup);
         }
      if(Close[i]>=Close[i+4] && sSetup!=0 && ObjectFind(""+i)==-1) 
         {
         sSetup++;
         if(sSetup==9) 
            {
            ObjectCreate(""+i,OBJ_TEXT,0,Time[i],High[i]+tfm);
            ObjectSetText(""+i,""+sSetup,10,"Arial Black",Setup); 
            sSetup=0; 
            sSetupInd=true;
            bSetupInd=false;
            bCountdown=0;
            }
         else 
            {
            ObjectCreate(""+i,OBJ_TEXT,0,Time[i],High[i]+tfm);
            ObjectSetText(""+i,""+sSetup,8,"Arial",Setup); 
            } 
         }
      //Perfected Setup
      if(sSetupInd==true)
         {
         if(Low[i+1]>=Low[i+3] || Low[i]>=Low[i+2])
            {
            sSetupInd=false;
            sPerfect=true;
            sPerfected[i]=High[i]+tfm*2;
            sCountdown=1;
            }
         if(Alerts==True && last_alert!=Time[0])
            {
            last_alert = Time[0];
            Alert("TD Sequential - ", Symbol(), " Sell Signal Perfected");
            }
          }
      //Deletes numbers that were created if there is a break in sequence before 9 is reached
      else if(Close[i]<=Close[i+4] && sSetup!=0) 
         {
         for(x=i+1; x<=i+sSetup; x++) ObjectDelete(""+x);
         sSetup=0; 
         }
//+------------------------------------------------------------------+
//| Sell Countdown Setup                                             |
//+------------------------------------------------------------------+
      if(sCountdown==13 && Close[i]>=Close[i+2] && Close[i]>=CountTest)
         {
         ObjectCreate("cd"+i,OBJ_TEXT,0,Time[i],High[i]+tfm*2.5);
         ObjectSetText("cd"+i,""+sCountdown,8,"Arial",Countdown);
         sCountdown=0;
         Sell[i]=High[i]+tfm*4;
         if(Alerts==True && last_alert!=Time[0])
            {
            last_alert = Time[0];
            Alert("TD Sequential - ", Symbol(), " Sell Countdown Completed");
            }
         } 
      if(sCountdown==13 && Close[i]>=Close[i+2] && Close[i]<CountTest)
         {
         ObjectCreate("cd"+i,OBJ_TEXT,0,Time[i],High[i]+tfm*2.5);
         ObjectSetText("cd"+i,"+",8,"Arial",Countdown); 
         }
      if(sCountdown>=1 && sCountdown<13 && Close[i]>=Close[i+2])
         {
         if(sCountdown==8)CountTest=Close[i];
         ObjectCreate("cd"+i,OBJ_TEXT,0,Time[i],High[i]+tfm*2.5);
         ObjectSetText("cd"+i,""+sCountdown,8,"Arial",Countdown); 
         sCountdown++;
         }
      }
//+------------------------------------------------------------------+
//| TDST Support and Resistance lines                                |
//+------------------------------------------------------------------+
   for(int j=Bars-counted_bars+10; j>=0; j--)
      {
      //TDST Support
      if(Close[j]<=Close[j+4]&& Close[j+1]>=Close[j+5] && Close[j-1]<=Close[j+3] && Close[j-2]<=Close[j+2] &&
      Close[j-3]<=Close[j+1] && Close[j-4]<=Close[j] && Close[j-5]<=Close[j-1] && Close[j-6]<=Close[j-2] &&
      Close[j-7]<=Close[j-3] && Close[j-8]<=Close[j-4])
         {
         Support[j]=High[j];
         Support[j+1]=EMPTY_VALUE;
         }
      else Support[j]=Support[j+1];
      //TDST Resistance
      if(Close[j]>=Close[j+4]&& Close[j+1]<=Close[j+5] && Close[j-1]>=Close[j+3] && Close[j-2]>=Close[j+2] &&
      Close[j-3]>=Close[j+1] && Close[j-4]>=Close[j] && Close[j-5]>=Close[j-1] && Close[j-6]>=Close[j-2] &&
      Close[j-7]>=Close[j-3] && Close[j-8]>=Close[j-4])
         {
         Resistance[j]=Low[j];
         Resistance[j+1]=EMPTY_VALUE;
         }
      else Resistance[j]=Resistance[j+1];
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments