Bonjour!
I noticed most people here use the following conditional statement in their codes. I think lines 1 and 3 are redundant. According to PRT help Sell command has no effect if there is no long position. Same with Exitshort.
- If longonmarket Then
- Sell At Market
- Endif
I haven’t tested this myself. I could be wrong!
I have tested it and it seems true!
I am not aware of any drawbacks.
AVTParticipant
Senior
First, you have to obey the syntax in a programming language. And in PRT the syntax for simple IF is:
IF condition THEN
action
ENDIF
wheras in other languages syntax might be:
if(condition) action;
So far for syntax.
Now for contents: IF conditions are written for every, really every imaginable case that could eventually happen. This does not mean, those cases must all happen. It is just an insurance for the case we have such an event.
Example: There is a box where a user should enter his age. We write an IF condition:
IF userinput != Number THEN
print “I want your age as a number, not as a joke”
ENDIF
Now think about your argumentation; right, if the user enters a number we don’t have to tell him to do what we want. And maybe it is so obvious that people will never get the idea to enter anything else than for example 19 or 56.
But is it therefore redundant? No. Because there might be a case where someone enters twenty or just middleage or whatever he wants.
Same applies to long on market. If there’s no long position, ok nothing to sell. But you never know what happens, so for the case that there is a long position we sell it and are safe.
@Mansoor, you are probably right, however, I tend to agree with @AVT, just because something works doesn’t mean it is good practice.
Especially with large pieces of code with multiple entry/exit conditions various points, a rogue piece of sell at market code can really mess things up.
So for me personally it simply comes down to good coding standards and habits.
AVTParticipant
Senior
Usually the underlying, executing program (in this case PRT) should return an error code, if it receives a command which cannot be exectuted. With a simple Sell at Market where there is no Long position to sell, the answer should be something like “no existing long position to sell”. To avoid such a case we need the IF statement. Don’t know whether PRT returns such error codes.
I guess leaving the if statement out of the equation will lead to a sell order after the first bar being long on the market.
If that’s what you want then stick to it.
AVTParticipant
Senior
@Derek good point! We just looked onto one aspect of it, forgetting the other – you never know what happens, even here :-))