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

 
Konnj:
What about Ticket chart type?
You mean Order Type ?
 
RaptorUK:

Did you select the correct Order first ?

I'm not sure how to select it!


Also . . . Object DeleteAll() is lazy, don't use it . . .

I'm working on it.


haven't I said that twice already ?

Yes, you did. I'm sorry. :(
 
RaptorUK:
You mean Order Type ?


Correct.
 
Konnj:

Correct.
OK, you confused the situation when you said . . . "charts type"
 
RaptorUK:

Did you select the correct Order first ?


How can I do it please?
 
Konnj:

How can I do it please?

You already do it in this code . . .

int CalculateCurrentOrders()
  {
                  int pos=0;

                  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++;
                       }
                    }
              
                return(pos);
  }

. . . just make sure you have selected the correct Order, if one exists before you try to use OrderType, or get the typee in that function.

 

I tried every things, but I can't!!

Dear RaptorUK, you have my complete codes, just tell me what shall I do please!

Best Regards

 

This code should work. It uses your definitions, and coding. I have to warn you that you have to work on it to make sure it works properly in ALL cases.

I did some of that (check for OrderType OP_SELL separately, else is not the best way to go since there are other order types). There are many things that have to be added for it to be a good tool. For example, now it will only show the type of the last order if you have more than one, it will not disappear when there are no positions, etc.

So take it from here and work on it. It will be a good start for learning MQL.

int start()
  {
   int    counted_bars=IndicatorCounted();
   int pos;
   string OrderTyp = "OT";
   string ot;
   color LabelColor;
//----
                  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) { ot="Buy";  LabelColor = DodgerBlue; }
      if (OrderType()==OP_SELL){ ot="Sell"; LabelColor = Red; }
      ObjectCreate(OrderTyp, OBJ_LABEL, 0 , 0, 0, 0);
      ObjectSet(OrderTyp, OBJPROP_CORNER, 1);
      ObjectSet(OrderTyp, OBJPROP_XDISTANCE, 10);
      ObjectSet(OrderTyp, OBJPROP_YDISTANCE, 15);
      ObjectSetText(OrderTyp, "Order Type: "+ot, 8, "Tahoma",LabelColor);
//----
   return(0);
  }
 
pro_: it will only show the type of the last order if you have more than one, it will not disappear when there are no positions, etc.


As you say, It shows the last order type! My problem is that! I want it to show current chart order type!


Thanks 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.

Reason: