cm_trend_info

Download script
Author: Copyright 2014, cmillion@narod.ru
cm_trend_info

This script is designed to enhance your trading chart by automatically calculating and displaying the price distance of any trend lines you draw. Instead of having to manually calculate the difference between two points on a trend line, this tool does the math for you in real-time.

How it Works

The logic follows a simple three-step process every time the market updates or the chart refreshes:

  1. Detection: The script constantly scans your active trading chart to identify any "Trend" objects (trend lines) that you have placed manually.
  2. Calculation: Once it finds a trend line, it looks at the starting price and the ending price of that specific line. It calculates the vertical difference between these two points to determine exactly how many price pips or points the trend covers.
  3. Labeling: The script then automatically generates a text label on your chart. This label is placed right at the starting point of the trend line and displays the calculated distance (e.g., "Trend 50p.").

Key Features for the User

  • Automatic Updates: You do not need to trigger the script manually; it monitors the objects on your screen dynamically.
  • Visual Consistency: The generated text automatically matches the color of the trend line you drew, ensuring the chart remains clean and easy to read.
  • Hidden Organization: To keep your workspace uncluttered, the labels are set to be "hidden" from the main object list, so they won't interfere with your ability to click on and move your primary trend lines.

In short, this tool acts as a personal assistant that automatically measures the "reach" of your trend lines, providing you with instant data on price movement without requiring manual calculations.

11 Views
0 Downloads
0 Favorites
cm_trend_info
//+------------------------------------------------------------------+
//|                                                cm trend info.mq4 |
//|                                Copyright 2014, cmillion@narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, cmillion@narod.ru"
#property link      "cmillion@narod.ru"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   for(int j=0; j<ObjectsTotal(); j++)
     {
      string name=ObjectName(j);
      if(ObjectType(name)!=OBJ_TREND) continue;
      datetime t1=(datetime)ObjectGet(name,OBJPROP_TIME1);
      double p1=ObjectGet(name,OBJPROP_PRICE1);
      string txt=StringConcatenate(" Trend ",DoubleToStr((p1-ObjectGet(name,OBJPROP_PRICE2))/Point,0),"p.");

      color c=(color)ObjectGet(name,OBJPROP_COLOR);
      name=StringConcatenate(name," t");
      ObjectDelete(0,name);
      TextCreate(0,name,0,t1,p1,txt,"Arial",8,c);
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool TextCreate(const long              chart_ID=0,               // ID ãðàôèêà
                const string            name="Text",              // èìÿ îáúåêòà
                const int               sub_window=0,             // íîìåð ïîäîêíà
                datetime                time=0,                   // âðåìÿ òî÷êè ïðèâÿçêè
                double                  price=0,                  // öåíà òî÷êè ïðèâÿçêè
                const string            text="Text",              // ñàì òåêñò
                const string            font="Arial",             // øðèôò
                const int               font_size=10,             // ðàçìåð øðèôòà
                const color             clr=clrRed,               // öâåò
                const double            angle=0.0,                // íàêëîí òåêñòà
                const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // ñïîñîá ïðèâÿçêè
                const bool              back=false,               // íà çàäíåì ïëàíå
                const bool              selection=false,          // âûäåëèòü äëÿ ïåðåìåùåíèé
                const bool              hidden=true,              // ñêðûò â ñïèñêå îáúåêòîâ
                const long              z_order=0)                // ïðèîðèòåò íà íàæàòèå ìûøüþ
  {
   ResetLastError();
   if(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price))
     {
      Print(__FUNCTION__,
            ": íå óäàëîñü ñîçäàòü îáúåêò \"Òåêñò\"! Êîä îøèáêè = ",GetLastError());
      return(false);
     }
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
   return(true);
  }
//+------------------------------------------------------------------+

Comments