Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to use SuperTrend as a StopLoss in my strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to use SuperTrend as a StopLoss in my strategy

    Hi Guys,

    I need some help.

    I would like to be able to use the attached indicator (SuperTrendU11.zip) as a stoploss for my strategy. To keep things simple, assume my strategy is a moving average cross over, as the SampleMACrossOver that comes with the NinjaTrader standard package, code below:

    Code:
    		protected override void OnBarUpdate()
    		{
    			if (CrossAbove(SMA(Fast), SMA(Slow), 1))
    			    EnterLong();
    			else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
    			    EnterShort();
    		}

    How could I modify the SuperTrendU11 code in order to generate the plotlines (Uptrend or Downtrend) ONLY when my strategy EnterLong or EnterShort?


    This query might not be immediately clear, but if you plot the indicator, you will notice that the plotlines, that I would like to use as stoploss for my strategy are only generated in case of stoploss event (close crossing above/below plotline) that not always coincides with what my strategy is doing. (e.i. strategy could be going long, whilst SuperTrendU11 plots a short stoploss plotline (Downtrend), rather than a new long stoploss plotline (Uptrend) as I would like.

    Thanks
    Attached Files

    #2
    Hello sburtt,

    It already had plot lines so you would not have modify any code inside of the SuperTrendU11 Indicator since stopdot and stopline are both plot values, but you will want to make sure that the value of the SuperTrendU11 is rounded to a tick value so that you may set your stop loss to the correct value. For this you can use the Rount2TickSize() method. Here is a link to our Help Guide that show how to use the Round2TickSize() method that you may view.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JC View Post
      Hello sburtt,

      It already had plot lines so you would not have modify any code inside of the SuperTrendU11 Indicator since stopdot and stopline are both plot values, but you will want to make sure that the value of the SuperTrendU11 is rounded to a tick value so that you may set your stop loss to the correct value. For this you can use the Rount2TickSize() method. Here is a link to our Help Guide that show how to use the Round2TickSize() method that you may view.
      http://www.ninjatrader.com/support/h...sub=Round2Tick
      JC, this is useful thanks. However what I am really trying to do here is to START plotting the stopline and dotline values from the moment my strategy enters a trade (rather that from the moment it gets stopped, as it's currently coded). I assume that for this I would need to manipulate the original code of the indicator to change the trigger to start plotting the stopline. Am I right saying this?

      Comment


        #4
        Hello sburtt,

        You may want to just use a Strategy Plot and once in a trade set the value of the SuperTrendU11 Indicator to the Strategy Plot. This is way you can make sure that you are in a position before it can be plotting. Here is a thread that demonstrates how to use a Strategy Plot that you may view.
        When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability
        JCNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ETFVoyageur, Today, 02:10 AM
        0 responses
        7 views
        0 likes
        Last Post ETFVoyageur  
        Started by rayyyu12, Today, 12:47 AM
        0 responses
        7 views
        0 likes
        Last Post rayyyu12  
        Started by ETFVoyageur, 05-07-2024, 07:05 PM
        17 responses
        136 views
        0 likes
        Last Post ETFVoyageur  
        Started by ETFVoyageur, Yesterday, 10:13 PM
        1 response
        10 views
        0 likes
        Last Post ETFVoyageur  
        Started by somethingcomplex, Yesterday, 10:36 PM
        0 responses
        10 views
        0 likes
        Last Post somethingcomplex  
        Working...
        X