If longonmarket, needed or not?

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #47393 quote
    Mansoor
    Participant
    Average

    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.

    1. If longonmarket Then
    2. Sell At Market
    3. Endif
    #47395 quote
    Mansoor
    Participant
    Average

    I haven’t tested this myself. I could be wrong!

    #47396 quote
    robertogozzi
    Moderator
    Master

    I have tested it and it seems true!

    I am not aware of any drawbacks.

    #47397 quote
    AVT
    Participant
    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.

    #47399 quote
    juanj
    Participant
    Master

    @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.

    #47408 quote
    AVT
    Participant
    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.

    #47425 quote
    Derek
    Participant
    Veteran

    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.

    #47429 quote
    AVT
    Participant
    Senior

    @Derek good point! We just looked onto one aspect of it, forgetting the other – you never know what happens, even here :-))

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

If longonmarket, needed or not?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mansoor @mansoor Participant
Summary

This topic contains 7 replies,
has 5 voices, and was last updated by AVT
8 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/26/2017
Status: Active
Attachments: No files
Logo Logo
Loading...