How do I put a text beside my horizontal line?

 
// Pivot Plus Add-On (Personal)
#property copyright "Copyright @ Malcolm"
#property link      "www.mql4.com"
#property version   "1.0"
#property description "Additional Pivot Points for more market opportunities"

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 4

#property indicator_type1 DRAW_LINE
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_color1 0x00BFFF
#property indicator_label1 "Yesterday's Low Pivot YLP"

#property indicator_type2 DRAW_LINE
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
#property indicator_color2 0x00BFFF
#property indicator_label2 "Yesterday's High Pivot YHP"

#property indicator_type3 DRAW_LINE
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
#property indicator_color3 0xFF00EE
#property indicator_label3 "Last Week's Low Pivot LWLP"

#property indicator_type4 DRAW_LINE
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
#property indicator_color4 0xFF00EE
#property indicator_label4 "Last Week's High Pivot LWHP"

//--- indicator buffers
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];

double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | Pivot Plus @ "+Symbol()+","+IntegerToString(Period())+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(4);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexBuffer(2, Buffer3);
   SetIndexEmptyValue(2, EMPTY_VALUE);
   SetIndexBuffer(3, Buffer4);
   SetIndexEmptyValue(3, EMPTY_VALUE);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   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[])
  {
   int limit = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   ArraySetAsSeries(Buffer3, true);
   ArraySetAsSeries(Buffer4, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, EMPTY_VALUE);
      ArrayInitialize(Buffer2, EMPTY_VALUE);
      ArrayInitialize(Buffer3, EMPTY_VALUE);
      ArrayInitialize(Buffer4, EMPTY_VALUE);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      
      int barshift_D1 = iBarShift(Symbol(), PERIOD_D1, Time[i]);
      if(barshift_D1 < 0) continue;
      int barshift_W1 = iBarShift(Symbol(), PERIOD_W1, Time[i]);
      if(barshift_W1 < 0) continue;
      
      //Indicator Buffer 1
      if(true //no conditions!
      )
        {
         Buffer1[i] = iLow(NULL, PERIOD_D1, 1+barshift_D1); //Set indicator value at Candlestick Low
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 2
      if(true //no conditions!
      )
        {
         Buffer2[i] = iHigh(NULL, PERIOD_D1, 1+barshift_D1); //Set indicator value at Candlestick High
        }
      else
        {
         Buffer2[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 3
      if(true //no conditions!
      )
        {
         Buffer3[i] = iLow(NULL, PERIOD_W1, 1+barshift_W1); //Set indicator value at Candlestick Low
        }
      else
        {
         Buffer3[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 4
      if(true //no conditions!
      )
        {
         Buffer4[i] = iHigh(NULL, PERIOD_W1, 1+barshift_W1); //Set indicator value at Candlestick High
        }
      else
        {
         Buffer4[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

Hi guys,


I've made a simple 'pivot point' that is an additional add-on to standard pivot points. This pivot point adds yesterday's low/high as well as the previous week's low/high.


Question and problem: How do I add a text box beside it that says 'YLP - 1.19049' (Stands for Yesterday's Low Pivot - Price of plotted line) etc.? An example of what I want and what I have is attached. (notmine.jpeg is what I want to achieve with the text)


I'll leave the MQL4 code here can anyone please help me out? Thanks!!! 

Files:
mine.jpeg  87 kb
notmine.jpeg  19 kb
 
malcolmlai_: To make it look more complete, how do I add a text box … please help me out?
  1. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum 2018.05.12

  2. Not such thing as a text box.

    Perhaps you should read the manual.
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

 
William Roeder:
  1. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum 2018.05.12

  2. Not such thing as a text box.

    Perhaps you should read the manual.
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

Well, I did state clearly to reference the images which you will be able to see what a text box is. And yes, I did state the problem (also referenced by comparing the two images, showing that it is the 'text' which i'm missing)...


There's a reason why i'm posting it on the forums and not paid MQL4 Freelance because the indicator is way too simple to be paid.

 
malcolmlai_:

Question and problem: How do I add a text box beside it that says 'YLP - 1.19049' (Stands for Yesterday's Low Pivot - Price of plotted line) etc.? An example of what I want and what I have is attached. (notmine.jpeg is what I want to achieve with the text)

Create an OBJ_TEXT for each line. These only need to be created once so create them in OnInit().

Use ObjectSetInteger() to set the time co-ordinate to Time[0] and also the anchor point to left.

Use ObjectSetString() to set the text

In OnCalculate check for a new bar and when there is a new bar

re-set the time  co-ordinate to Time[0]

check if the text needs to be changed

check if the price co-ordinate needs to be changed using ObjectSetDouble().


 
Keith Watford:

Create an OBJ_TEXT for each line. These only need to be created once so create them in OnInit().

Use ObjectSetInteger() to set the time co-ordinate to Time[0] and also the anchor point to left.

Use ObjectSetString() to set the text

In OnCalculate check for a new bar and when there is a new bar

re-set the time  co-ordinate to Time[0]

check if the text needs to be changed

check if the price co-ordinate needs to be changed using ObjectSetDouble().


Hey,

Thanks for helping out. I tried doing what you said but I was unsuccessful (i just started coding). Is it possible you paste it in my code to show me how it's done?

Much thanks!

 
malcolmlai_:

Hey,

Thanks for helping out. I tried doing what you said but I was unsuccessful (i just started coding). Is it possible you paste it in my code to show me how it's done?

Much thanks!

Show the code that you have done and I will tell you what you have done wrong.

You will learn by doing this.

If I just do the code for you, you will not learn.


Additional tip: Give your buffers (and variables) meaningful names, it will make your code easier to follow.

Buffer1 etc is meaningless. DayHighBuffer is meaningful.

 
Keith Watford:

Show the code that you have done and I will tell you what you have done wrong.

You will learn by doing this.

If I just do the code for you, you will not learn. No problem Keith, I've attached the code. I've added the OBJ_TEXT and ObjectSetString as a test but when compiling there were errors. If I can't even get that right I will have difficulties trying to add time.


It's surpassingly a very easy code? Hence why I left my code open to the public because anyone could do it haha. Just having big issues with the text. That way you know i'm trying to learn from you :)

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
// AS INDICATED TO PLACE IT UNDER ONINIT
int OnInit()
  {   
   IndicatorBuffers(4);
   SetIndexBuffer(0, Buffer1);
   
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexBuffer(1, Buffer2);
   //ADDED AND MODIFIED BELOW, BUT I AM REALLY CONFUSED CAUSE I'M STILL PRETTY NEW//
   OBJ_TEXT
   ObjectSetString("Hello")
   // ABOVE
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexBuffer(2, Buffer3);
   
   SetIndexEmptyValue(2, EMPTY_VALUE);
   SetIndexBuffer(3, Buffer4);
   
   SetIndexEmptyValue(3, EMPTY_VALUE);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }

 
malcolmlai_:

If I just do the code for you, you will not learn. No problem Keith, I've attached the code. I've added the OBJ_TEXT and ObjectSetString as a test but when compiling there were errors. If I can't even get that right I will have difficulties trying to add time.


It's surpassingly a very easy code? Hence why I left my code open to the public because anyone could do it haha. Just having big issues with the text. That way you know i'm trying to learn from you :)


Are you reading the documentation?

Read the documentation for ObjectCreate() and ObjectSetString()

 
Keith Watford:

Are you reading the documentation?

Read the documentation for ObjectCreate() and ObjectSetString()

I guess i'll go back to YouTube videos lol.


For anyone who will like to help with the code, feel free to do so!

 
malcolmlai_:

I guess i'll go back to YouTube videos lol.


For anyone who will like to help with the code, feel free to do so!

Increasing your knowledge will be very slow if you are not prepared to read the documentation.

 
Keith Watford:

Increasing your knowledge will be very slow if you are not prepared to read the documentation.

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
// AS INDICATED TO PLACE IT UNDER ONINIT
int OnInit()
  {   
   IndicatorBuffers(4);
   SetIndexBuffer(0, Buffer1);
   
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexBuffer(1, Buffer2);
   //Create the object
   ObjectCreate("Pivot", OBJ_TEXT,)
   //Set the time
   ObjectSetString("Pivot", ObjectSetInterger())
  
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexBuffer(2, Buffer3);
   
   SetIndexEmptyValue(2, EMPTY_VALUE);
   SetIndexBuffer(3, Buffer4);
   
   SetIndexEmptyValue(3, EMPTY_VALUE);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }


This is what I got out of the manual, still really boggled

Reason: