How to show order type (Sell/Buy) on chart? - page 3

 
pro_:

If it works for you - fine. I am glad. But my view is that any indicator should be universal as much as possible, and not good for some specific situation only. You do it once but do it properly, so that if you need to change something or situation changes in terms of your positions it works correctly.

Anyway, you are welcome.

It won't work, you create the Object and then try to create it again on the next tick, this will fail . . . so if the first Order is a Buy and the second a Sell the text will not update from Buy to Sell.
 
As I said before there are A LOT of mistakes in the code. I was hoping the asker will work on it himself and understand the coding a bit more. That seems not to be his intention. And unfortunately I have no time to write the code for him. I just gave him something to start working, not a finished product.
 
RaptorUK:
It won't work, you create the Object and then try to create it again on the next tick, this will fail . . . so if the first Order is a Buy and the second a Sell the text will not update from Buy to Sell.


It works, but just show the last order. I don't know how to change it for current order!
 

I don;t know if it is good practice or not, but I create the labels in init() and ObjectSetText just with a "."

I haven't figured out how to place a label with totally empty text yet. If I try it comes up with the text"Label"

Of course that is fine as long as you know how many labels you will need.

I guess that it shouldn't be too difficult to delete excess labels and add new labels when required in the main body.

This is the code that I use in init() to create the labels

int y=20;
for(int x=1;x<=10;x++)
{
ObjectCreate("Message"+x, OBJ_LABEL, 0, 0, 0);// Creating obj.
   ObjectSet("Message"+x, OBJPROP_CORNER, 1);    // Reference corner
   ObjectSet("Message"+x, OBJPROP_XDISTANCE, 10);// X coordinate
   ObjectSet("Message"+x, OBJPROP_YDISTANCE, y);// Y coordinate
   ObjectSetText("Message"+x,".",8,"Arial",CLR_NONE);  // Empty Labels
   y=y+15;
 

Oh. and in deinit()

for(int x=1;x<=10;x++)
 {
 ObjectDelete("Message"+x) ;   
 }
 
Konnj:

It works, but just show the last order. I don't know how to change it for current order!
Post your latest code . . .
 
{
   int    counted_bars=IndicatorCounted();
   int pos;
   string OrderTip = "OT";
   string ottt;
   color LabelColor3;

       for(int i=0;i<OrdersTotal();i++)
                    {
                     if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
                     if(OrderSymbol()==Symbol() )
                       {
                        if(OrderType()==OP_BUY)  pos++;
                        if(OrderType()==OP_SELL) pos++;
                       }
                    }            
                    
      if (OrderType()==OP_BUY) { ottt="Buy";  LabelColor3 = DodgerBlue; } 
      if (OrderType()==OP_SELL){ ottt="Sell"; LabelColor3 = Red; }
      else ottt="";
     
      ObjectCreate(OrderTip, OBJ_LABEL, 0 , 0, 0, 0);
      ObjectSet(OrderTip, OBJPROP_CORNER, 1);
      ObjectSet(OrderTip, OBJPROP_XDISTANCE, 10);
      ObjectSet(OrderTip, OBJPROP_YDISTANCE, 15);
      ObjectSetText(OrderTip, "Order Type: "+ottt, 8, "Tahoma",LabelColor3);
}
 
Konnj:

I meant the whole code . . . but never mind . . . try these changes.

{
   int    counted_bars=IndicatorCounted();
   int pos;
   string OrderTip = "OT";
   string ottt = " ";
   color LabelColor3 = Black;

   for(int i=0;i<OrdersTotal();i++)
      {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() )
         {
         if (OrderType() == OP_BUY) { ottt = "Buy";  LabelColor3 = DodgerBlue; } 
         if (OrderType() == OP_SELL){ ottt = "Sell"; LabelColor3 = Red; }
         }
      }            
     
   if (ObjectFind(OrderTip) < 0) ObjectCreate(OrderTip, OBJ_LABEL, 0 , 0, 0, 0);

   ObjectSet(OrderTip, OBJPROP_CORNER, 1);
   ObjectSet(OrderTip, OBJPROP_XDISTANCE, 10);
   ObjectSet(OrderTip, OBJPROP_YDISTANCE, 15);
   ObjectSetText(OrderTip, "Order Type: "+ottt, 8, "Tahoma",LabelColor3);
}
 
It's working right now, Thank you very much.
 

Please do not post queries that have nothing to do with this very old thread

I have reposted your query

https://forum.mql4.com/72256