4 Warning message (Variables)

 

I got 4 warning messages in variables.


I want extern for Time into object rectangle


Here code:

//+------------------------------------------------------------------+
//|                                                squarecomment.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

extern datetime StartTime;
extern datetime EndTime;

int OnInit()
  {
//--- indicator buffers mapping


//---------------------------RECTANGLE---------------
ChartSetInteger(ChartID(),CHART_FOREGROUND,0,false);
ObjectCreate(ChartID(),"obj_rect",OBJ_RECTANGLE_LABEL,0,0,0);
ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_XDISTANCE,0);
ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_YDISTANCE,15);
ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_BACK,false);
ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_XSIZE,300);
ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_YSIZE,100);
//---------------------------END OF RECTANGLE---------



string time1sttext = "Start Time is ",StartTime; // Name of Object for color comment
string time2ndtext = "End Time is ",EndTime; // Name of Object for color comment

string str1stText = "Start Time is "; //String Const or Variable used on ObjectCreate
string str2ndText = "End Time is "; //String Const or Variable used on ObjectCreate

   // Create text object with given name

   ObjectCreate(time1sttext, OBJ_LABEL, 0, 0, 0, 0); // Type of Object Label = COMMENT OBJ_LABEL
   ObjectCreate(time2ndtext, OBJ_LABEL, 0, 0, 0, 0); // Type of Object Label = COMMENT OBJ_LABEL

   // Set pixel co-ordinates from top left corner (use OBJPROP_CORNER to set a different corner)

   ObjectSet(time1sttext, OBJPROP_XDISTANCE, 20);
   ObjectSet(time1sttext, OBJPROP_YDISTANCE, 50);
   
   ObjectSet(time2ndtext, OBJPROP_XDISTANCE, 20);
   ObjectSet(time2ndtext, OBJPROP_YDISTANCE, 70);   

   // Set text, font, and colour for object

   ObjectSetText(time1sttext, str1stText, 10, "Arial", clrBlack);
   ObjectSetText(time2ndtext, str2ndText, 10, "Arial", clrRed);
   
 


//---
   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[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
What are the warnings?
 
Keith Watford:
What are the warnings?
   see previous declaration of 'StartTime' squarecomment.mq4 15 17
declaration of 'EndTime' hides global variable squarecomment.mq4 36 37
   see previous declaration of 'EndTime' squarecomment.mq4 16 17
variable 'StartTime' not used squarecomment.mq4 35 39
variable 'EndTime' not used squarecomment.mq4 36 37
0 errors, 4 warnings, 223 msec elapsed 1 5

 
string time1sttext = "Start Time is " + TimeToString(StartTime); // Name of Object for color comment
string time2ndtext = "End Time is " + TimeToString(EndTime); // Name of Object for color comment
 
Marco vd Heijden:

Thank you very much... I never think of + TimeToString...

Solved. Closed case. 

Thank

 

You also have optional keys you can specify.

TIME_DATE    //gets result as "yyyy.mm.dd"
TIME_MINUTES //gets result as "hh:mi"
TIME_SECONDS //gets results as "hh:mi:ss"
 
Marco vd Heijden:

You also have optional keys you can specify.

noted, I will try this later. Thank

Reason: