This script is designed to act as an automated visual aid for traders using the MetaTrader platform. Its primary function is to scan your current chart for manually placed horizontal lines and automatically calculate the distance between those lines and the current market price.
How it Works
Automated Detection The tool begins by scanning all the elements currently on your trading chart. It specifically looks for objects categorized as "Horizontal Lines." If the script detects that no such lines have been drawn, it will display a notice on the screen informing you of this.
Dynamic Calculations Once horizontal lines are identified, the script retrieves the exact price level of each line. It then performs a real-time calculation to determine the difference between that price level and the current closing price of the market.
Visual Feedback Instead of requiring you to do the math manually, the script generates a text label for every horizontal line found. These labels appear just above each line and display:
- The distance (in "points") from the current price.
- A clear, readable format using an orange font.
Chart Management To keep your workspace clean, the script includes a self-cleaning mechanism. Whenever the indicator is removed or the chart is refreshed, it automatically deletes the temporary labels it created, ensuring that no "ghost" text remains on your screen after the tool is turned off.
Summary for the User
In simple terms, this tool turns your static horizontal lines into dynamic information displays. It tells you exactly how far away the current price is from your marked levels in real-time, allowing for quicker decision-making without manual calculation.
#property copyright "neo"
#property link "http://www.metaquotes.net"
#property indicator_chart_window
int init()
{
return(0);
}
int deinit()
{
int j,count;
int objtot=ObjectsTotal();
for (j=objtot-1; j>=0; j--)
{
if(StringSubstr(ObjectName(j),0,4)=="illu" && ObjectType(ObjectName(j))==OBJ_TEXT) ObjectDelete(ObjectName(j));
//count--;
}
return(0);
}
int start()
{
double price1;
int j,count,k=0;
int objtot=ObjectsTotal();
string nameH[],null_string;
//----------------- filter out all horizontal lines
for (j=0; j<objtot; j++)
{
if(StringSubstr(ObjectName(j),0,9)=="Horizonta" && ObjectType(ObjectName(j))==OBJ_HLINE)
{
nameH[k]=ObjectName(j);
k ++;
}
}
if(k<1)
{
Comment("ÇëÌí¼ÓˮƽÏß !!! ");
return(0);
}
ArrayResize(nameH,k);
// Print("name0: "+nameH[0]+".....name1: "+nameH[1]);
for(j=0; j<k; j++)
{
price1=ObjectGet(nameH[j],OBJPROP_PRICE1);
ObjectCreate("illu"+nameH[j], OBJ_TEXT, 0,Time[WindowFirstVisibleBar()-15],price1+8*Point );
ObjectSetText("illu"+nameH[j],"¾àÀë: "+DoubleToStr(MathAbs(price1-Close[0])/Point,0),14,"Times New Roman",Orange);
}
return(0);
}
Comments