Questions on OOP in MQL5 - page 42

 
Igor Makanu:

...

calls all in privat methods, but is there a "Jedi mindset ?" to get away from CheckPointer(m_order)==POINTER_INVALID in source code

...

It's more likely that this is not a trick, the algorithm must be such, that this part of code is not executed if there is no order.

Or maybe it was intended that way. But unlikely, if there is a pointer, it doesn't mean there is an order, so we have to check if there is an order.

 
Igor Makanu:

and if memory serves me correctly, at the beginning of the year it was possible to unset NULL in the log and get 0 there, now it gives an error

Changes

Forum on trading, automated trading systems and strategy tester

Bugs, bugs, questions

Kirill Belousov, 2017.12.14 21:34

Print(NULL); // 'NULL' - expression of 'void' type is illegal
Alert(NULL); // 'NULL' - expression of 'void' type is illegal

Time to retire

 
A100:

Changes

Yes indeed, but i remembered how i used to do it in MT4, that's how i deregistered the pointers:

class A {};

A *a;
void OnStart()
{  Print("1 : ",a);
   a= new A;
   Print("2 : ",a);
   a = NULL;
   Print("3 : ",a);

delete a;
}

2019.09.17 07:52:40.855 tst (EURUSD,H1) 1 : 0

2019.09.17 07:52:40.856 tst (EURUSD,H1) 2 : 1048576

2019.09.17 07:52:40.856 tst (EURUSD,H1) 3 : 0

2019.09.17 07:52:40.856 tst (EURUSD,H1) 1 undeleted objects left

2019.09.17 07:52:40.856 tst (EURUSD,H1) 1 object of type A left

2019.09.17 07:52:40.856 tst (EURUSD,H1) 24 bytes of leaked memory

Dmitry Fedoseev:

This is probably not the case, the algorithm should be such that this part of the code is not executed if there is no order.

Or maybe it is intended that way. But it's unlikely, if there is a pointer, it doesn't mean there is an order, so we have to check for existence of an order.

Depending on the problem, I have already written in code how to create an "order object" that would itself look what is in the market - search for an order in the designer using a magik, if found it will pick it up, open an order at a price, the order type itself counts (market or pending), lot normalization, retry to open an order if requotes were on a previous tick, after a successful order placement on the next tick, place a sl and so on... this all is done by itself without any intervention from the "order object".

And if the order has been closed, it is sort of still there for the strategy - ultimately, the strategy is interested in the order profit (current or closed already - it does not matter!) and in thestate of the order itself (not yet placed, active or already closed)


everything works as planned, maybe you are right somewhere, but for now the code is still being tested, pointers must be checked, later we can try without this check... although the logic of work implies the following actions if there is no such object.... in principle not much left to redo everything to virtual orders, I still need to think ))))

 
Igor Makanu:

I wanted to write what I used to have instead of

it was like this:

but remembered how to check macro substitutions in MQL

2019.09.16 22:57:42.837 tst (EURUSD,H1) a = 1

2019.09.16 22:57:42.837 tst (EURUSD,H1) POINTER_INVALID = 0

2019.09.16 22:57:42.837 tst (EURUSD,H1) NULL = 0


and if memory serves me correctly, at the beginning of the year it was possible to unprinter NULL into the log and get 0 there , now an error is displayed

I.e. the behavior NULL as if should not change in the future, but what is substituted there instead of NULL is not clear, probably if this situation is checked now, as writtenif(CheckPointer(m_order)==POINTER_INVALID)) ) it is so to say the correct code))

Feel free to apply. With 98% confidence NULL in the source code is something like #define NULL nullptr
 
Vladimir Simakov:

And then there's this, for sugar:

The first simple test shows

void OnStart()
{
    A * const a = new A;
    DELETE(a); //Error: 'a' - constant cannot be modified
}

that it's not sugar, but a different... more liquid substance

 
A100:

The first simple test shows

that it's not sugar, but a different... more liquid substance.

Because it's not there.) NULL is neither here nor there. You should use the CheckPointer() function. The pointer does not need to be zeroed by itself - after deleting it becomes POINTER_INVALID by itself.

 
Dmitry Fedoseev:

Because that's not where you are)) NULL is neither here nor there. You should use the CheckPointer() function. You don't need to zero the pointer by yourself, it becomes POINTER_INVALID by itself after deleting.

I completely agree. If you read admins, it usually sounds as follows: "Write your codes correctly

MQL in general is always tough, new build, new troubles, you start to find out if I've used it incorrectly, here you go and sign it ))))

 
A100:

The first simple test shows

that it's not sugar, but a different... more liquid substance

Good man. Where are the statistics of your freelance work, your products in the marketplace, your publications concerning programming? Or are you trying to open someone's eyes on the topic of constant pointers, or flashing your knowledge on the subject of substance types...? In the future, please consider the context of the examples, rather than trying to reproduce a compiler error.
 
Vladimir Simakov:
Dear man. Where are the statistics of your freelance jobs, products in the marketplace, publications related to programming? Or are you trying to open someone's eyes on the topic of constant pointers, or flashing your knowledge on the topic of substance types ...? In the future, please consider the context of the examples, rather than trying to reproduce a compiler error.

I have a simple context: If the code (in this case a macro) is written with an error, I think it is possible to report it (and give an example to prove it). And in this context it is not clear to me whatthe statistics have to do with it

 
A100:

And in this context it is not clear to me what the statistics have to do with it.

Keep it simple and people will come to you.

;)

SZZY: Your posts are almost always a good idea, but the presentation of material, well, not entirely with good intentions, of course your business, but imho, want to help - help, want to be clever, well, often it turns out so

It's up to you, but boosting your self-esteem with online resources - .... I'm too lazy to keep typing.

Reason: