Wait for specific event before placing a new Buy Stop

Forums ProRealTime English forum ProOrder support Wait for specific event before placing a new Buy Stop

Viewing 11 posts - 1 through 11 (of 11 total)
  • #214454

    Hello,

     

    I have a hard time finding how to write what I want, simply put let’s say we have a Simple Moving Average 20 Period and a Simple Moving Average 50 Period.

    How could I do so when the SMA20 > SMA50 and close < SMA50 a BUY x SHARES AT SMA50 STOP is placed on the SMA50 and if the buy stop is reached and the shares bought, then wait for SMA20 to go below SMA50 then come back above before placing a new buying stop on SMA50? So if SMA20 > SMA50 and close keep going above and below SMA50, only the first time close was below SMA50 the buy stop was placed

     

    It’s the waiting part once a buy stop has been reached that is causing me an issue 😕 If I enter and exit on the same candle I can’t just call IF LongOnMarket and setup a flag telling me I already entered in position, since I will not be LongOnMarket anymore when reaching this condition I believe

    #214456

    If I enter and exit on the same candle I can’t just call IF LongOnMarket and setup a flag telling me I already entered in position, since I will not be LongOnMarket anymore when reaching this condition I believe

    The solution comprises two parts (pseudo code) :

    This is a quick and dirty of course, but I assume sufficient for you to fully work out.

    Checking for having been OnMarket within a candle is always a hassle and depending on whether you applied other stuff, my example must be adjusted.
    N.b.: IMO it is an omission that PRT does not provide a simple “HasTraded” as a Boolean telling you that a trade occurred in the last bar.

    Hint : keep on checking your Ticks in the Optimization Result window. Each count in there implies a “too positive” result, as in-bar multiple trades can not be tracked correctly by PRT. At least always cause the Ticks to be on as per the Editor window checkbox, and ALWAYS backtest from within the button on that window (or else results are erroneous).

    1 user thanked author for this post.
    #214459

    PRT does not provide a simple “HasTraded” as a Boolean

     

     

    2 users thanked author for this post.
    #214478

    Yes, but that would be the same as an If OnMarket which was not true the previous call, right ?

    So it remains a kind of a hassle to know whether two events happened (even three can occur) within the bar. An Enter followed by an Exit would not be unambiguously covered with anything.

     

    #214631

    1
    2
    LongTriggered[N]
    ShortTriggered[N]

    no good Snippet link about this fonction LongTriggered ?

    #214633

    1

    2

    LongTriggered[N]

    ShortTriggered[N]

    no good Snippet link about this fonction LongTriggered ?

    That is quite easy to use :

    • LongTriggered is True if we entered long on the current candle (otherwise False)
    • LongTriggered[1] is True if we entered long on the last candle (otherwise False)
    • etc

     

    So one way to use it could be

    Just an example, it would be dangerous to use that if the last candle was finally bearish and the SL was put too late

    1 user thanked author for this post.
    #214635

    @aldtrading tks you,

    I want somethink maybe more complicated 😊

    #214636

    Are there no SellTriggered and ExitShortTriggered variables so I can know when instructions like SELL x SHARES AT y STOP (to exit partially from a position) have been triggered and act accordingly?

    #214638

    you can use CountOfPosition of the current candle and the previous candle to compare the size of the position maybe 😊

    1 user thanked author for this post.
    #214639

    Yep I came up with something like this too, just making sure because I found it funny we have the implementation for when entering the positions but not for when exiting them 😁

    #214659

    don’t forget to use ABS when Short :

    1 user thanked author for this post.
Viewing 11 posts - 1 through 11 (of 11 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login