moving sell or buy stop (not trailing stop)

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #153589 quote
    theo123
    Participant
    Junior

    Hi, Would appreciate anyone that can help on this.

    So I have the following buy code,

    IF NOT LongOnMarket AND LongEntry THEN
    BUY 1 CONTRACTS AT MARKET
    set stop ploss longSL
    
    ENDIF

    LongEntry is the event with lime green background color and the first one is my buy position with a 9.1 pips stop loss.  As you can see, there will be multiple events of LongEntry, and each one there’s a corresponding “LongSL” drawn with a segment and pips measure (i.e. 4.8, 4.4 and 4.8.

    What I want to do is to either to get the lowest LongSL in this case, 4.4pips (longSL can also be calculated as a price) OR get the latest LongSL – the 4.8pips or 104.066 – as my exit signal.  I cannot use a trailing stop loss because I work with guaranteed sto loss which are normally farther than my LongSL price.  Is there a possible solution to this?  Im thinking of a counter of the event so I can get the latest one but I dont know how to do it.

    thanks for anyone who find time to reply.

    stop.png stop.png
    #153593 quote
    robertogozzi
    Moderator
    Master

    To get the lowest longSL you can write:

    longSL = min(longSL,longSL_calculation)

    but I an not sure that’s what you want.

    A text example would be of greater help.

    #153626 quote
    theo123
    Participant
    Junior

    LongSL is calculated as

    LongSL=(Close-DonchianDown)/pipsize and LongEntry
    LongEntry=Close crossses over Tenkan
    
    PriCeSL=(Close-DonchianDown) and LongEntry
    

    There will be multiple events of LongEntry like in this scenario, 4 times (see picture).  The first one is my buy entry and with first LongSL asssigned as my stoploss.

    Now, what I want is to get the min of the suceeding LongSL (in pips) or PriceSL (price) to be exit scenario i.e 104.066

     

    The other option is to get the latest PriceSL as my exit point.

    #153627 quote
    robertogozzi
    Moderator
    Master

    To get the lowest among LongSL and PriceSL:

    LongSL = min(longSL,min(longSL[1],min(PriceSL,PriceSL[1])))

    but as you have combined that calculation with a logical operator, you will instead get either 0 or 1.

    Moreover,  at line 4 you did not use PIPSIZE (that you used at line 1)  thus probably making my line of code fail in some cases.

    If you want to be helped you need to post your code or be accurate when posting details, otherwise we can only guess.

    #153629 quote
    theo123
    Participant
    Junior

    Apology if I provide confusion for adding the PriceSL, it is not on my original code but added since I realized that the new exit cannot be based on pips but price

     

    Tenkan  =(highest[9](high)+lowest[9](low))/2
    DonchianDown=LOWEST[20](LOW[1])
    
    
    LongEntry=Close crossses over Tenkan
    ShortEntry= Close crossses under Tenkan
    
    LongSL=(Close-DonchianDown)/pipsize and LongEntry
    
    PriCeSL=(Close-DonchianDown) and LongEntry
    
    IF NOT LongOnMarket AND LongEntry THEN
    BUY 1 CONTRACTS AT MARKET
    set stop ploss longSL
    endif
    
    //this is the one I don’t know how to solve.
    movingSL=
    
    If LongOnMarket AND ShortEntry and movingSL THEN
    SELL AT MARKET
    ENDIF
     
    ENDIF
    

    so from the above, what I am trying to find is to have another exit point (MovingSL).  I will exit my position if the Price crossess under movingSL

    I intended to have the MovingSL as either:

    1. the highest (correction from my initial post) of the previous PriceSL that happne
    2. OR the latest one PriceSL recorded.

    From the attahcment you can see, 4 events of the PriceSL.  The first one is my entry point (LongEntry).

    In both option since highest is also the latest PriceSL on this picture, exit pooint should be earlier at 104.066 and not on 104.041 which is the set stop loss.

    stop2.png stop2.png
    #153907 quote
    theo123
    Participant
    Junior

    Hi Roberto, Do you know of possible solution for this.  I provide more details.

    Thanks in advance.

    #153920 quote
    Vonasi
    Moderator
    Master

    theo123 – Topic moved to ProOrder forum as it is a strategy topic and not an indicator topic. Please try to post in the correct forum with any future topics.

    _ ProRealTime Platform Support: only platform related issues.
    _ ProOrder: only strategy topics.
    _ ProBuilder: only indicator topics.
    _ ProScreener: only screener topics
    _ General Discussion: any other topics.
    _ Welcome New Members: for new forum members to introduce themselves.

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

moving sell or buy stop (not trailing stop)


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
theo123 @theo123 Participant
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Vonasi
5 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/13/2020
Status: Active
Attachments: 2 files
Logo Logo
Loading...