I'm testing a scalping algo and am having problems calculating independent order profits. Can anyone help?
It's only printing an "incorrect" BUYORDERSPROFIT, and one of either USDJPYBUYOPL," or ",EURUSDBUYOPL, with one of them printing as 0 which is mucking up the calculation and closing trades regardless of P/L.
The main problem is the calculation for BUYORDERSPROFIT is not closing on greater than 0.
What am I doing wrong here? Full code below...
It's only printing an "incorrect" BUYORDERSPROFIT, and one of either USDJPYBUYOPL," or ",EURUSDBUYOPL, with one of them printing as 0 which is mucking up the calculation and closing trades regardless of P/L.
The main problem is the calculation for BUYORDERSPROFIT is not closing on greater than 0.
What am I doing wrong here? Full code below...
Inserted Code
void CalcOP() { int totalorders = OrdersTotal(); for(int i=totalorders-1;i>=0;i--) { if(!OrderSelect(i, SELECT_BY_POS)) { Print(TimeToStr(TimeCurrent(),TIME_SECONDS), " CHECK Function > ", __FUNCTION__," !!!!! ", OrderMagicNumber(), " Error code = ", GetLastError()); } if ((Hour() >= CH) && (Minute() >= CM)) { CloseOutBUYORDERS(); CloseOutSELLORDERS(); } double USDJPYBUYOPL; double EURUSDBUYOPL; double USDJPYSELLOPL; double EURUSDSELLOPL; double BUYORDERSPROFIT; double SELLORDERSPROFIT; { if ((OrderType() == OP_BUY) && (OrderSymbol() == "USDJPY") && (OrderMagicNumber() == Trade1L)) USDJPYBUYOPL = OrderProfit(); } { if ((OrderType() == OP_BUY) && (OrderSymbol() == "EURUSD") && (OrderMagicNumber() == Trade2L)) EURUSDBUYOPL = OrderProfit(); } { if ((OrderType() == OP_SELL) && (OrderSymbol() == "USDJPY") && (OrderMagicNumber() == Trade1S)) USDJPYSELLOPL = OrderProfit(); } { if ((OrderType() == OP_SELL) && (OrderSymbol() == "EURUSD") && (OrderMagicNumber() == Trade2S)) EURUSDSELLOPL = OrderProfit(); } BUYORDERSPROFIT = ((USDJPYBUYOPL) + (EURUSDBUYOPL)); SELLORDERSPROFIT = ((USDJPYSELLOPL) + (EURUSDSELLOPL)); if (((OrdersTotal() > 0) && (OrderType() == OP_BUY) && (OrderSymbol() == "USDJPY") && ((BUYORDERSPROFIT) > 0) && ((BUYORDERSPROFIT) > ( OrderLots()*PT ))) || ((OrdersTotal() > 0) && (OrderType() == OP_BUY) && (OrderSymbol() == "EURUSD") && ((BUYORDERSPROFIT) > 0) && ((BUYORDERSPROFIT) > ( OrderLots()*PT )))) {Print(BUYORDERSPROFIT," ",USDJPYBUYOPL," ",EURUSDBUYOPL," ",MarketInfo("USDJPY",MODE_ASK)," ",MarketInfo("EURUSD",MODE_ASK)); CloseOutBUYORDERS(); } if (((OrdersTotal() > 0) && (OrderType() == OP_SELL) && (OrderSymbol() == "USDJPY") && ((SELLORDERSPROFIT) > 0) && ((SELLORDERSPROFIT) > ( OrderLots()*PT ))) || ((OrdersTotal() > 0) && (OrderType() == OP_SELL) && (OrderSymbol() == "EURUSD") && ((SELLORDERSPROFIT) > 0) && ((SELLORDERSPROFIT) > ( OrderLots()*PT )))) {Print(SELLORDERSPROFIT," ",USDJPYSELLOPL," ",EURUSDSELLOPL," ",MarketInfo("USDJPY",MODE_ASK)," ",MarketInfo("EURUSD",MODE_ASK)); CloseOutSELLORDERS();} } return; }