What's not working, exactly? Is the order not being placed or is the order not being executed?
Before making the call to OrderSend, do a ResetLastError, make the call, then Print out GetLastError. If the error value is greater than 0, check the error codes to help you debug it.
If you're trying to do a reversal, double check the parameters for OrderSend.
Right off the bat, I see that you're using NULL as a parameter where you shouldn't, since the docs don't specify NULL as a valid parameter value. It may work, but you should use a valid parameter value, instead.
Make sure to double check your lot size is >= SYMBOL_VOLUME_MIN, <= SYMBOL_VOLUME_MAX, and a valid lot step using SYMBOL_VOLUME_STEP. You can get those values using SymbolInfoDouble.
Make sure your Entry price, TP Price, and SL price are properly normalized. If not, your order won't go through. From the OrderSend section of the docs:
Calculated or unnormalized price cannot be applied.
Or it could be that you're trying to set a take profit on the open order. In which case, you should modify the open order to include the TP using OrderModify
- docs.mql4.com
-
if( OrderSelect(z, SELECT_BY_POS, MODE_TRADES) && OrderType() == OP_SELL || OrderType()==OP_BUY)
Never mix and's and or's. A && B || C Do you mean (A && B) || C Or A && (B || C) Your code bool checkOpenOrders() { for (int z = OrdersTotal()-1; z >=0; z--) { if( OrderSelect(z, SELECT_BY_POS, MODE_TRADES) && OrderType() == OP_SELL || OrderType()==OP_BUY) return(true); } return(false); //no open orders for mag# }
Simplified bool checkOpenOrders() { return countOpenOrders() > 0; }
-
OrderSend(NULL,OP_SELLSTOP,ls3,tpSell,10,slSell,tpSellStop,NULL,1);
Be careful with NULL.
- On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
- Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
- Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
- MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
- Cloud Protector Bug? - MQL4 programming forum (2020.07.25)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want my EA to only do the OrderSend if the OrderMagicNumber 0 (a pending order) is fulfilled. I can't seem to make this work.
I also tried this approach but it also failed.
I'm a beginner. I've been working on this for weeks and I'm desperate for help. Any help will be greatly appreciated!!