A strange overly complex function... nevertheless, appears to now work with just 2 mods.
Use below - a fast test gave output of 6 - since all initially open at a loss...
Lines altered are commented out with "//" and have highlighted also removed syntax
Please see after code for test results and test code used.
//+----------------------------------------------------------------------------+ //| ????? : ??? ????? ?. aka KimIV, http://www.kimiv.ru | //+----------------------------------------------------------------------------+ //| ?????? : 19.02.2008 | //| ???????? : ?????????? ?????????? ????????? ???????, ???????? ???????. | //+----------------------------------------------------------------------------+ //| Parametrs: | //| sy - symbol ("" - any symbol, | //| NULL - current symbol) | //| op - operation (-1 - any position) | //| mn - MagicNumber (-1 - any magic) | //+----------------------------------------------------------------------------+ int NumberOfLossPosToday(string sy="", int op=-1, int mn=-1) { datetime t; int i, k=OrdersHistoryTotal(), kp=0; //if (sy=="0") sy=Symbol(); if (sy=="") sy=Symbol(); for (i=0; i<k; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { //if (OrderSymbol()==sy || sy=="") { if (OrderSymbol()==sy) { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { if (op<0 || OrderType()==op) { if (mn<0 || OrderMagicNumber()==mn) { t=OrderCloseTime(); if (Year()==TimeYear(t) && DayOfYear()==TimeDayOfYear(t)) { if (OrderProfit()<0) kp++; } } } } } } } return(kp); }
... if (OrderProfit()<0) kp++; if (OrderProfit()<0) Print("#",OrderTicket(),", Profit=",OrderProfit()); //for test output } ... and... //test harness used: // int start() { Print("NumberOfLossPosToday() = ",NumberOfLossPosToday()); return(0); }
from terminal:
2008.06.18 18:16:50 prosper1 GBPUSD,M15: uninit reason 0
2008.06.18 18:16:50 prosper1 GBPUSD,M15: NumberOfLossPosToday() = 6
2008.06.18 18:16:50 prosper1 GBPUSD,M15: #12092545, Profit=-0.2
2008.06.18 18:16:50 prosper1 GBPUSD,M15: #12092548, Profit=-0.3
2008.06.18 18:16:50 prosper1 GBPUSD,M15: #12092565, Profit=-0.3
2008.06.18 18:16:50 prosper1 GBPUSD,M15: #12092158, Profit=-0.2
2008.06.18 18:16:50 prosper1 GBPUSD,M15: #12092199, Profit=-0.4
2008.06.18 18:16:50 prosper1 GBPUSD,M15: #12092206, Profit=-0.3
2008.06.18 18:16:50 prosper1 GBPUSD,M15: loaded successfully
from history:

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I have put this code in my EA' s code but it seems it doesn't work. I ask myself if is code works ? It really stops EA after loss or does other things ? Sorry for this question but i begin in programmation.
This is the code :
Function NumberOfLossPosToday():
//+----------------------------------------------------------------------------+ //| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru | //+----------------------------------------------------------------------------+ //| Версия : 19.02.2008 | //| Описание : Возвращает количество убыточных позиций, закрытых сегодня. | //+----------------------------------------------------------------------------+ //| Parametrs: | //| sy - symbol ("" - any symbol, | //| NULL - current symbol) | //| op - operation (-1 - any position) | //| mn - MagicNumber (-1 - any magic) | //+----------------------------------------------------------------------------+ int NumberOfLossPosToday(string sy="", int op=-1, int mn=-1) { datetime t; int i, k=OrdersHistoryTotal(), kp=0; if (sy=="0") sy=Symbol(); for (i=0; i<k; i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { if (OrderSymbol()==sy || sy=="") { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { if (op<0 || OrderType()==op) { if (mn<0 || OrderMagicNumber()==mn) { t=OrderCloseTime(); if (Year()==TimeYear(t) && DayOfYear()==TimeDayOfYear(t)) { if (OrderProfit()<0) kp++; } } } } } } } return(kp); }