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

Development of Automated Strategy with a SL at Previous Candle Low

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

    Development of Automated Strategy with a SL at Previous Candle Low

    Hello,

    I hope my message finds you well. I am trying to develop a new strategy in the strategy builder, that if all of my conditions are true it enters a long position.
    In regards to risk management, I would like to set a SL at the Previous Candle Low.
    So basically, if my entry Long is at Close Candle 0, the Stop Loss would be set at Low Candle 1.
    Would you be able to help me?

    Thank you very much





    #2
    Hello NorwegianCat92,

    Welcome to the NinjaTrader forums!

    To do this, you will need to use exit orders in the conditions and actions page of the Strategy Builder.

    Add a double variable on the Inputs and variables page to store the price for the order, and when the position is long set the variable to Price -> Low, with Bars ago set to 1.

    Below is a link to an example script that sets a stop market order based on a calculated value, and also demonstrates breakeven and trailing behavior.


    I am also including a link to a forum post with helpful resources such as training videos on getting started with C# and NinjaScript.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thank you very much for your response. Is this the area where I have to add the double variable? And is it correct?
      Thank you
      Attached Files

      Comment


        #4
        Hello NorwegianCat92,

        Yes, the variable you have named Long is in the correct place and is the correct type.

        In the Condition Builder you will see this in the User variables, in the Actions you will see this in the Misc section.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          Thank you very much for your help yesterday. However, I feel a bit lost... after having added the Long double variable (In Input and Variable Section), as I showed you yesterday, I don't know what I have to do in the Conditions and Actions section.
          Would you be able to help me?

          Thank you a lot for your availability.
          Attached Files

          Comment


            #6
            Hello NorwegianCat92,

            Have a look at Set 3 in the BreakEvenBuilderExample.

            The StopPrice variable used for the stop price of the order, is set when the position is long, and is set to the position average price (entry price) plus the number of ticks for the distance (which defaults to -10).

            You would be assigning this to Price -> Low with Bars ago set to 1 instead.
            (You likely need additional logic in another condition set to ensure that Low[1] is a valid price and is less than the Price -> Current bid to prevent the order from be rejected due to an invalid stop price.)

            Then in Set 5 the order is submitted using the StopPrice variable in the Stop price parameter of the order.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Nicholewatkinsi, Today, 10:53 PM
            0 responses
            5 views
            0 likes
            Last Post Nicholewatkinsi  
            Started by dward123, 01-02-2024, 09:59 PM
            4 responses
            175 views
            0 likes
            Last Post Lancer
            by Lancer
             
            Started by ETFVoyageur, Today, 04:00 PM
            2 responses
            19 views
            0 likes
            Last Post ETFVoyageur  
            Started by AaronKTradingForum, Today, 03:44 PM
            1 response
            14 views
            0 likes
            Last Post AaronKTradingForum  
            Started by Felix Reichert, 04-26-2024, 02:12 PM
            11 responses
            80 views
            0 likes
            Last Post Felix Reichert  
            Working...
            X