Errors, bugs, questions - page 1887

 
Vladimir Karputov:

You, as I see it, have not checked the code I showed you. Let's put it this way: you check it first, then ask the question again.

I don't need to verify it, I can see that it returns what it should.

I was talking about the first use of the function

 
Alexandr Bryzgalov:

I don't need to verify it, I can see that it returns what I need

I was talking about the first variant of using the function


Ok, then. Let's go from the tail.

1. PositionGetInteger:

The function returns the requested property of an open position previously selected using the function...

That is, before using PositionGetInteger, the position must first be selected.


2. We select the position using the PositionGetTicket:

Return value.

The position ticket. In case of an unsuccessful execution it returns 0.


And where do you have a check (after the loop) that there was returned from PositionGetTicket? There is no check, and there, by the way, "zero" is returned - that is, PositionGetTicket was triggered with an error - which is tantamount to selecting a position that does not exist. Then, without checking the result of PositionGetTicket, you try to get its property from the non-existent position. And there, in the non-existent position's properties, either rubbish or just data of null structures.


To sum it up: without checking whether the PositionGetTicket returns "zero", you can't go further.

 
Vladimir Karputov:


Ok, then. Let's go from the tail.

1. PositionGetInteger:

The function returns the requested property of an open position previously selected using the function...

That is, the position must first be selected before using PositionGetInteger.


2. We select the position using the PositionGetTicket:

Return value.

The position ticket. In case of an unsuccessful execution it returns 0.


And where do you have a check (after the loop) that there was returned from PositionGetTicket? There is no check, and there, by the way, "zero" is returned - that is, PositionGetTicket was triggered with an error - which is tantamount to selecting a position that does not exist. Then, without checking the result of PositionGetTicket, you try to get its property from the non-existent position. And there, in the non-existent position's properties, either rubbish or just data of null structures.


To summarize: without checking the PositionGetTicket to return "zero", you can't go any further.

Thank you, very detailed and helpful.
 
Vladimir Karputov:


Ok, let's go like this. Let's go from the tail.

1. PositionGetInteger:

The function returns the requested property of an open position previously selected using the function...

That is, the position must first be selected before using PositionGetInteger.


2. We select the position by using the PositionGetTicket:

Return value.

The position ticket. In case of an unsuccessful execution it returns 0.


And where do you have a check (after the loop) that there was returned from PositionGetTicket? There is no check, and there, by the way, "zero" is returned - that is, PositionGetTicket was triggered with an error - which is tantamount to selecting a position that does not exist. Then, without checking the result of PositionGetTicket, you try to get its property from the non-existent position. And there, in the non-existent position's properties, either rubbish or just data of null structures.


To sum it up: without checking the PositionGetTicket for the return of "zero", you can't go any further.

don't need to explain yourself )

That's not the question.

read correctly: is it ok for a function to return the same value for different situations?

is it ok for the function to do that?
 
Vladimir Karputov:

To sum it up: without checking PositionGetTicket for a return of "zero" you cannot move on.

You can

Forum on trading, automated trading systems and strategy testing

Bugs, bugs, questions

fxsaber, 2017.05.12 11:19

it is logical to do a check (PositionGetInteger(POSITION_TICKET) > 0).
 
Alexandr Bryzgalov:

that function for different situations returns the same value?

is it correct that the function does this?
Unfortunately, yes.

Forum on trading, automated trading systems and strategy testing

Bugs, bugs, questions

fxsaber, 2017.05.12 11:29

Yes. But any other value would also be misleading.
 
Alexandr Bryzgalov:

1. you don't have to explain yourself.)

that's not the point

2. Read it right: is it ok for a function to return the same value for different situations?

is it ok for a function to do this?


1. You are a rude person who also made a mistake in your code, but does not want to admit it.

2. The function works absolutely correctly. Because it (PositionGetInteger(POSITION_TYPE)) can return only 2 values - either POSITION_TYPE_BUY orPOSITION_TYPE_SELL. But without selecting a position (and you don't select it - you don't check what exactly was selected) to demand something from (PositionGetInteger(POSITION_TYPE)) is reckless.


Bottom line: when your code is written with a logical error - you simply have no right to demand something from system functions.

 
Vladimir Karputov:

Bottom line: when your code is written with a logical error - you simply have no right to demand anything from the system functions.

A good example is when the question was never answered.
 
Vladimir Karputov:


1. You are a rude person who made a mistake in the code but won't admit it.

2. The function works absolutely correctly. Because it (PositionGetInteger(POSITION_TYPE)) can return only TWO values - either POSITION_TYPE_BUY orPOSITION_TYPE_SELL. But without selecting a position (and you don't select it - you don't check what exactly was selected) to demand something from (PositionGetInteger(POSITION_TYPE)) is reckless.


Bottom line: when your code is written with a logical error, you simply have no right to demand something from system functions.

Sorry, it's not my fault that someone cannot see the issue.

The fact that there is a deliberate error in the code is acknowledged.

And I know how to fix it.

But the question is different.

 

Why does the PositionGetInteger(POSITION_TYPE) function return a purchase value (equal to 0) instead of an error value (equal to 0) if the input parameters are not correct?

Reason: