Here it is simple programm and it works sometimes not correct:
What could you say about it?
- Attaching a ex4 is useless for us humans.
- INDENT is one pip. You can not put a pending order closer to market than MarketInfo(chart.symbol, MODE_STOPLEVEL)*Point which is typically 3 pips.
- You don't test return codes to find out why it wasn't working. If the orderSelect fails, then the OrderSymbol is meaningless. If the OrderSend fails you don't notify.
- You don't have wait for the market to get above the open prices. In fact if you wait, you have no stop at all.
for (i = 0; i < OrdersTotal(); i++) if ( OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() // && magic number? ){ is_orders_this_symbol = true; break; } if (!is_orders_this_symbol){ int ticket = OrderSend(Symbol(), OP_BUYSTOP, 0.1, Ask + INDENT, 5, 0.0, 0.0); if (ticket < 0) Alert("OrderSend failed: ", GetLastError()); else if (OrderSelect(ticket, SELECT_BY_TICKET)) Alert("OrderSelect failed: ", GetLastError()); else if (!OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - STOP, 0.0, 0)) Alert("OrderModify failed: ", GetLastError()); }
Well, I initially disliked this code
for (i = 0; i < OrdersTotal(); i++) if ( OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() // && magic number? ){ is_orders_this_symbol = true; break; } if (!is_orders_this_symbol){ int ticket = OrderSend(Symbol(), OP_BUYSTOP, 0.1, Ask + INDENT, 5, 0.0, 0.0); if (ticket < 0) Alert("OrderSend failed: ", GetLastError()); else if (OrderSelect(ticket, SELECT_BY_TICKET)) Alert("OrderSelect failed: ", GetLastError()); else if (!OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - STOP, 0.0, 0)) Alert("OrderModify failed: ", GetLastError()); }
Then I thought, perhaps it is a bit clever and neat, and I was just being a misery guts.
+ + + + +
but now I have changed my mind again and don't like it. If the OrderSelect (by ticket) fails the error is reported but there is no way to fix it. ( I don't think there is any mechanism by which that one can actually fail though.) If the OrderModify fails, a highly likely situation, again there is no remedy. I understand you are not writing the code for him, and it is not complete code, but it would require a repeated block of code to select by the ticket that we no longer know. Therefore the code is actually less efficient than it might at first appear. Which is not to say it is bad code, but it is not as good as it could be.
OK, I added testing return codes, increased INDENT value, but the problem still takes place - sometimes in log error 133 appears, trade is disabled.
I don't understand, why is it disabled, when it's enabled? This is what I want to hear from you, guys.
OK, I added testing return codes, increased INDENT value, but the problem still takes place - sometimes in log error 133 appears, trade is disabled.
I don't understand, why is it disabled, when it's enabled? This is what I want to hear from you, guys.
Always search before asking, thats how the rest of us get by. Link Here. And Documentations Here. Provided the Doc as your reference after you Print-Errors when testing.
Of course, I searched before asking!
As I understood, 133 error means that trade is fully disabled. But with my account I can to trade manually, OrderSend() always works, but SOMETIMES OrderModify() returns this error.
Or do you want to say that it is anyway because of Broker, not MT4 terminal?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello!
Here it is simple programm and it works sometimes not correct:
What could you say about it?