Set stop loss to an indicator.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #168541 quote
    VelociraptuxVelociraptux
    Participant
    New
    Hi. I try to adjust my stoploss to my second closest supertrend to the price. But I can’t. Does anyone have an idea? Thank you
    DEFPARAM FLATAFTER = 224500
    DEFPARAM CUMULATEORDERS = False
    
    once startt = 000000
    once endt = 220000
    
    // SUPERTREND
    st1 = Supertrend[1,10]
    st2 = Supertrend[2,11]
    st3 = Supertrend[3,12]
    
    // SUPERTREND CONDITIONS
    stl = 0
    sts = 0
    
    IF st1 < close AND st2 < close THEN
    stl = 1
    ENDIF
    IF st1 < close AND st3 < close THEN
    stl = 2
    ENDIF
    IF st2 < close AND st3 < close THEN
    stl = 3
    ENDIF
    IF st1 < close AND st2 < close AND st3 < close THEN
    stl = 4
    ENDIF
    
    
    // SOTP LOSS CONDITIONS
    IF stl = 1 AND st1 < st2 THEN
    sll = st1
    ELSE
    sll = st2
    ENDIF
    IF stl = 2 AND st1 < st3 THEN
    sll = st1
    ELSE
    sll = st3
    ENDIF
    IF stl = 3 AND st2 < st3 THEN
    sll = st2
    ELSE
    sll = st3
    ENDIF
    IF stl = 4 THEN
    sll = st2
    ENDIF
    
    // POSITIONS CONDITIONS
    IF time >= startt AND time <= endt THEN
    IF not onmarket AND stl >= 1 THEN
    buy 1 contract at market
    set stop loss (tradeprice - sll)
    SET TARGET PPROFIT 45
    ENDIF
    
    #168545 quote
    robertogozzirobertogozzi
    Moderator
    Legend
    I suggest computing the middle of their range like that, for line 54:
    set stop loss ((tradeprice - ((st1 + st2 + st3) / 3))
    Velociraptux thanked this post
    #168547 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    There’s a major issue, TRADEPRICE is not known when BUY is executed, until the next candle.

    Due to this it will retain the exit price of the prior trade or 0 the very first time making the stop loss negative.

    To overcome this I’d change line 54 using the current price and saving the ST value for a later use:

    MyST = (st1 + st2 + st3) / 3)
    set stop loss (close - MyST)
    then I would append these lines at the end, for the next candle:
    If OnMarket and Not OnMarket[1] then
       set stop loss (tradeprice - MyST)
    Endif
    This will grant you an initial stop loss, making it more accurate next candle.
    Velociraptux thanked this post
    #169201 quote
    VelociraptuxVelociraptux
    Participant
    New
    Thank you Roberto.
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Set stop loss to an indicator.


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/02/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...