Need assistance checking if the last closed order was a profit and the day before
You are in trouble every month: 31 => 1!
Either use TimDayOfYear (= once-a-year-trouble) or use:
... if ( OrderCloseTime() > iTime(_Symbol,PERIOD_D1,1) ) { // closed after yesterday's open.. ...
Okay I now have this and it still allows orders to open if an order closed the previous day in profit.
bool CheckLastOrder() { for(int i=OrdersHistoryTotal()-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS,MODE_HISTORY); if ( OrderSymbol()==Symbol() && OrderMagicNumber() == Magic ) { Print (OrderCloseTime(), " ",iTime(_Symbol,PERIOD_D1,1)); if ( OrderCloseTime() < iTime(_Symbol,PERIOD_D1,1) && OrderProfit() > 0 ) { // Print ("Not last day", " ", TimeDay(OrderCloseTime())+1 , " ", TimeDay(TimeCurrent()) ); return(True); } if ( OrderCloseTime() >= iTime(_Symbol,PERIOD_D1,1) && OrderProfit() > 0 ) { return(False); // Print ("last day", " ", TimeDay(OrderCloseTime())+1 , " ", TimeDay(TimeCurrent()) ); } } return(True); } }
Now if I change the function to setting a variable rather than returning a boolean and test this, it works. Go figure!
Best regards Steve
Hi,
After analysis of my backtest results it seems apparent that my EA would perform better if orders were not raised if the previous day an order was closed in profit. I've tried adding a function.
Which I call before all my trade logic with
if ( CheckLastOrder()); { ... ...However it's not preventing orders being raised on the following day as expected. Can anyone spot any obvious mistakes with my logic please?
Best regards Steve