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

Stop Loss (Fix and Trailing)

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

    Stop Loss (Fix and Trailing)

    Hello,

    I'm recently working on an automated strategy that involves using super trend indicators (attached). I have difficulties adding my stop loss. I have 2 types of entry, 1stEntryLong, and 2ndEntryLong.

    For 1stEntryLong:
    1) Stop loss to be set at the swing low.
    2) Once the low and high of the candle is above the entry price, move the stop loss to 1 tick in profit.
    3) If the next supertrend green line goes above the 1 tick stop loss profit, the stop loss follows the supertrend line.

    For 2ndEntryLong
    1) Set stop loss as the green supertrend line.
    2) Stop loss adjusts to follow the green supertrend line. So it will be constantly changing following the supertrend.

    Can this be done using the strategy builder? If we need to unlock the code, can you assist in showing me how this will be coded?

    I have attached the strategy that I have created so far using the Strategy Builder. Appreciate the help.
    Attached Files

    #2
    Hello neshnix89,

    Thanks for your post.

    You would likely need to create multiple double variables in the Inputs and Variables screen to hold the entry price of your Entry order when it is submitted, the swing low value from the Swing indicator, and the SuperTrend indicator value.

    To save the entry price of your Entry order, you would assign the Close[0] price to a double variable in the same Set as your Entry order method, after the Entry order method is called. This way, the strategy will place the EnterLong/EnterShort order at the Close[0] price and then the Close[0] price would be saved to your double variable.

    These double variables could then be used to set up conditions and actions in the Conditions and Actions screen of the Strategy Builder.

    Note that you would need to use Exit order methods, not Set methods, to create your Profit Target and Trailing Stop logic.

    Please note that you would not be able to use the Exit methods and the Stops in the Stop and Targets window as that creates a violation of the Managed Approach Internal Order Handling Rules, linked here: https://ninjatrader.com/support/help...d_approach.htm

    My colleague Chelsea has created educational examples of Strategy Builder Breakeven and Trailing Stop in the Strategy Builder here:
    https://ninjatrader.com/support/foru...der#post806596

    Also, see the help guide documentation below for more information about working with the Strategy Builder.

    Strategy Builder Screens: https://ninjatrader.com/support/help...er_screens.htm
    Conditions: https://ninjatrader.com/support/help...on_builder.htm
    Actions: https://ninjatrader.com/support/help...t8/actions.htm

    Let us know if we may assist further.​
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by neshnix89 View Post
      Hello,

      I'm recently working on an automated strategy that involves using super trend indicators (attached). I have difficulties adding my stop loss. I have 2 types of entry, 1stEntryLong, and 2ndEntryLong.

      For 1stEntryLong:
      1) Stop loss to be set at the swing low.
      2) Once the low and high of the candle is above the entry price, move the stop loss to 1 tick in profit.
      3) If the next supertrend green line goes above the 1 tick stop loss profit, the stop loss follows the supertrend line.

      For 2ndEntryLong
      1) Set stop loss as the green supertrend line.
      2) Stop loss adjusts to follow the green supertrend line. So it will be constantly changing following the supertrend.

      Can this be done using the strategy builder? If we need to unlock the code, can you assist in showing me how this will be coded?

      I have attached the strategy that I have created so far using the Strategy Builder. Appreciate the help.
      Hey neshnix, I have had the same problem and wondered if you found a solution to this. https://ninjatrader.com/support/foru...or#post1226118

      I am not sure how to create double variables that reference previous candle highs and lows.

      Comment


        #4
        Hello RallySquirrel,

        Thanks for your note.

        I understand that you want to create two double variables and assign the previous candle's High price and the previous candle's Low price to those variables.

        Double variables named something like PrevHighPrice and PrevLowPrice can be created on the Inputs and Variables screen of the Strategy Builder.

        Then, in the Actions section of the Conditions and Actions screen of the Builder, you could assign the High price and Low price with a BarsAgo value of 1 to those variables. Supplying a BarsAgo value of 1 when using a price will access that price value of the previous candle (High[1] or Low[1]).

        See the attached example script demonstrating this. The example scripts saves the previous High price and previous Low price to double variables. Then, draws text on the chart to display the value of those variables.

        To see the generated syntax to accomplish this, you could click the 'View code' button in the Strategy Builder when viewing the script.

        See the help guide documentation below for more information about working with the Strategy Builder.

        Strategy Builder Screens: https://ninjatrader.com/support/help...er_screens.htm
        Conditions: https://ninjatrader.com/support/help...on_builder.htm
        Actions: https://ninjatrader.com/support/help...t8/actions.htm

        Here is a link to our publicly available training video, 'Strategy Builder 301', for you to view at your own convenience.

        Strategy Builder 301 — https://www.youtube.com/watch?v=_KQF2Sv27oE&t=13s

        If you are new to C#, to get a basic foundation for the concepts and syntax used in NinjaScript I would recommend this section of articles in our help guide first:
        https://ninjatrader.com/support/help...g_concepts.htm

        Let me know if I may assist further.
        Attached Files
        Last edited by NinjaTrader_BrandonH; 12-05-2022, 03:33 PM.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_BrandonH View Post
          Hello RallySquirrel,

          Thanks for your note.

          I understand that you want to create two double variables and assign the previous candle's High price and the previous candle's Low price to those variables.

          Double variables named something like PrevHighPrice and PrevLowPrice can be created on the Inputs and Variables screen of the Strategy Builder.

          Then, in the Actions section of the Conditions and Actions screen of the Builder, you could assign the High price and Low price with a BarsAgo value of 1 to those variables. Supplying a BarsAgo value of 1 when using a price will access that price value of the previous candle (High[1] or Low[1]).

          See the attached example script demonstrating this. The example scripts saves the previous High price and previous Low price to double variables. Then, draws text on the chart to display the value of those variables.

          To see the generated syntax to accomplish this, you could click the 'View code' button in the Strategy Builder when viewing the script.

          See the help guide documentation below for more information about working with the Strategy Builder.

          Strategy Builder Screens: https://ninjatrader.com/support/help...er_screens.htm
          Conditions: https://ninjatrader.com/support/help...on_builder.htm
          Actions: https://ninjatrader.com/support/help...t8/actions.htm

          Here is a link to our publicly available training video, 'Strategy Builder 301', for you to view at your own convenience.

          Strategy Builder 301 — https://www.youtube.com/watch?v=_KQF2Sv27oE&t=13s

          If you are new to C#, to get a basic foundation for the concepts and syntax used in NinjaScript I would recommend this section of articles in our help guide first:
          https://ninjatrader.com/support/help...g_concepts.htm

          Let me know if I may assist further.
          Very helpful. Thank you

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DJ888, 04-16-2024, 06:09 PM
          4 responses
          11 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by terofs, Today, 04:18 PM
          0 responses
          5 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by nandhumca, Today, 03:41 PM
          0 responses
          5 views
          0 likes
          Last Post nandhumca  
          Started by The_Sec, Today, 03:37 PM
          0 responses
          3 views
          0 likes
          Last Post The_Sec
          by The_Sec
           
          Started by GwFutures1988, Today, 02:48 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Working...
          X