- I change to code as per 2nd snippet, but still no luck. Any idea how to do that?
- Luck is irrelevant. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
- Check your return codes (ObjectCreate)
and find out why.
What are Function
return values ? How do I use them ? - MQL4 forum and Common Errors
in MQL4 Programs and How to Avoid Them - MQL4 Articles
- Sell_Ticket = OrderSend(Symbol(),Type,LotSize,pPrice,Slippage,SL_Level,TP_Level,CommentSell,Magic,0,Arrow);OrderSend returns a ticket number or -1. Since non-zero is true, your if statement is always true.
if(Sell_Ticket)
{
for(int order = 0; order <= OrdersTotal() - 1; order++)
{
bool select = OrderSelect(order,SELECT_BY_POS);
RefreshRates();
if(select && OrderType()==OP_SELL && OrderMagicNumber() == Magic) - Why are you doing all that? If you have a valid Sell_Ticket, just select by ticket.
|
hi whroeder1, thanks for replying.
- The code work, but it only work once... as per my above explanation.. But anyway, found the solution already, like 1 hour ago.. (my mistake, i miss que the trade logic)
SOLVE
- Luck is irrelevant. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
- Check your return codes (ObjectCreate)
and find out why.
What are Function
return values ? How do I use them ? - MQL4 forum and Common Errors
in MQL4 Programs and How to Avoid Them - MQL4 Articles
- Sell_Ticket = OrderSend(Symbol(),Type,LotSize,pPrice,Slippage,SL_Level,TP_Level,CommentSell,Magic,0,Arrow);OrderSend returns a ticket number or -1. Since non-zero is true, your if statement is always true.
if(Sell_Ticket)
{
for(int order = 0; order <= OrdersTotal() - 1; order++)
{
bool select = OrderSelect(order,SELECT_BY_POS);
RefreshRates();
if(select && OrderType()==OP_SELL && OrderMagicNumber() == Magic) - Why are you doing all that? If you have a valid Sell_Ticket, just select by ticket.
I have another logic for if(!Sell_Ticket), to check for error.. Order Failed & no OBJ_TEXT will be drawn.
anyway Thanks Whoeder1 for your reply.
I have another logic for if(!Sell_Ticket), to check for error.. Order Failed & no OBJ_TEXT will be drawn.
anyway Thanks Whoeder1 for your reply.
OrderSend does NOT return true/false.
OrderSend returns the ticket number, or -1 if it failed.
This:
Means the same as this:
Means the same as this:
As @whroeder1 has pointed out, this will probably never happen. The only time it can happen is if OrderSend succeeds, and the ticket number is 0. I have never seen this.
Remember: if OrderSend fails, it returns -1
You should be writing:
OrderSend does NOT return true/false.
OrderSend returns the ticket number, or -1 if it failed.
This:
Means the same as this:
Means the same as this:
The only time your logic works is if OrderSend succeeds, and the ticket number is 0.
Hi honest_Knave,
Thanks for pointing out. should've change to
and select by ticket as Whoeder1 advise.

- docs.mql4.com

- 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 friends,
I develop and EA to open order base on multiple strategy.
CommentBuy = "Buy Order";
void OnTick()
{
// Trade Logic
if(Startegy1()=="Sell")
{
Sell_Ticket = OrderSend(Symbol(),Type,LotSize,pPrice,Slippage,SL_Level,TP_Level,CommentSell,Magic,0,Arrow);
if(Sell_Ticket)
{
for(int order = 0; order <= OrdersTotal() - 1; order++)
{
bool select = OrderSelect(order,SELECT_BY_POS);
RefreshRates();
if(select && OrderType()==OP_SELL && OrderMagicNumber() == Magic) OpenOrderTag(CommentSell,OrderOpenPrice()+50*Point,clrRed);
}
}
}
if(Startegy1()=="Buy")
{
// code goes here
}
}
void OpenOrderTag(string name, double price, color col)
{
ObjectCreate(name,OBJ_TEXT,0,Time[0],price);
ObjectSetText(name,name,7,"Arial",EMPTY);
ObjectSet(name, OBJPROP_COLOR,col);
}
Revised code.
{
string x = IntegerToString(Ticket);
ObjectCreate(name+x,OBJ_TEXT,0,Time[0],price);
ObjectSetText(name+x,name,7,"Arial",EMPTY);
ObjectSet(name+x,OBJPROP_COLOR,col);
}