Download MetaTrader 5

Show text object

To add comments, please log in or register
Michael
718
Michael  

Can someone tell me why this text object doesn't appear on the chart?  It shows in the object list.

//+------------------------------------------------------------------+
//|                                                    TestChart.mq4 |
//|                                                 Nondisclosure007 |
//|                                               http://no.link.yet |
//+------------------------------------------------------------------+
#property copyright "Nondisclosure007"
#property link      "http://no.link.yet"
#property version   "1.00"
#property strict
#property indicator_chart_window

#include <ChartObjects\ChartObjectsTxtControls.mqh>
CChartObjectText myTxt;

string Txt;
bool IsInit;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   IsInit=true;
   Txt="Hello World!";
//---
   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[])
  {
//---
   if(!IsInit)
     {
      myTxt.SetPoint(0,Time[0],(High[0]-Low[0])/2);
      myTxt.SetString(OBJPROP_TEXT,Txt);
     }
   if(IsInit)
     {
      //myTxt.Delete();
      myTxt.Create(0,StringConcatenate(Symbol(),"_myTxt"),0,Time[0],(High[0]-Low[0])/2);
      myTxt.Color(clrWhite); 
      myTxt.Font("Arial");
      myTxt.FontSize(11);
      myTxt.Background(false);
      myTxt.SetString(OBJPROP_TEXT,Txt);
      myTxt.Hidden(false);
      IsInit=false;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Keith Watford
Moderator
10645
Keith Watford  

I don't use the mqh so I can't be sure but I would think that the price level will be close to zero, therefore not showing in the chart window.

myTxt.Create(0,StringConcatenate(Symbol(),"_myTxt"),0,Time[0],(High[0]-Low[0])/2)
Michael
718
Michael  
Keith Watford:

I don't use the mqh so I can't be sure but I would think that the price level will be close to zero, therefore not showing in the chart window.

Thanks.  That's just a price coordinate.  The object only has 1 point, price and time.
Keith Watford
Moderator
10645
Keith Watford  
Michael:
Thanks.  That's just a price coordinate.  The object only has 1 point, price and time.


You are missing the point.

If the price co-ordinate is lower than the lowest price on the chart, you will not be able to see it.

Think about what price co-ordinate you want as I am sure that you do not want High[0]-Low[0])/2 maybe you want High[0]+Low[0])/2 ?

Irwan Adnan
925
Irwan Adnan  
Press Ctrl+B, then select your object and then clik Edit on the right menu. It will pop up your object properties. Choose Parameters Tab then you can see object time and price. I guess they are beyond your screen. Thx.
Michael
718
Michael  
Thanks everyone.  You were all right.  It was off the chart.
To add comments, please log in or register