Download MetaTrader 5
To add comments, please log in or register
Download documentation as one file. It is easy!
WhiteEagle
25
WhiteEagle 2014.05.01 00:21 

I've modified the code found here - https://docs.mql4.com/constants/objectconstants/enum_object/obj_hline

And, I've successfully increased the width of the horizontal line to 20

USDCAD showing "width=20" HLINE

I can move it where I wish on the chart. I'm trying to create horizontal lines at the places where Market Profile shows Value, etc.

My problem is that I cannot create more than one object with the following code:

#property strict
//--- description
#property description "Script draws \"Horizontal Line\" graphical object."
#property description "Anchor point price is set in percentage of the height of"
#property description "the chart window."
//--- display window of the input parameters during the script's launch
#property script_show_inputs
//--- input parameters of the script
input string          InpName="HLine";     // Line name
input int             InpPrice=25;         // Line price, %
input color           InpColor=clrMagenta;     // Line color
input ENUM_LINE_STYLE InpStyle=STYLE_SOLID; // Line style
input int             InpWidth=20;          // Line width
input bool            InpBack=false;       // Background line
input bool            InpSelection=true;   // Highlight to move
input bool            InpHidden=true;      // Hidden in the object list
input long            InpZOrder=0;         // Priority for mouse click
//+------------------------------------------------------------------+
//| Create the horizontal line                                       |
//+------------------------------------------------------------------+
bool HLineCreate(const long            chart_ID=0,        // chart's ID
                 const string          name="HLine",      // line name
                 const int             sub_window=0,      // subwindow index
                 double                price=0,           // line price
                 const color           clr=clrMagenta,        // line color
                 const ENUM_LINE_STYLE style=STYLE_SOLID, // line style
                 const int             width=20,           // line width
                 const bool            back=false,        // in the background
                 const bool            selection=true,    // highlight to move
                 const bool            hidden=true,       // hidden in the object list
                 const long            z_order=0)         // priority for mouse click
  {
//--- create a horizontal line
   if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price))
     {
      Print(__FUNCTION__,
            ": failed to create a horizontal line! Error code = ",GetLastError());
      return(false);
     }
//--- set line color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set line display style
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set line width
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the line by mouse
//--- when creating a graphical object using ObjectCreate function, the object cannot be
//--- highlighted and moved by default. Inside this method, selection parameter
//--- is true by default making it possible to highlight and move the object
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- check correctness of the input parameters
   if(InpPrice<0 || InpPrice>100)
     {
      Print("Error! Incorrect values of input parameters!");
      return;
     }
//--- price array size
   int accuracy=1000;
//--- array for storing the price values to be used
//--- for setting and changing line anchor point's coordinates
   double price[];
//--- memory allocation
   ArrayResize(price,accuracy);
//--- fill the array of prices
//--- find the highest and lowest values of the chart
   double max_price=ChartGetDouble(0,CHART_PRICE_MAX);
   double min_price=ChartGetDouble(0,CHART_PRICE_MIN);
//--- define a change step of a price and fill the array
   double step=(max_price-min_price)/accuracy;
   for(int i=0;i<accuracy;i++)
      price[i]=min_price+i*step;
//--- define points for drawing the line
   int p=InpPrice*(accuracy-1)/100;
//--- create a horizontal line
   if(!HLineCreate(0,InpName,0,price[p],InpColor,InpStyle,InpWidth,InpBack,
      InpSelection,InpHidden,InpZOrder))
     {
      return;
     }
//--- redraw the chart and wait for 1 second
   ChartRedraw();
   Sleep(1000);
  }

Any suggestions? How can I edit my code to allow more than one HLINE to be created? Thanks (I'm sure it's a simple problem)

FYI - My chart is an M5 chart using GMMA Long, GMMA Short, i-Sessions, Pivot Points - Shifted and Market Profile (EarnForex)

Keith Watford
Moderator
8014
Keith Watford 2014.05.01 00:43  
input string          InpName="HLine";     // Line name
input string          InpName2="HLine2";     // Line name
//
//
//
if(!HLineCreate(0,InpName,0,price[p],InpColor,InpStyle,InpWidth,InpBack,
      InpSelection,InpHidden,InpZOrder))
//
//
if(!HLineCreate(0,InpName2,0,price[p],InpColor,InpStyle,InpWidth,InpBack,
      InpSelection,InpHidden,InpZOrder))
WhiteEagle
25
WhiteEagle 2014.05.01 08:39  

ok, I see it . . . thanks

Now, is there a way to make it an indefinite number of extra "HLine" entries (maybe changing the "name" input)?

Sorry to be so ignorant, but I'm learning bit by bit. I've modified all of the extensions I used, and I search for appropriate code snippets.

Tjipke de Vries
6283
Tjipke de Vries 2014.05.01 10:37  
whiteEagle:

ok, I see it . . . thanks

Now, is there a way to make it an indefinite number of extra "HLine" entries (maybe changing the "name" input)?

Sorry to be so ignorant, but I'm learning bit by bit. I've modified all of the extensions I used, and I search for appropriate code snippets.



input string          InpName="HLine"+TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES);     // Line name

you only need to name it differently you can use a number, time, price,....

but be sure it is unique and simple to use in your program

WhiteEagle
25
WhiteEagle 2014.05.01 14:11  

ok, thanks . . .

I'll work on that and let you know my success! I'm sure it will work (I can tell by the snippets you both wrote)

You guys (and gals) have been great!

That line . . .

input string          InpName="HLine"+TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES);     // Line name

. . . gives me an error . . .

'CreateLevels.mq4'
'+'-constant expected           CreateLevels.mq4        9       38
1 error(s), 0 warning(s)

