Feel free to return GetPointer(this) from methods.
At least in method setters this is justified - the code may become more readable and compact, you get a la named parameters
ChartObject *hline=HLine::New(1.255).Color(clrGreen).Width(2).Selectable(true); // не надо помнить очерёдность параметров и можно писать в одну строку - цепочкой
// получается вот из подобного : class HLine:public ChartObject { public: HLine(double price); HLine *New(double _price) { return new HLine(_price); } // это чтобы не городить (new HLine(...)).Method1 HLine *Color(color _clr) { fgColor=_clr; return GetPointer(this); } // а это чтобы получались цепочки obj.Method1(..).Method2(..) };
Of course, use with caution, because there are no exception`s in the language and are not expected
and a little bit interferes with the qualification of functions by the returned type.
// После этого в MQL4 будут компилироваться все библиотеки из MQL5\Include\Math#property strict#ifdef __MQL4__#include <Math\Alglib\bitconvert.mqh>
#define TEMP_MACROS(A) double A( double ) { return(0); }
TEMP_MACROS(MathLog1p)
TEMP_MACROS(MathExpm1)
TEMP_MACROS(MathArcsinh)
TEMP_MACROS(MathArccosh)
TEMP_MACROS(MathArctanh)
#undef TEMP_MACROS
#endif
To close an order, we do not have to define the order type and the price that corresponds to this type. It is enough to write "close at price" in OrderClosePrice()!
/********************Script program start function********************/ voidOnStart() { int i, total = OrdersTotal()-1; for(i = total; i >= 0; i--) { if(OrderType() < OP_SELLSTOP) { if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 100)) printf("***********"); } } }/********************************************************************/
Pretty cool! ) Thank you.
Judging by the example, you don't need OrderSelect() either?
Artyom Trishkin: Needed. Just missed it due to laziness...
Yeah, well... Really messed up.
But before, I didn't come across these topics.
fxsaber:
So you can use OrderClosePrice only AFTER the corresponding OrderSelect. Since OrderSelect copies the data for Order(const)-functions once, and the same RefreshRates is not able to update them.
I.e. if, for example, OrderClosePrice fails to close, then you must do OrderSelect again before the next attempt (RefreshRates is not required).
ZS This thread is from 2005! There are detailed arguments from the developers here.
So you can use it, but with the understanding that there may be trouble.
Open orders should be analysed from a higher number, i.e. for(int nom=OrdersTotal()-1; nom>=0; nom--) This is especially important when deleting orders. But what will happen if we do the opposite for(int nom=0; nom<OrdersTotal(); nom++) ? At first, the index is equal to zero and the very first order with number 0 is deleted. Then the index becomes equal to 1. At this point the remaining orders are shifted and the one with number 1 occupies the zero position. The former number 2 takes position 1. It will be deleted. Then the index becomes 2. And the order which was number 4 at the beginning will be deleted. Thus, the orders which occupy even-numbered positions at the beginning are deleted. The odd-numbered ones will remain. This can be seen in the comments to the orders and numbers. I attach a script showing both options of deleting and screenshots There are 20 pending orders
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
At least in method setters this is justified - the code may become more readable and compact, you get a la named parameters
ChartObject *hline=HLine::New(1.255).Color(clrGreen).Width(2).Selectable(true); // не надо помнить очерёдность параметров и можно писать в одну строку - цепочкой
// получается вот из подобного :
class HLine:public ChartObject {
public:
HLine(double price);
HLine *New(double _price) { return new HLine(_price); } // это чтобы не городить (new HLine(...)).Method1
HLine *Color(color _clr) { fgColor=_clr; return GetPointer(this); } // а это чтобы получались цепочки obj.Method1(..).Method2(..)
};
and a little bit interferes with the qualification of functions by the returned type.
Feel free to return GetPointer(this) from methods.
This way &this is more concise.
Well, let me start first.
To close an order, we do not have to define the order type and the price that corresponds to this type. It is enough to write "close at price" in OrderClosePrice()!
void OnStart()
{
int i, total = OrdersTotal()-1;
for(i = total; i >= 0; i--)
{
if(OrderType() < OP_SELLSTOP)
{
if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 100))
printf("***********");
}
}
}/********************************************************************/
Pretty cool! ) Thank you.
Judging by the example, you don't need OrderSelect() either?
(Cool! ) Thanks.
Judging by the example, OrderSelect() isn't needed either?
Nice! ) Thanks.
Needed. Just missed it due to laziness...
Yeah, well... Really messed up.
But before, I didn't come across these topics.
So you can use OrderClosePrice only AFTER the corresponding OrderSelect. Since OrderSelect copies the data for Order(const)-functions once, and the same RefreshRates is not able to update them.
I.e. if, for example, OrderClosePrice fails to close, then you must do OrderSelect again before the next attempt (RefreshRates is not required).
ZS This thread is from 2005! There are detailed arguments from the developers here.
Open orders should be analysed from a higher number, i.e. for(int nom=OrdersTotal()-1; nom>=0; nom--)
There are 20 pending orders
This is especially important when deleting orders.
But what will happen if we do the opposite for(int nom=0; nom<OrdersTotal(); nom++) ?
At first, the index is equal to zero and the very first order with number 0 is deleted.
Then the index becomes equal to 1. At this point the remaining orders are shifted and the one with number 1
occupies the zero position. The former number 2 takes position 1. It will be deleted.
Then the index becomes 2. And the order which was number 4 at the beginning will be deleted.
Thus, the orders which occupy even-numbered positions at the beginning are deleted. The odd-numbered ones will remain. This can be seen in the comments to the orders and numbers.
I attach a script showing both options of deleting and screenshots