missing label

 

Hello Forum

Just tried putting together an indicator to show Bid Ask Spread

All seems to work nicely EXCEPT, I don't know why my 2nd label is not appearing

I'll include a picture, but basically, the 1st Label works nicely and the Word "Ask sits above the shaded spread box

But the 2nd label is no where to be seen and I can't work out why

Assume it is something obvious, but I am yet to see it !!!

Would love someone to point out the error, thanks in Advance...


//+------------------------------------------------------------------+
//|                                                                  |
//|                 Copyright © 1999-2008, MetaQuotes Software Corp. |
//|                                         http://www.metaquotes.ru |
//+------------------------------------------------------------------+

//---- indicator settings

#property  indicator_chart_window
#property  indicator_buffers 0
//----

//---- indicator parameters

extern string          help                     = "bars forward positions Level Line";
extern double          bars_forward             = 1;      //Time[0] + numberOfSecondsIntoTheFuture is Time[0]+q*Period()*60; // q bars into the future
extern double          BoxLength                = 3;      // sets length of Level Line
extern double          LabelAdjHorizontal       = 2;      // positions label above or under shaded box depicting spread   
extern double          LabelAdjVertical         = 0.00005;
extern int             font_size                = 8;      // sets font size
extern string          help1                    = "set to true to show box";
extern bool            ShowBox                  = true;   // set true to display box
extern bool            ShowLabel                = true;   // set true to display label


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
   {
   IndicatorShortName("Bid-Ask Spread");
   
   
   //---- initialization done
   return(0);
   }    
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
   {
    ObjectDelete("Box");
    ObjectDelete("Box_label");
    ObjectDelete("Box_label2");         
   return(0);
   }
//+------------------------------------------------------------------+
//| Other timeframe line levels                                           |
//+------------------------------------------------------------------+
int start()
       
       {
       
//-
//-----Draw Box Rectangle");
//--
       if (ShowBox) // draw if true
       {
       if (ObjectFind   ("Box") == -1) 
           ObjectCreate ("Box", OBJ_RECTANGLE, 0, 0, 0, 0, 0);
         
           ObjectSet    ("Box", OBJPROP_TIME1,       Time[0] +             bars_forward * 60 * Period() );
           ObjectSet    ("Box", OBJPROP_TIME2,       Time[0] + BoxLength * bars_forward * 60 * Period() );
      
           ObjectSet    ("Box", OBJPROP_PRICE1,      Ask );
           ObjectSet    ("Box", OBJPROP_PRICE2,      Bid );
      
           ObjectSet    ("Box", OBJPROP_RAY,         false);
           ObjectSet    ("Box", OBJPROP_COLOR,       PeachPuff);
           ObjectSet    ("Box", OBJPROP_WIDTH,       3);
       }
  //-- Draw Box Label -----------------------------------------      
       if (ShowBox) // draw if true
       {
       if (ObjectFind   ("Box_label") == -1) 
           ObjectCreate ("Box_label", OBJ_TEXT, 0, 0, 0);
      
           ObjectSet    ("Box_label", OBJPROP_TIME1, Time[0] + LabelAdjHorizontal *bars_forward * 60 * Period() );
           ObjectSet    ("Box_label", OBJPROP_PRICE1, (Ask+LabelAdjVertical) );

           ObjectSet    ("Box_label", OBJPROP_COLOR, Black);
           ObjectSetText("Box_label", "Ask", font_size, "Arial", Black); 
       }
       
  //-- Draw Box Label2 -----------------------------------------      
       if (ShowBox) // draw if true
       {
       if (ObjectFind   ("Box_label2") == -1) 
           ObjectCreate ("Box_label2", OBJ_TEXT, 0, 0, 0);
      
           ObjectSet    ("Box_label2", OBJPROP_TIME1, Time[0] + LabelAdjHorizontal *bars_forward * 60 * Period() );
           ObjectSet    ("Box_label2", OBJPROP_PRICE2,( Bid-LabelAdjVertical) );

           ObjectSet    ("Box_label2", OBJPROP_COLOR, Black);
           ObjectSetText("Box_label2", "Bid", font_size, "Arial", Black); 
       }     
       
  
   //----
   return(0);
   }
//+------------------------------------------------------------------+
 
pullend:

Hello Forum

Just tried putting together an indicator to show Bid Ask Spread

All seems to work nicely EXCEPT, I don't know why my 2nd label is not appearing

I'll include a picture, but basically, the 1st Label works nicely and the Word "Ask sits above the shaded spread box

But the 2nd label is no where to be seen and I can't work out why

Assume it is something obvious, but I am yet to see it !!!

Would love someone to point out the error, thanks in Advance...


Maybe this . . .

ObjectSet    ("Box_label2",   OBJPROP_PRICE2,   ( Bid-LabelAdjVertical) );

  . . .  where is OBJPROP_PRICE1 ?

 
A tip,  when you have a missing Object check the list of Objects (Ctrl + B),  if you find it in the list double click it and check it's properties,  that should give you a clue as to what the problem is. 

 
RaptorUK:

Maybe this . . .

  . . .  where is OBJPROP_PRICE1 ?

 
A tip,  when you have a missing Object check the list of Objects (Ctrl + B),  if you find it in the list double click it and check it's properties,  that should give you a clue as to what the problem is. 


Thanks Raptor, annoyingly obvious AND

Thanks for the tip, will list with your other pearls of wisdom

Your tip just about better searching the code base (about a week or 2 back) is already saving me MUCH!!!! time

Thanks Again.

 
That's why you should never write code like that. Factor it. Create a function CreateText(string name, string lable, datetime time, double price){...}
Reason: