SmartSarb: need to calculate total lost orders from my order history, since the last profit order closed.
for(int i=0; i < hstTotal; i++)
You are processing the earliest orders not the latest. You count all looser but you don't reset the count at a winner. Or you can process the latest and stop counting when you find the latest winner.OrderProfit() < 0
Profit = OrderProfit + commission + swap.if(OrderMagicNumber()== Magic
You are processing orders from any chart, not the current one.- There are other things in history besides closed orders.
- You assume history is ordered by date, it's not.
whroeder1:
- You are processing the earliest orders not the latest. You count all looser but you don't reset the count at a winner. Or you can process the latest and stop counting when you find the latest winner.
- Profit = OrderProfit + commission + swap.
- You are processing orders from any chart, not the current one.
- There are other things in history besides closed orders.
- You assume history is ordered by date, it's not.
Points #1 and #5 are contradictory.
nicholishen: Points #1 and #5 are contradictory.
It is mostly ordered ascending. Therefor the code is mostly "processing the earliest orders." Therefor #1 and #5 are not mostly "contradictory."
SmartSarb:
Hi, I wonder if someone can help me. I need to calculate total lost orders from my order history, since the last profit order closed. I can count the orders but i am struggling with the equation of selecting it from the last profit order. Below is my script. Please can someone help out?
Like whroeder said, you need to sort your orders programmatically before you analyse them. Here is a class to do just that
void OnStart() { //--- MQL4OrderPool pool; pool.Init( Symbol(), 0, // magic MODE_HISTORY, // mode ORDERS_FILLED, // filter by order type filled = OP_BUY+OP_SELL SORT_CLOSE_TIME_DESCENDING);// default sort mode int losing_orders = 0; for(int i=0;i<pool.Total();i++) { if(pool[i].OrderProfit() < 0) losing_orders++; else break; } // or you can also use losing_orders=0; for(MQL4Order *ord = pool.GetFirstNode();ord!=NULL;ord = pool.GetNextNode()) { if(ord.OrderProfit() < 0) losing_orders++; else break; } }
so that you can count losing orders.
or if you're feeling lazy you can just copy/paste this function...
int LosingOrdersSinceProfitOrder(int magic) { MQL4OrderPool pool; pool.Init(Symbol(),magic,MODE_HISTORY,ORDERS_FILLED,SORT_CLOSE_TIME_DESCENDING); int losing = 0; if(pool.Total() < 2) return losing; if(pool[0].OrderProfit() > 0) { for(int i=1;i<pool.Total();i++) { if(pool[i].OrderProfit() < 0) losing_orders++; else break; } } return losing; }
Files:
MQL4OrderPool.mqh
9 kb
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi, I wonder if someone can help me. I need to calculate total lost orders from my order history, since the last profit order closed. I can count the orders but i am struggling with the equation of selecting it from the last profit order. Below is my script. Please can someone help out?