TD_Points&Line_mgtd1

Download script
Author: Vladislav Goshkov (VG)
TD_Points&Line_mgtd1

This script is a technical analysis tool designed to identify specific price action patterns on a trading chart. It focuses on identifying historical "Supply" and "Demand" zones and projecting potential price targets based on the velocity and geometry of those zones.

Core Logic Overview

The script functions by scanning past price data to find significant structural points where the market showed clear resistance (Highs) or support (Lows). It then calculates the trajectory of these points to draw visual Trend Lines and identify "Breakout" signals.

Key Components

1. Supply and Demand Point Detection

The tool automatically scans the historical chart to locate two primary types of points:

  • Supply Points: These are high prices where the market showed a reversal or significant peak. The script looks for specific conditions where a price reached a high, was higher than the surrounding bars, and stood out from the previous closing prices.
  • Demand Points: These are low prices where the market showed strong support. Similar to supply points, it identifies "dips" that were lower than the surrounding bars and subsequent closing prices.

2. Trend Line Construction

Once these high and low points are identified, the script draws two dynamic trend lines on your chart:

  • Upper Trend Line (DodgerBlue): Connects the most recent significant Supply Points.
  • Lower Trend Line (OrangeRed): Connects the most recent significant Demand Points. These lines help traders visualize the "slope" of the market's price action over time.

3. Velocity and Breakout Analysis

The script doesn't just draw lines; it calculates the Velocity (the rate of change) between these points. It uses this mathematical slope to predict where a "Breakout" might occur:

  • It looks for instances where the current price crosses over the calculated trend line.
  • It checks for specific confirmation criteria (defined by user settings) to ensure the move is significant enough to be considered a valid signal.

4. Visual Signals and Targets

When the script detects a valid breakout of these trend lines, it provides three visual cues:

  • Breakout Arrows: It places an arrow on the chart at the exact moment the price broke through the trend line (Red for upward breaks, Blue for downward breaks).
  • Target Projection: The script calculates a "Target Price" based on the geometry of the previous trend structure. It averages three different calculation methods to find a balanced target level.
  • Target Line: A horizontal dotted line (YellowGreen) appears on the chart to show traders the projected price objective for that specific breakout move.

Summary for the User

Essentially, this tool acts as an automated "trend-path" mapper. It identifies where the market has historically held its ground, draws lines connecting those boundaries, and then alerts you with arrows and a target line whenever the price finally breaks through those historical barriers.

12 Views
0 Downloads
0 Favorites
TD_Points&Line_mgtd1
//+------------------------------------------------------------------+
//|                                        TD_Points&Lines_mgtd1.mq4 |
//|                                           Vladislav Goshkov (VG) |
//|                                                      4vg@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Vladislav Goshkov (VG)"
#property link      "4vg@mail.ru"

#property indicator_chart_window

extern int SetPoint=0;
extern int StepBack=0;
extern int Qw1=1;
extern int Qw2=1;
extern int Qw3=1;

int i=1,NP=0,D=0,
    iB_Up=0,iB_Dn=0,
    S1=0,
    S2=0,
    UpLev=0,
    DownLev=0,
    iP_Up=0,
    iP_Dn=0,
    value=0,
    CurPeriod=0,
    shift=0;

datetime  nTime=0;

double UpV=0,
       DownV=0,
       iP=0,
       target = 0,
       UpP[2]={0,0},
       DownP[2]={0,0},
       PP1=0,PP2=0,PP3=0;

int    DownBT[2]={0,0}, // Bar Time
       UpBT[2]={0,0},
       UpB[2]={0,0},    // Bar Num
       DownB[2]={0,0};
