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

Back to topics list  | 1 2 3 To post a new topic, please log in or register
avatar
14167
RaptorUK 2013.07.31 10:31 #
 
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.

 
avatar
321
pro_ 2013.07.31 10:40 #
 
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.
 
avatar
33
Konnj 2013.07.31 10:50 #
 
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!
 
avatar
Moderator
3419
GumRai 2013.07.31 13:00 #
 

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;

 
avatar
Moderator
3419
GumRai 2013.07.31 13:02 #
 

Oh. and in deinit()

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

avatar
14167
RaptorUK 2013.07.31 13:41 #
 
Konnj:

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

avatar
33
Konnj 2013.07.31 13:50 #
 
{
   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);
}

avatar
14167
RaptorUK 2013.07.31 14:18 #
 
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);
}

avatar
33
Konnj 2013.07.31 14:46 #
 
It's working right now, Thank you very much.
avatar
Moderator
3419
GumRai 2016.04.17 13:00 #
 

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

Back to topics list   | 1 2 3  

To add comments, please log in or register