Order History in pips

hughbriss
131
hughbriss  

I've coded this little indicator to show me the last 10 trades profit or loss in pips. At the moment it shows me the first 10 trades in the order history pool. I want to display the last 10 trades. I can't work out why it won't work, can anyone help? Thanks.

 

double orderpipsprofit;
color profcol;

int start() 
{
Display("heading", 40,20);
ObjectSetText("heading","Account History In Pips",12,"Verdana", Blue);

int counter1;
  for(counter1 = OrdersHistoryTotal() - 10; counter1 <= OrdersHistoryTotal(); counter1++)
  {
  OrderSelect(counter1,SELECT_BY_POS,MODE_HISTORY);
  
  if(OrderType() == OP_BUY)
  {
  orderpipsprofit = (OrderClosePrice() - OrderOpenPrice()) * 10;
  profcol = Blue; if(orderpipsprofit > 0) profcol = Lime; if(orderpipsprofit < 0) profcol = Red;
  }
  if(OrderType() == OP_SELL)
  {
  orderpipsprofit = (OrderOpenPrice() - OrderClosePrice()) * 10;
  profcol = Blue; if(orderpipsprofit > 0) profcol = Lime; if(orderpipsprofit < 0) profcol = Red;
  }
  
  Display("order" + OrderTicket(), 40, 40 + (20 * counter1));
  ObjectSetText("order" + OrderTicket(),OrderSymbol() + " / " + DoubleToStr(orderpipsprofit,1),10,"Verdana", profcol);
}
return(0);
  }
  
  void Display(string name, int x, int y)
   {
   ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
   ObjectSet(name, OBJPROP_CORNER, 0);
   ObjectSet(name, OBJPROP_XDISTANCE, x);
   ObjectSet(name, OBJPROP_YDISTANCE, y);
   ObjectSet(name, OBJPROP_BACK, FALSE);
   } 
Simon Gniadkowski
17400
Simon Gniadkowski  
hughbriss:

I've coded this little indicator to show me the last 10 trades profit or loss in pips. At the moment it shows me the first 10 trades in the order history pool. I want to display the last 10 trades. I can't work out why it won't work, can anyone help?

I assume you mean the 10 most recently closed trades ?  these should be the 10 highest (largest index numbers) positions in the pool.  Your loop is wrong,  the last position is OrderHistoryTotal() - 1,  starting at OrderHistoryTotal() - 10 and counting up while your count is  <= OrdrHistoryTotal() will try to go one index too far,  it should be < OrdrHistoryTotal()

If you only have 10 Orders in the pool you will be finding the first and last 10.  How many do you have ? 

hughbriss
131
hughbriss  

Thanks, part of the problem was the method I was using to display the pairs. I have sorted it now.  

hughbriss
131
hughbriss  

Here is the code if anyone wants it. I gave you a vouch on Forex Factory by the way, in case you haven't seen it. Thanks for the help.

 

double orderpipsprofit;
color profcol;

int start() 
{
ObjectsDeleteAll();

Display("heading", 40,20);
ObjectSetText("heading","Account History In Pips",12,"Verdana", Blue);

int counter1;
int ordercount = 0;
for(counter1 = OrdersHistoryTotal() -1; ordercount < 11; counter1--)
{
OrderSelect(counter1,SELECT_BY_POS,MODE_HISTORY);

  int pipMult = 10000;
  if(StringFind(OrderSymbol(),"JPY",0) != -1) pipMult = 100;
  
  if(OrderType() == OP_BUY)
  {
  orderpipsprofit = (OrderClosePrice() - OrderOpenPrice()) * pipMult;
  profcol = Blue; if(orderpipsprofit > 0) profcol = Lime; if(orderpipsprofit < 0) profcol = Red;
  ordercount++;
  }
  if(OrderType() == OP_SELL)
  {
  orderpipsprofit = (OrderOpenPrice() - OrderClosePrice()) * pipMult;
  profcol = Blue; if(orderpipsprofit > 0) profcol = Lime; if(orderpipsprofit < 0) profcol = Red;
  ordercount++;
  }
  
  if(OrderType() == OP_BUY || OrderType() == OP_SELL)
  {
  Display("order" + OrderTicket(), 40, ((ordercount * 20) + 20));
  ObjectSetText("order" + OrderTicket(),OrderSymbol() + " / " + DoubleToStr(orderpipsprofit,1),10,"Verdana", profcol);
  }

}
return(0);
 }
  
  void Display(string name, int x, int y)
   {
   ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
   ObjectSet(name, OBJPROP_CORNER, 0);
   ObjectSet(name, OBJPROP_XDISTANCE, x);
   ObjectSet(name, OBJPROP_YDISTANCE, y);
   ObjectSet(name, OBJPROP_BACK, FALSE);
   } 
Simon Gniadkowski
17400
Simon Gniadkowski  
hughbriss:

Here is the code if anyone wants it. I gave you a vouch on Forex Factory by the way, in case you haven't seen it. Thanks for the help.

Thank you,  I hadn't seen it,  not been on there for a little while,  you are most welcome :-) 
hughbriss
131
hughbriss  
RaptorUK:
Thank you,  I hadn't seen it,  not been on there for a little while,  you are most welcome :-) 
I have over 2500 posts there and I haven't been there in a little while. I was a commercial member and charged for a forum but I have shut everything down since I have been trading for a group of investors. I don't have the time anymore. I dip in here from time to time as I do all of my own coding these days, albeit hit and miss sometimes. I am going to add the above code to my main alert dashboard and add average win/loss stats. I like adding useful little bits and pieces like that.
William Roeder
25313
William Roeder  
hughbriss: At the moment it shows me the first 10 trades in the order history pool. I want to display the last 10 trades. 
You probably don't want to either. You want the last 10 closed trades (by datetime.) The order in the pool is irrelevant. Could EA Really Live By Order_History Alone? - MQL4 forum
hughbriss
131
hughbriss  
WHRoeder:
You probably don't want to either. You want the last 10 closed trades (by datetime.) The order in the pool is irrelevant. Could EA Really Live By Order_History Alone? - MQL4 forum
Well it appears to be giving me the information that I want as it is. It is showing the last 10 closed trades in the order they were closed. I assume they enter the pool in that order.
William Roeder
25313
William Roeder  
hughbriss: Well it appears to be giving me the information that I want as it is.
So what? Did you bother to follow AND read the links. What part of "dabbler says "the order of entries is mysterious (by actual test)" was not clear?