Tjipke de Vries
6283
Tjipke de Vries 2014.05.01 16:35  
whiteEagle:

ok, thanks . . .

I'll work on that and let you know my success! I'm sure it will work (I can tell by the snippets you both wrote)

You guys (and gals) have been great!

That line . . .

. . . gives me an error . . .



sorry, was only concentrating on changing objectname didn't look that quick to 'input' and where it was defined

input string          InpName="HLine";     // Line name


void OnStart()
  {
//--- check correctness of the input parameters
string          InpName="HLine"+TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES);     // Line nam

if you do it this way it works

WhiteEagle
25
WhiteEagle 2014.05.01 17:00  

hmm . . .

It gives me one warning . . .

declaration of 'InpName' hides global declaration at line 9     CreateLevels.mq4        67      16

. . . which I understand (not a problem)

And, it allows me to put two (2) lines on the chart, and after "Compile" and "Save as," a second or third time, it allows me to put two more lines.

It needs to be "re-saved" several times before I can put more lines on the chart. I'm wanting to place lines on the chart over a period of time and keep them there.

The lines represent levels of "buy/sell" orders! I'm trying to use Market Profile to identify "liquidity levels" but I want a "band" and not a "fat" line.

I've tried modifying "ChartObjectLines" to get a "fatter" line, but all I can get is "width=5"

//+------------------------------------------------------------------+
//| Class CChartObjectTrend.                                         |
//| Purpose: Class of the "Trendline" object of chart.               |
//|          Derives from class CChartObject.                        |
//| It is the parent class for all objects that have properties      |
//| RAY_LEFT and RAY_RIGHT.                                          |
//+------------------------------------------------------------------+
class CChartObjectTrend : public CChartObject
  {
public:
                     CChartObjectTrend(void);
                    ~CChartObjectTrend(void);
   //--- methods of access to properties of the object
   bool              RayLeft(void) const;
   bool              RayLeft(const bool new_sel) const;
   bool              RayRight(void) const;
   bool              RayRight(const bool new_sel) const;
   //--- method of creating the object
   bool              Create(long chart_id,const string name,const int window,
                            const datetime time1,const double price1,
                            const datetime time2,const double price2,
                            const ENUM_LINE_STYLE style=STYLE_SOLID,const int width=20,
                            const bool back=false,const bool selection=true,
                            const bool hidden=true,const long z_order=0);
   //--- method of identifying the object
   virtual int       Type(void) const { return(OBJ_TREND); }
   //--- methods for working with files
   virtual bool      Save(const int file_handle);
   virtual bool      Load(const int file_handle);
  };
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CChartObjectTrend::CChartObjectTrend(void)
  {
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CChartObjectTrend::~CChartObjectTrend(void)
  {
  }
//+------------------------------------------------------------------+
//| Create object "Trendline"                                        |
//+------------------------------------------------------------------+
bool CChartObjectTrend::Create(long chart_id,const string name,const int window,
                               const datetime time1,const double price1,
                               const datetime time2,const double price2,
                               const ENUM_LINE_STYLE style=STYLE_SOLID,const int width=20,
                               const bool back=false,const bool selection=true,
                               const bool hidden=true,const long z_order=0)
  {
   if(!ObjectCreate(chart_id,name,OBJ_TREND,window,time1,price1,time2,price2))
      return(false);
   if(!Attach(chart_id,name,window,2))
      return(false);
//--- successful
   return(true);
  }

It's a different approach to the same problem - "How to put a horizontal line with more width on the chart"

I appreciate your attention to the problem! What you gave me works but only to a point (and, I'll keep working on it)

I'm working on the theory that "Market Profile" gives me the prices at which "buy/sell" orders occur, and the "fat" lines represent "liquidity" levels.

WhiteEagle
25
WhiteEagle 2014.05.02 16:13  

Problem Solved! Thanks!

I found that the 2nd solution to my problem (i.e., modifying "ChartObjectLines") gave lines that were not always straight (especially, in the future)

So, I returned to the solutions given me above. The first . . .

input string          InpName="HLine";     // Line name
input string          InpName2="HLine2";     // Line name
//
//
//
if(!HLineCreate(0,InpName,0,price[p],InpColor,InpStyle,InpWidth,InpBack,
      InpSelection,InpHidden,InpZOrder))
//
//
if(!HLineCreate(0,InpName2,0,price[p],InpColor,InpStyle,InpWidth,InpBack,
      InpSelection,InpHidden,InpZOrder))

. . . meant I'd have to multiply the "names" indefinitely. Thanks, GumRai, but it wasn't the final solution.

The second . . .

input string          InpName="HLine";     // Line name


void OnStart()
  {
//--- check correctness of the input parametersth
string          InpName="HLine"+TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES);     // Line name

. . . worked when placed in the proper area. Thanks, deVries, but I found it needed an additional value . . .

input string          InpName="HLine";     // Line name


void OnStart()
  {
//--- check correctness of the input parameters
string          InpName="HLine"+TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS);     // Line name

Once I understood what was happening, I saw that I could "add" two "HLines" when Price advanced by MINUTES, and when I added SECONDS, I could "add" indiscriminately.

Thanks, guys (and gals), for the help! I have it "how" I wanted it.

usdcad

The "Goldenrod" horizontal lines represent the "Daily H/L" The "Teal" band represents "Value" in "Market Profile," and the "Blue" bands represent "Liquidity" levels.

I'm trying to follow the strategy of "prop trader" Ray DeMedici trading out of London.

Yogesh
3
Yogesh 2014.10.22 14:58  

Hi whiteEagle,

            Looks very impressive !!! How is indicator working for you? Can you share the full source code please?

Thanks,

Vaikay 

/
To add comments, please log in or register