TrendByAngle
Download scriptThis tool is designed to provide visual assistance for traders by automatically identifying and plotting key price levels on a trading chart based on historical high and low points. Instead of requiring the user to manually draw trend lines, the script scans a specific window of past market data to project potential geometric angles.
How the Logic Works
Data Analysis Window The script looks back at a pre-defined period of recent market history (set by a "Cycle" variable). During every new minute of trading activity, it automatically scans this timeframe to find two specific pieces of information:
- The highest price reached during that period.
- The lowest price reached during that period.
Dynamic Visual Mapping Once these peak and valley points are identified, the script generates a series of diagonal lines originating from those coordinates. These lines serve as visual guides to help traders perceive the "trajectory" of the market:
- Upward Projections: From the lowest point found in the cycle, the script draws four different upward-sloping lines at varying angles.
- Downward Projections: From the highest point found in the cycle, the script draws four different downward-sloping lines at corresponding negative angles.
Visual Organization To ensure the chart remains clean and readable, the tool uses a color-coded system:
- Upward Lines: Displayed in Aqua, representing potential bullish trajectories.
- Downward Lines: Displayed in Red, representing potential bearish trajectories.
The script also varies the line styles (using different dot patterns) depending on how steep the angle is, making it easier for the user to distinguish between shallow and aggressive trends at a glance.
Automatic Maintenance The tool is designed to be "self-cleaning." Every time the market updates, it clears out the previous set of lines before drawing the new ones. This ensures that the chart does not become cluttered with outdated data and that the lines always correspond strictly to the most recent high and low points within the defined cycle.
#property copyright "Copyright 2012, YangShu.net"
#property link "http://yangshu.net"
#property indicator_chart_window
int now;//define a time variant
extern int Cycle=144;
int init()
{
DropAllAngleLine();
return(0);
}
int deinit()
{
DropAllAngleLine();
return(0);
}
void DrawAngleLine(string lname,int bar,double value,int angle)
{
int style;
color linecolor;
if (angle>0)
{
linecolor=Aqua;
if (angle==85 || angle==25) style=STYLE_DASHDOT;else style=STYLE_DOT;
}
else
{
linecolor=Red;
if (angle==-85 || angle==-25) style=STYLE_DASHDOT;else style=STYLE_DOT;
}
ObjectCreate(lname,OBJ_TRENDBYANGLE,0,bar,value);
ObjectSet(lname,OBJPROP_COLOR,linecolor);
ObjectSet(lname,OBJPROP_STYLE,style);
ObjectSet(lname,OBJPROP_WIDTH,1);
ObjectSet(lname,OBJPROP_ANGLE,angle);
}
void DropAllAngleLine()
{
int obj_total=ObjectsTotal();
string obj_name;
for(int i=0;i<obj_total;i++)
{
obj_name=ObjectName(i);
if (StringFind(obj_name,"Angle",0)>0) ObjectDelete(obj_name);
}
}
int start()
{
if (now!=Minute()) //every minute refresh once
{
now=Minute();
double HighValue,LowValue;
int HstBar,LstBar;
DropAllAngleLine();
DropAllAngleLine(); //twice delete
HighValue=High[iHighest(NULL,0,MODE_HIGH,Cycle,1)];
LowValue= Low[iLowest(NULL,0,MODE_LOW,Cycle,1)];
HstBar=Time[iHighest(NULL,0,MODE_HIGH,Cycle,1)];
LstBar=Time[iLowest(NULL,0,MODE_LOW,Cycle,1)];
DrawAngleLine("UpAngleA",LstBar,LowValue,25);
DrawAngleLine("UpAngleB",LstBar,LowValue,45);
DrawAngleLine("UpAngleC",LstBar,LowValue,65);
DrawAngleLine("UpAngleD",LstBar,LowValue,85);
DrawAngleLine("DownAngleA",HstBar,HighValue,-25);
DrawAngleLine("DownAngleB",HstBar,HighValue,-45);
DrawAngleLine("DownAngleC",HstBar,HighValue,-65);
DrawAngleLine("DownAngleD",HstBar,HighValue,-85);
}
return(0);
}
Comments