Wait for specific event before placing a new Buy Stop

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #214454 quote
    aldtrading
    Participant
    New

    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 quote
    PeterSt
    Participant
    New

    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) :

    Once PutLimit = 0
    NewOrderGoodToGo = 0
    
    If PutLimit then   // Check whether order was filled.
      If StrategyProfit <> StrategyProfit[1] then   // Somehthing changed ?
        // This either tells you're OnMarket now, or that you're foo already again.
        If Not OnMarket then
          // Prepare condition for new Order.
          NewOrderGoodToGo = 1
        endif
      endif
      PutLimit = 0   // Reset.
    endif
    
    [...]
    
    If NewOrderGoodToGo and MySMAConditions then
      Buy At MyPrice Limit
      PutLimit = 1
    endif
    
    NewOrderGoodToGo = 0   // Reset.
    

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

    aldtrading thanked this post
    #214459 quote
    GraHal
    Participant
    New

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

     

    LongTriggered[N]
    ShortTriggered[N]
    aldtrading and ZeroCafeine thanked this post
    #214478 quote
    PeterSt
    Participant
    New

    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 quote
    ZeroCafeine
    Participant
    Senior

    1
    2
    LongTriggered[N]
    ShortTriggered[N]

    no good Snippet link about this fonction LongTriggered ?

    #214633 quote
    aldtrading
    Participant
    New

    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

    //If we entered Long on the last candle
    //Then put a Stop Loss 1 pip below the last candle
    
    IF LongTriggered[1] THEN
       SET STOP Price low[1] - 1*PointSize
    ENDIF

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

    ZeroCafeine thanked this post
    #214635 quote
    ZeroCafeine
    Participant
    Senior

    @aldtrading tks you,

    I want somethink maybe more complicated 😊

    #214636 quote
    aldtrading
    Participant
    New

    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 quote
    ZeroCafeine
    Participant
    Senior

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

    aldtrading thanked this post
    #214639 quote
    aldtrading
    Participant
    New

    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 quote
    ZeroCafeine
    Participant
    Senior

    don’t forget to use ABS when Short :

    abs(COUNTOFPOSITION)
    aldtrading thanked this post
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

Wait for specific event before placing a new Buy Stop


ProOrder support

New Reply
Author
author-avatar
aldtrading @aldtrading Participant
Summary

This topic contains 10 replies,
has 4 voices, and was last updated by ZeroCafeine
2 years, 8 months ago.

Topic Details
Forum: ProOrder support
Language: English
Started: 05/10/2023
Status: Active
Attachments: No files
Logo Logo
Loading...