What is the calculation to move a stop with the SuperTrend line?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5102 quote
    minmax
    Participant
    Average

    Can anyone please help me with the code/formula to trail my stop into profit along with the SuperTrend line.

    I was hoping that ProRealtime would allow me to specify a level for my stop, (i.e. set stop loss 17000), but it looks like that isn’t possible.

    Regards

    Steve

    #5111 quote
    Nicolas
    Keymaster
    Master

    Of course it is already possible to set a trailing stop on an indicator line, just like the SuperTrend. You have to define the distance between the Close and the indicator to reflect the new stop at each bar, like a dynamic stoploss.

    Example :

    defparam cumulateorders=false
    
    //indi
    st = SuperTrend[3,10]
    
    // case BUY
    IF close>st THEN
     BUY 1 LOT AT MARKET 
    ENDIF
    
    SET STOP TRAILING Close-st

     

    As you can see on the picture attached, the stoploss of the buy order is moving correctly with the supertrend line. Hope it helps.

    supertrend-stoploss.png supertrend-stoploss.png
    #5200 quote
    minmax
    Participant
    Average

    Thanks Nicolas, I’ve tried that, I get an error from the system that the trading system has to be stopped because it tried to put the stop at a negative level (but or sell both give the same error) Any ideas?

    If I make an indicator to show the position of the stop loss it will show the correct position, but if I try to use set stop trailing SuperTrend[3,10] then it sets the stop 7200 pips away, so it seems like the system is using some other value for SuperTrend?

    Regards

     

    Steve

    #5202 quote
    Nicolas
    Keymaster
    Master

    If Close is above the supertrend and you are in buying conditions, this code should do the trick. But if you are using the same one for short orders, you’ll have negative values indeed! Because SuperTrend is above the price when you sell the instrument. You should use these lines instead in your code :

    IF LONGONMARKET THEN 
     SET STOP TRAILING Close-st
    ENDIF
    
    IF SHORTONMARKET THEN 
     SET STOP TRAILING st-Close
    ENDIF
    #39744 quote
    Seb
    Participant
    Average

    Unfortunately this method of trailing stop is not effective when I try it:

    defparam cumulateorders=false
    
    st = SuperTrend[3,10]
    
    IF close crosses over st THEN
    BUY 1 LOT AT MARKET
    ENDIF
    
    IF LONGONMARKET THEN
    SET STOP TRAILING Close - st
    ENDIF
    
    IF close crosses under st THEN
    Sellshort 1 LOT AT MARKET
    ENDIF
     
    IF SHORTONMARKET THEN
    SET STOP TRAILING st - Close
    ENDIF
    USD-Mini-.png USD-Mini-.png
    #39754 quote
    Nicolas
    Keymaster
    Master

    You can give a try to this method also: https://www.prorealcode.com/blog/learning/moving-stoploss-dynamic-informations-proorder/

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

What is the calculation to move a stop with the SuperTrend line?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
minmax @minmax Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/08/2016
Status: Active
Attachments: 2 files
Logo Logo
Loading...