if(!CheckIfOpenOrdersByMagicNumber(MN)) { if (lastordertype == 1) { shortSL = Close[0] + (Point*100); int orderid = OrderSend(NULL,OP_SELL,lotsize(maxRiskPerTrade,shortentry,shortSL),shortentry,slippage,shortSL,0,NULL,MN); if (orderid < 0) Alert("order rejected. Order error: " + GetLastError()); lastordertype = 0; } else if (lastordertype == 0) { longSL = Close[0] - (Point*100); int orderid = OrderSend(NULL,OP_BUY,lotsize(maxRiskPerTrade,longentry,longSL),longentry,slippage,longSL,0,NULL,MN); if (orderid < 0) Alert("order rejected. Order error: " + GetLastError()); lastordertype = 1; } else if (Open[0] < Close[0]) { {int orderid = OrderSend(NULL,OP_BUY, lotsize(maxRiskPerTrade,longentry,longSL),longentry,slippage,longSL,0,NULL,MN);} if (orderid < 0) Alert("order rejected. Order error: " + GetLastError()); lastordertype = 0; } else if (Open[0] > Close[0]) { {int orderid = OrderSend(NULL,OP_SELL, lotsize(maxRiskPerTrade,shortentry,shortSL),shortentry,slippage,shortSL,0,NULL,MN);} if (orderid < 0) Alert("order rejected. Order error: " + GetLastError()); lastordertype = 1; }
instead of using ordershistorytotal, I simply created a variable to compare it to last order(lastordertype is int value inside of ontick). The back-tester is now working, but orders are not sending as they should. If it gets stopped out on a long position, it will re-enter a long position. same for shorts.
Actually, see the above error in the code. mixed up lastordertype
Ok the duplicate orders stopped since the revised code above. Thanks anyway :-)
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
Howdy peeps! The EA is sending duplicate orders instead of 1, therefore doubling my risk. I tried removing the else if code blocks of (Open[0] < Close[0]) & (Open[0] > Close[0]) thinking that maybe it ran through the code block before the order could execute but I received the same result when I removed those lines of code. How can I get around this?
Also, when i try to back-test this it does not return any trades. No errors are generated. I think it is not reading the ordershistorytotal loop(althought it works fine trading live except for double orders), but from what i have read the back-tester works with that function. What could it be?