string buff_str = "";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
Comment(" ");   
ObjectDelete("TD_Up");
ObjectDelete("TD_Dn");
ObjectDelete("Target");
ObjectDelete("Break_Sig_Up");
ObjectDelete("Break_Sig_Dn");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   //int    counted_bars=IndicatorCounted();
//---- TODO: add your code here
if ( (nTime!=Time[0]) || (CurPeriod!=Period()) ) {
   UpP[0] = 0;
   UpP[1] = 0;

//=================================================
//******** Ïîèñê îïîðíûõ òî÷åê ïðåäëîæåíèÿ ********
//=================================================
   for(i=2+StepBack,D=2,NP=0; (NP<D)&&(i<Bars); i++) {//Begin
       if (High[i]!= High[i+1]) { 
          if( (High[i]>High[i+1] && High[i]>High[i-1] && High[i]>Close[i+2] ) 
              && High[i]> UpP[0] ) {
	     	 UpB[NP]  = i;
		    UpBT[NP] = Time[i];
		    UpP[NP]  = High[i];
		    NP++;
		    }
		  }

    if (High[i]== High[i+1])  { 
       if ( (High[i]>High[i+2] && High[i]>High[i-1] && High[i]>Close[i+3] ) && High[i]> UpP[0] ) {
	     	 UpB[NP]  = i;
		    UpBT[NP] = Time[i];
		    UpP[NP]  = High[i];
		    NP++;
		    }
		  }
     if(i == (Bars-2) ) {
	     	 UpB[NP]  = i;
		    UpBT[NP] = Time[i];
		    UpP[NP]  = High[i];
		    break;
		    }
     }//for(i=2+StepBack,D=2,NP=0; NP<D; ) {//End;

//=================================================
//********** Ïîèñê îïîðíûõ òî÷åê ñïðîñà ***********
//=================================================
   DownP[0] = 1000000000;
   DownP[1] = 1000000000;
   for(i=2+StepBack,D=2,NP=0; (NP<D)&&(i<Bars); i++) {//Begin
    if (Low[i]!= Low[i+1])  { 
       if ( (Low[i]<Low[i+1] && Low[i]<Low[i-1] && Low[i]<Close[i+2] ) && Low[i]< DownP[0] ){
	  	    DownB[NP] = i;
		    DownBT[NP]= Time[i];
		    DownP[NP] = Low[i];
		    NP++;
		    }
		  //i++;
		  };
    if (Low[i]== Low[i+1])  { 
       if ( (Low[i]<Low[i+2] && Low[i]<Low[i-1] && Low[i]<Close[i+3] ) && Low[i]< DownP[0] ){
	  	    DownB[NP] = i;
		    DownBT[NP]= Time[i];
		    DownP[NP] = Low[i];
		    NP++;
		    }
		  //i++;
		  };
     if (i == (Bars-2) ) { 
	  	    DownB[NP] = i;
		    DownBT[NP]= Time[i];
		    DownP[NP] = Low[i];
		    break;
		    };
     }//End;
     

UpV = (UpP[1]-UpP[0])/(UpB[0]-UpB[1]);
DownV = (DownP[1]-DownP[0])/(DownB[0]-DownB[1]);

//=================================================
//****       Ðèñóåì  TD-ëèíèè                  ****
//=================================================
   buff_str = "TD_Up";
   if(ObjectFind(buff_str) == -1) {
      ObjectCreate(buff_str, OBJ_TREND, 0, UpBT[1], UpP[1],UpBT[0], UpP[0]);
      ObjectSet(buff_str, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(buff_str, OBJPROP_COLOR, DodgerBlue);
      //ObjectMove(buff_str, 0, UpBT[1], UpP[1],UpBT[0], UpP[0]);
      }
   else {
      ObjectMove(buff_str, 1, UpBT[0], UpP[0]);
      ObjectMove(buff_str, 2, UpBT[1], UpP[1]);
      }

   buff_str = "TD_Dn";
   if(ObjectFind(buff_str) == -1) {
      ObjectCreate(buff_str, OBJ_TREND, 0, DownBT[1], DownP[1],DownBT[0], DownP[0]);
      ObjectSet(buff_str, OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet(buff_str, OBJPROP_COLOR, OrangeRed);
      //ObjectMove(buff_str, 0, UpBT[1], UpP[1],UpBT[0], UpP[0]);
      }
   else {
      ObjectMove(buff_str, 1, DownBT[0], DownP[0]);
      ObjectMove(buff_str, 2, DownBT[1], DownP[1]);
      }

   CurPeriod = Period();
   nTime = Time[0];
   }//if (nTime <> Time[0]) {
//----
   target = 0;

	for( i=UpB[0]; i>=StepBack; i--){
	   if( (Close[i]>UpP[0]+UpV*(UpB[0]-i)) && (Close[i+1]<UpP[0]+UpV*(UpB[0]-(i+1))) ) {
		    iB_Up=i; 
		    iP=UpP[0]+UpV*(UpB[0]-i);
		    iP_Up = iP; 
		    S1=Lowest(NULL,0,MODE_LOW,UpB[1],0);
		    S2=Lowest(NULL,0,MODE_CLOSE,UpB[1],0);

	       PP1=iP+((UpP[1]+UpV*(UpB[1]-S1))-Low[S1]);
	       PP2=iP+((UpP[1]+UpV*(UpB[1]-S2))-Low[S2]);
          PP3=iP+((UpP[1]+UpV*(UpB[1]-S1))-Close[S1]);
		    if((Qw1!=0 && Close[2]>Close[1])
          || (Qw2!=0 && Open[0]> iP)
          || (Qw3!=0 && (Close[0]+(Close[0]-MathMin(Low[0],Close[1])))<iP) ) {
             target = (PP1+PP2+PP3)/3;
             buff_str = "Break_Sig_Up";
             if(ObjectFind(buff_str) == -1) {
                ObjectCreate(buff_str, OBJ_ARROW,0, Time[iB_Up], iP+2*Point );
                ObjectSet(buff_str, OBJPROP_ARROWCODE, 164);
                ObjectSet(buff_str, OBJPROP_COLOR, Red);
                }
             else {
                ObjectMove(buff_str, 0, Time[iB_Up], iP+2*Point );
                }
             }
		    }
	   }

   for( i=DownB[0]; i>=StepBack;i--) {
	   if( (Close[i]<DownP[0]+DownV*(DownB[0]-i)) && (Close[i+1]>DownP[0]+DownV*(DownB[0]-(i+1))) ) {
	       iB_Dn=i; 
		    iP=DownP[0]+DownV*(DownB[0]-i);
		    iP_Dn = iP;
		    S1=Highest(NULL,0,MODE_HIGH,DownB[1],0);
		    S2=Highest(NULL,0,MODE_CLOSE,DownB[1],0);

          PP1=iP-(High[S1]-(DownP[1]+DownV*(DownB[1]-S1)));
	       PP2=iP-(High[S2]-(DownP[1]+DownV*(DownB[1]-S2)));
	       PP3=iP-(Close[S1]-(DownP[1]+DownV*(DownB[1]-S1)));
    		 if((Qw1!=0 && Close[1]<Close[0] )
          || (Qw2!=0 && Open[0] < iP )
		    || (Qw3!=0 && (Close[0]+(Close[0]-MathMax(High[0],Close[1])))>iP) ) {
             target = (PP1+PP2+PP3)/3;
             buff_str = "Break_Sig_Dn";
             if(ObjectFind(buff_str) == -1) {
                ObjectCreate(buff_str, OBJ_ARROW,0, Time[iB_Dn], iP+2*Point );
                ObjectSet(buff_str, OBJPROP_ARROWCODE, 164);
                ObjectSet(buff_str, OBJPROP_COLOR, Blue);
                }
             else {
                ObjectMove(buff_str, 0, Time[iB_Dn], iP+2*Point );
                }
             }
 		    }
		}//for( i=DownB[1]; i>=StepBack;i--) {

   buff_str = "Target";
   if(ObjectFind(buff_str) == -1) {
      ObjectCreate(buff_str, OBJ_HLINE,0, Time[0], target );
      ObjectSet(buff_str, OBJPROP_STYLE, STYLE_DOT);
      ObjectSet(buff_str, OBJPROP_COLOR, YellowGreen);
      //ObjectMove(buff_str, 0, UpBT[1], UpP[1],UpBT[0], UpP[0]);
      }
   else {
      ObjectMove(buff_str, 0, Time[0], target );
      }



//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments