Is there ever Op_Buy orders when you run that code?
Is there ever Op_Buy orders when you run that code?
For buy order there is a special code.
sell : Top position
Buy: bottom position
//+-------------------------------------------------------------------+ double Open.Sell.End() { double OOP=0; if (OTMS(Magicsell)>0) { for (int q=0;q<OrdersTotal();q++) { if (OrderSelect(q,SELECT_BY_POS,MODE_TRADES)==true) { if (OrderMagicNumber()==Magicsell) { if (OrderType()==OP_SELL) { if (OOP==0) OOP=OrderOpenPrice(); else if (OrderOpenPrice()>OOP) { OOP=OrderOpenPrice(); } } } } } } return(OOP); } //+-------------------------------------------------------------------+ double Open.Buy.End() { double OOP=0; if (OTMB(Magicbuy)>0) { for (int q=0;q<OrdersTotal();q++) { if (OrderSelect(q,SELECT_BY_POS,MODE_TRADES)==true) { if (OrderMagicNumber()==Magicbuy) { if (OrderType()==OP_BUY) { if (OOP==0) OOP=OrderOpenPrice(); else if (OrderOpenPrice()<OOP) { OOP=OrderOpenPrice(); } } } } } } return(OOP); }
Humm well. The biggest thing I see here is that you're comparing Integers to Doubles.
if (OOP==0) OOP=OrderOpenPrice();
The above is usually not a big deal when comparing it to 0. However if something like
if (OrderMagicNumber()==Magicsell)
if Magicsell is a type double. This can cause some problems. Check out this Article.
Well that's about all I can see thus far.
#define INF 0x6FFFFFFF // Not quite infinite, Jul 2029, or 1,879,048,191 double Open.Sell.End(){ double OOP=-INF; for (int pos=OrdersTotal()-1; pos >= 0; pos--) if( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. && OrderType() == OP_SELL){ OOP = MathMax(OOP, OrderOpenPrice()); } return(OOP); } double Open.Buy.End(){ double OOP=+INF; for (int pos=OrdersTotal()-1; pos >= 0; pos--) if( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. && OrderType() == OP_BUY){ OOP = MathMin(OOP, OrderOpenPrice()); } return(OOP); }No need for two magic numbers, but they should be integers.
Humm well. The biggest thing I see here is that you're comparing Integers to Doubles.
The above is usually not a big deal when comparing it to 0. However if something like
if Magicsell is a type double. This can cause some problems. Check out this Article.
Well that's about all I can see thus far.
Thanks a lot for response, the problem has been solved
Here's How I would code it for clarity: No need for two magic numbers, but they should be integers.
Thanks for nice code
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
the following code is working in some brokers but will fail in others. In some brokers the function will return 0 instead of returning the value of the top order.