No guts, no glory
Help with multiple OrderProfit() Calculations 0 replies
Adding Lots 12 replies
Adding Brokers to Metatrader 1 reply
Adding more charts on MT4 2 replies
Adding to Mouteki without Understanding why 25 replies
Disliked/// declarations int OrdProf=0,OrdLoss=0; double TotalProf=0.0,TotalLoss=0.0; // loop through all orders for(int i=0;i<OrdersTotal();i++) { // each order need to be selected before refering to its data if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderProfit()>0.0) { OrdProf ++ ; TotalProf += OrderProfit(); } else { OrdLoss ++ ; TotalLoss += OrderProfit(); } }Ignored
Disliked{quote} Are you suggesting to count forward through orders, instead of backwards? Also, shouldn't it be using OrdersHistoryTotal & MODE_HISTORY for closed trades? VladIgnored
DislikedHi Abokwaik. Thanks for the reply but I do not see your code - the one that you will quit overIgnored
DislikedHi Abokwaik Sorry I missed post 19. Actually, I have tried that exactly, but as I am calculating MAE and MFE (as well as Sharpe) I actually do a lot of work with an order. If you look at post 16 you will see that I am actually working with closed orders only. Just by the way, your code won't be correct because in the Closed History there are records you don not want to process - deposit, cancellations and Stop/Limits. In your code they would all go into the 'else'.Ignored
int OrdProf=0,OrdLoss=0; double TotalProf=0.0,TotalLoss=0.0; int hist_count=OrdersHistoryTotal(); // loop through all orders for(int i=hist_count-1;i>-1;i--) { // each order need to be selected before refering to its data if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) break; if(OrderType()==OP_BUY || OrderType()==OP_SELL) { if(OrderProfit()>0.0) { OrdProf ++ ; TotalProf += OrderProfit(); } else { OrdLoss ++ ; TotalLoss += OrderProfit(); } } } Print("OrdProf= ",OrdProf," TotalProf= ",TotalProf," OrdLoss= ",OrdLoss," TotalLoss= ",TotalLoss);
DislikedHi Abokwaik. Your OP_BUY and OP_SELL would work - or you could just use OrderType() < 2 which will only read true closed Buys and SellsIgnored
DislikedHi Abokwaik Yep, I also like to be specific. Have you read any of my replies? As I have said, I have tried that and it makes no difference - I have also tried that as isolated code. It is for this reason that I am sure there is something wrong with my MT4 installation.Ignored
void OnStart() { //--- int OrdProf=0,OrdLoss=0; double TotalProf=0.0,TotalLoss=0.0; int hist_count=OrdersHistoryTotal(); // loop through all orders for(int i=hist_count-1;i>-1;i--) { // each order need to be selected before refering to its data if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) break; if(OrderType()==OP_BUY || OrderType()==OP_SELL) { if(OrderProfit()>0.0) { OrdProf ++ ; TotalProf += OrderProfit()+OrderSwap()+OrderCommission(); } else { OrdLoss ++ ; TotalLoss += OrderProfit()+OrderSwap()+OrderCommission(); } } } Print("OrdProf= ",OrdProf," TotalProf= ",DoubleToStr(TotalProf,2)," OrdLoss= ",OrdLoss," TotalLoss= ",DoubleToStr(TotalLoss,2)); }
DislikedHi Gumrai If you read my earlier mail, you will see I have tried OrderProfit() with no change at all. I do not add 1 to OrdProfit - only to OrdProf - the number of orders. Also, it is not the Profit section that doesn't work - it is the Negative - the bit after the else.Ignored
DislikedHi Abokwaik . Please read my mails. My code too is EXACTLY the same as the MT4 report, however, the details in that report are very light = no major stats. It is for this reason that I am writing this. For the record - ALL my code is mover 900 lines not the few you are showing, so I actually do an awful lot with this. As I have said - everything except the Negative closed orders is correct - including fields you do not have such as MAE, MFE Distribution, Sharpe etc. This does that - and asw I have shown it also adds Comm and Swap. But thank you...Ignored