Supertrend stop loss

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #217693 quote
    SVK
    Participant
    Junior

    Hi all,

    again I have run out of talent so I’m turning to you knowledgable guys for help.

     

    I’m trying to create stop loss based on supertrend indicator.

    Long condition can be executed once bar closes above Supertrend 2 – 11 or Supertrend 3 – 12.

    If long is executed at Supertrend 2 – 11 then stop loss needs to be placed at 2 -11.

    If long is executed at Supertrend 3 – 12 then stop loss needs to be placed at 3 -12.

     

    I have run the strategy with folowing code:

    IF NOT shortOnMarket and Trigger AND CondiLong1 and CondiLong2 AND TradingON THEN
    BUY 1 PERPOINT AT MARKET
    StopInd = close-SuperTrend[3,12]
    ENDIF
    
    
    // Stops and targets
    SET STOP pLOSS StopInd
    SET TARGET pPROFIT StopInd *1.6

    Problem is that Supertrend 3 – 12 is not always below the bar close so I have caught a trade with no stop loss set 🙁

    Would anyone know how to code this for Long and Short trading please ?

    Thank you very much for the help

    #217710 quote
    ProRealAlgos
    Participant
    Junior

    What do you want to happen if the supertrend is bigger than the close? The code below catches such cases and sets the stoploss to 30 points.

    IF NOT shortOnMarket and Trigger AND CondiLong1 and CondiLong2 AND TradingON THEN
    BUY 1 PERPOINT AT MARKET
    StopInd = close-SuperTrend[3,12]
    ENDIF
     
    If Stopind < 0 then 
    Stopind = 30
    Endif
     
    // Stops and targets
    SET STOP pLOSS StopInd
    SET TARGET pPROFIT StopInd *1.6
    SVK thanked this post
    #217720 quote
    SVK
    Participant
    Junior
    Hi ProrealAlgos,   many thanks for your response. I was thinking of having two options for stop loss. StopInd 1 = closeSuperTrend[3,12] StopInd 2 = closeSuperTrend[2,11]   If trade is executed and SuperTrend[3,12] is above Close then Stop loss is placed at  SuperTrend[2,11] level. If trade is executed and SuperTrend[3,12] is below Close then Stop loss is placed at  SuperTrend[3,12] level.
    #217730 quote
    Nicolas
    Keymaster
    Master
    If trade is executed and SuperTrend[3,12] is above Close then Stop loss is placed at  SuperTrend[2,11] level. If trade is executed and SuperTrend[3,12] is below Close then Stop loss is placed at  SuperTrend[3,12] level.
    Find below the code to achieve this:
    if SuperTrend[3,12]>close then 
     set stop price SuperTrend[2,11]
    else
     set stop price SuperTrend[3,12]
    endif 
    
    SVK thanked this post
    #217797 quote
    SVK
    Participant
    Junior
    Nicolas, thank you very much for your help. Unfortunately I must be doing something wrong as it doesn’t work. I have insrted your code like this:
    //
    IF NOT shortOnMarket and Trigger AND CondiLong1 and CondiLong2 AND TradingON and DayLimit  THEN
    BUY 1 PERPOINT AT MARKET
    if SuperTrend[3,12]>close then
    set stop price SuperTrend[2,11]
    else
    set stop price SuperTrend[3,12]
    endif
    ENDIF
        This way code just keeps following Supertrend and doesn’t place stop loss at the trigger bar.
    Screenshot-2023-07-17-231623.jpg Screenshot-2023-07-17-231623.jpg
    #217809 quote
    Nicolas
    Keymaster
    Master
    Because you have wrongly coded the conditions, the IF statement is entered and therefore the stoploss is updated with the SET STOP PRICE instruction. Replace IF NOT shortOnMarket with IF NOT longOnMarket
    SVK thanked this post
    #217844 quote
    SVK
    Participant
    Junior
    Thank you very much Nicolas.   Can I run Long and Short strategies at the same time on the same instrument with IF NOT longOnMarket ?
    #217848 quote
    GraHal
    Participant
    Master
    Yes if you use something like below …
    IF NOT shortOnMarket AND ShortCond Then
    SellShort at Market
    Endif
    
    IF NOT longOnMarket AND LongCond Then
    Buy at Market
    Endif
    SVK thanked this post
    #217851 quote
    SVK
    Participant
    Junior
    Thank you very much Grahal.   Now I’m trying to figure out how to place profit target at *1.5 of a set stop price. So far 1 hour and 7 minutes and I’m nowhere. LOL
    //
    IF NOT longOnMarket and Trigger AND CondiLong1 and CondiLong2 AND TradingON and DayLimit  THEN
    BUY 1 PERPOINT AT MARKET
    if SuperTrend[3,12]>close then
    set stop price SuperTrend[2,11]
    else
    set stop price SuperTrend[3,12]
    endif
    ENDIF
    #217853 quote
    GraHal
    Participant
    Master
    Yes coding is very time consuming, especially if at the end of a few hours there  isn’t  a working result! Have you tried below … set stop price (SuperTrend[2,11] + (0.5*SuperTrend[2,11])) But do you really mean 1.5*Price anyway?   Taking DJI at 35,000 this gives 52,500 for 1.5*Price??
    SVK thanked this post
    #217854 quote
    SVK
    Participant
    Junior
    Thanks Grahal. Nope nope that would be crazy 🙂 If stop loss is placed at Supertrend 3,12 then profit is 1.5* of a stop loss. So Spuertrend 3,12 stop loss is 10 points then take profit is 15 points.
    #217855 quote
    GraHal
    Participant
    Master
    Ah right gotcha, sorry watching a film at same time so not concentrating. How about below …
    IF NOT longOnMarket and Trigger AND CondiLong1 and CondiLong2 AND TradingON and DayLimit  THEN
    BUY 1 PERPOINT AT MARKET
    if SuperTrend[3,12]>close then
    set stop price SuperTrend[2,11]
    else
    set stop price SuperTrend[3,12]
    Set Target Price (Close + ((Close -  SuperTrend[2,11]) *1.5))
    endif
    ENDIF
    SVK thanked this post
    #217874 quote
    SVK
    Participant
    Junior
    Grahal,   it works and it improved the forward testing results 🙂 Thank you very much for that 🙂
    GraHal thanked this post
Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.

Supertrend stop loss


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
SVK @svk Participant
Summary

This topic contains 12 replies,
has 4 voices, and was last updated by SVK
2 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 07/15/2023
Status: Active
Attachments: 1 files
Logo Logo
Loading...