Indicator Miscellaneous Questions - page 11

 
Can you see my example code in this comment #99
 

Oh ok that code.

ObjectCreate() also needs the chart ID:

bool  ObjectCreate(
   long         chart_id,      // chart identifier
   string       name,          // object name
   ENUM_OBJECT  type,          // object type
   sub_window   nwin,          // window index
   datetime     time1,         // time of the first anchor point
   double       price1,        // price of the first anchor point
   ...
   datetime     timeN=0,       // time of the N-th anchor point
   double       priceN=0,      // price of the N-th anchor point
   ...
   datetime     time30=0,      // time of the 30th anchor point
   double       price30=0      // price of the 30th anchor point
   );

As the first parameter.

int OnInit()
  {
   Print("Outside");

   ObjectCreate("Object Outside",OBJ_LABEL,0,0,0);
   ObjectSetInteger(0,"Object Outside",OBJPROP_XDISTANCE,20);
   ObjectSetInteger(0,"Object Outside",OBJPROP_YDISTANCE,20);
   ObjectSetString(0,"Object Outside",OBJPROP_TEXT,"Outside");

   if(DayOfWeek()==5)
     {
      Print("Inside");

      ObjectCreate("Object Inside",OBJ_LABEL,0,0,0);
      ObjectSetInteger(0,"Object Inside",OBJPROP_XDISTANCE,20);
      ObjectSetInteger(0,"Object Inside",OBJPROP_YDISTANCE,40);
      ObjectSetString(0,"Object Inside",OBJPROP_TEXT,"Inside");
     }
  }

But you start with the objectname.

Also you can specify a base corner/anchor point.

Please see: https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_label

//+------------------------------------------------------------------+
//| Create a text label                                              |
//+------------------------------------------------------------------+
bool LabelCreate(const long              chart_ID=0,               // chart's ID
                 const string            name="Label",             // label name
                 const int               sub_window=0,             // subwindow index
                 const int               x=0,                      // X coordinate
                 const int               y=0,                      // Y coordinate
                 const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // chart corner for anchoring
                 const string            text="Label",             // text
                 const string            font="Arial",             // font
                 const int               font_size=10,             // font size
                 const color             clr=clrRed,               // color
                 const double            angle=0.0,                // text slope
                 const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type
                 const bool              back=false,               // in the background
                 const bool              selection=false,          // highlight to move
                 const bool              hidden=true,              // hidden in the object list
                 const long              z_order=0)                // priority for mouse click
  {
//--- reset the error value
   ResetLastError();
//--- create a text label
   if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))
     {
      Print(__FUNCTION__,
            ": failed to create text label! Error code = ",GetLastError());
      return(false);
     }
//--- set label coordinates
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set the chart's corner, relative to which point coordinates are defined
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set the text
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text font
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font size
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set the slope angle of the text
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- set anchor type
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- set color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- 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 label by mouse
   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);
  }
//+------------------------------------------------------------------+

Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_LABEL - Reference on algorithmic/automated trading language for MetaTrader 5
 

I am just worrying that I couldn't explained my issue that I want to ask did you tried it, please? Then you can know what is my problem with that code.

I just try like this - 1. I added my example file to the chart then I close MT4. 2. Open MT4 - then I do not see my Inside Label Object.

That's what I try to find solution to my issue. : /


Maybe I will be for sure Monday.

( when I think this is so easy I spend a lot of time for that easy things - when I think this is so hard that I did them so easily... - Almost all of what I want to do. first I try to read documentation... )

 

I tried it and there are two objects shown.

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
      Print("Outside");

   ObjectCreate(0,"Object Outside",OBJ_LABEL,0,0,0);
   ObjectSetInteger(0,"Object Outside",OBJPROP_XDISTANCE,20);
   ObjectSetInteger(0,"Object Outside",OBJPROP_YDISTANCE,20);
   ObjectSetString(0,"Object Outside",OBJPROP_TEXT,"Outside");

   if(DayOfWeek()==5)
     {
      Print("Inside");

      ObjectCreate(0,"Object Inside",OBJ_LABEL,0,0,0);
      ObjectSetInteger(0,"Object Inside",OBJPROP_XDISTANCE,20);
      ObjectSetInteger(0,"Object Inside",OBJPROP_YDISTANCE,40);
      ObjectSetString(0,"Object Inside",OBJPROP_TEXT,"Inside");
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+


 

Cool!

Look my screenshot, please.

there is a issue

Thanks a lot for your time Mr. Marco

 

I never mind that part of code will give me different result in Indicator. : /
I try that part of code in my Indicator File.

( I decided that I will write some code in indicator files just not in my Trade Panel file. )


2nd time edited

I already use your method - now it works without any issues, hope it will work.

Thanks a lot Mr. Marco


#Not Monday - Closed
 

#Refresh - Open

Once I solve my this issue - my indicator works good in my main MT4 platform - but I use 2nd MT4 platform which is my indicator needs refresh when I start MT4 platform.
I have no idea where that problem comes from... that I ask something exactly about that.

Q:  Can anyone let me something about this weird situation, please?

Thanks in advance.

 

You mean you witness different behavior between two platforms?

Are they the same build?

 
Marco vd Heijden:

You mean you witness different behavior between two platforms?

Are they the same build?

Yeah absolutely different behavior...

Also yes both of them 1065 Build

 

Maybe I found where comes those weird issues...

What a secret of load template?
There is mystical things, which is destroying me at all... that is really really making me mad at all... - I have already did huge things for my EA's and Indicator's that I never spent a lot of time like I am spending few minor issues...

How? Simple!

After I decided that I should not put some scripts in my EA's files - then I continuously facing minors issues that I can't find solution in SEO. ( actually sometimes I find easily solution to my huge EA's issues on SEO - but this minor issues. )

---

I put this simple code in my example indicator file.

int OnInit()
{
  Print( "This Year", Year() );
  return(INIT_SUCCEEDED);
}

When I try to load this example file to my chart. It does not work correctly until I change TimeFrame.
( it's possible I already tired today )
( also I know I can solve this issue if I put that code in OnCalculate(...) - but I just need to put that code in OnInit() )

Please, I just need more clearly explanation for this issue. I really need it, because few my indicators have same irrelevant issues. ( that if I put this in my EA's files it will work correctly )

Thanks in advance.
Have a nice weekend.

Reason: