I need an help with this monitor

 

Hi all, could you indicate the mistakes in this indicator monitor?

I'm trying to write this indicator to monitor the global variables in my expert, but I don't find the errors...

Thank you!


#property indicator_chart_window

extern int mCorn = 0, mTextSize = 10;
extern color mTextCol = White ;
extern int shift = 20 ;

//-----------------------------------------------+

int start()
 {

 }

//-----------------------------------------------+
void CreateLabels()
 { 

int total = OrdersTotal();

 for(int cnt=0;cnt<=total;cnt++)
     {
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) ; 
     
     int ticket = OrderTicket() ; 
     int magic  = OrderMagicNumber() ;         
                    
       int a = 1 + cnt ;
       int z = 40 + cnt * shift ;      
       ObjectCreate("a", OBJ_LABEL, 0, 0, 0, 0);
       ObjectSet("a", OBJPROP_CORNER, mCorn);
       ObjectSet("a", OBJPROP_XDISTANCE, 10);
       ObjectSet("a", OBJPROP_YDISTANCE, z );        
       ObjectSetInteger("a",ticket,mTextSize, "Verdana", mTextCol );
       
       int b = 2 + cnt ;      
       ObjectCreate("b", OBJ_LABEL, 0, 0, 0, 0);
       ObjectSet("b", OBJPROP_CORNER, mCorn);
       ObjectSet("b", OBJPROP_XDISTANCE, 30);
       ObjectSet("b", OBJPROP_YDISTANCE, z );        
       ObjectSetText("b",OrderSymbol(), mTextSize, "Verdana", mTextCol );
       
       int c = 3 + cnt ;       
       ObjectCreate(c, OBJ_LABEL, 0, 0, 0, 0);
       ObjectSet(c, OBJPROP_CORNER, mCorn);
       ObjectSet(c, OBJPROP_XDISTANCE, 50);
       ObjectSet(c, OBJPROP_YDISTANCE, z );        
       ObjectSetInteger(c,magic,"Verdana", mTextCol );
       
       int d = 4 + cnt ;      
       ObjectCreate(d, OBJ_LABEL, 0, 0, 0, 0);
       ObjectSet(d, OBJPROP_CORNER, mCorn);
       ObjectSet(d, OBJPROP_XDISTANCE, 70);
       ObjectSet(d, OBJPROP_YDISTANCE, 40 );        
       ObjectSetInteger(d,Bars,mTextSize, "Verdana", mTextCol );
       
       int e = 5 + cnt ;      
       ObjectCreate(e, OBJ_LABEL, 0, 0, 0, 0);
       ObjectSet(e, OBJPROP_CORNER, mCorn);
       ObjectSet(e, OBJPROP_XDISTANCE, 90);
       ObjectSet(e, OBJPROP_YDISTANCE, z ); 
       
       if(OrderType()==OP_BUY && OrderMagicNumber()==1)
         {       
         ObjectSetText(e,GlobalVariableGet(StringConcatenate("Barre_Long_1_",OrderTicket(),1)), mTextSize, "Verdana", mTextCol );
         }  
       if(OrderType()==OP_BUY && OrderMagicNumber()==2)
         {       
         ObjectSetText(e,GlobalVariableGet(StringConcatenate("Barre_Long_2_",OrderTicket(),2)), mTextSize, "Verdana", mTextCol );
         } 
       if(OrderType()==OP_SELL && OrderMagicNumber()==1)
         {       
         ObjectSetText(e,GlobalVariableGet(StringConcatenate("Barre_Short_1_",OrderTicket(),1)), mTextSize, "Verdana", mTextCol );
         } 
       if(OrderType()==OP_SELL && OrderMagicNumber()==2)
         {       
         ObjectSetText(e,GlobalVariableGet(StringConcatenate("Barre_Short_2_",OrderTicket(),2)), mTextSize, "Verdana", mTextCol );
         } 
             
       int f = 6 + cnt ;           
       ObjectCreate(f, OBJ_LABEL, 0, 0, 0, 0);
       ObjectSet(f, OBJPROP_CORNER, mCorn);
       ObjectSet(f, OBJPROP_XDISTANCE, 110);
       ObjectSet(f, OBJPROP_YDISTANCE, z ); 
       if(OrderType()==OP_BUY || OrderType()==OP_BUYSTOP) 
         {       
         ObjectSetDouble(f,GlobalVariableGet(StringConcatenate("Take_Profit_Long_1_",OrderTicket() )) , mTextSize, "Verdana", mTextCol  );
         }         
       if(OrderType()==OP_SELL || OrderType()==OP_SELLSTOP) 
         {       
         ObjectSetDouble(f,GlobalVariableGet(StringConcatenate("Take_Profit_Short_1_",OrderTicket() )) , mTextSize, "Verdana", mTextCol );
         }     

       int g = 7 + cnt ;      
       ObjectCreate(g, OBJ_LABEL, 0, 0, 0, 0);
       ObjectSet(g, OBJPROP_CORNER, mCorn);
       ObjectSet(g, OBJPROP_XDISTANCE, 130);
       ObjectSet(g, OBJPROP_YDISTANCE, z );        
       if(OrderType()==OP_BUY || OrderType()==OP_BUYSTOP) 
         {       
         ObjectSetText(g,GlobalVariableGet(StringConcatenate("Take_Profit_Long_2_",OrderTicket() )) , mTextSize, "Verdana", mTextCol  );
         }         
       if(OrderType()==OP_SELL || OrderType()==OP_SELLSTOP) 
         {       
         ObjectSetText(g,GlobalVariableGet(StringConcatenate("Take_Profit_Short_2_",OrderTicket() )) , mTextSize, "Verdana", mTextCol );
         }        
     
     }
 
 }
 

Your code didn't call any function :

int start()
 {

 }

You should write this code inside start() function :

int start()
 {
  CreateLabels();
 }
 
Biantoro Kunarto:

Your code didn't call any function :

You should write this code inside start() function :


Thank you!

 
Alberto Tortella:

Thank you!

You're welcome 
 
Biantoro Kunarto: You should write this code inside start() function :
Start using the new Event Handling Functions.
          Event Handling Functions - Functions - Language Basics - MQL4 Reference
 

Ok now my monitor works better.

I wrote the following code to delete the objects related to the closed orders, but it does not work well. Could you help me? Thank you!

void DeleteLabels()
 { 
 int obj_total=ObjectsTotal();
     
     for(int ww=obj_total-1;ww>(OrdersTotal()+1)*9;ww--)
     {
     string name=ObjectName(ww);
     ObjectDelete(name);
     }
 }

In the first rows I see the market ticket and it's ok.

Then I see the closed orders, but I don't want to see them.

Files:
Prova_3_r1g.mq4  11 kb
 
int total = OrdersTotal();

 for(int cnt=0;cnt<=total;cnt++){
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) ;
                    
       int a = 1 + cnt ;
       ObjectCreate("a", OBJ_LABEL, 0, 0, 0, 0);
  1. If there are total orders, their positions are zero to total orders minus one. Your last select always fails but since you don't check everything after that is BOGUS. Check your return codes for errors and report them.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  2. You are creating object using position as a name. As older orders get closed, position indexes change. You can't create new objects with the same old names. Don't use non-unique names (position,) use ticket.