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

NT Strategy Builder Logic

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

    NT Strategy Builder Logic

    I'm having trouble getting my script to function correctly. Use the following chart as a reference for a visual setup and action.

    In this case, a green candle will form and the next red candle that forms will have parameters that make it the "setup candle". Once the "setup candle" closes with the required parameters, the action candle will wait until price reaches a certain requirement before placing a short stop market order. Keep reading after the following screenshot...

    Click image for larger version

Name:	mpA4L.png
Views:	70
Size:	422.7 KB
ID:	1282076

    You can see that Ninja Trader has a strategy builder in the following screenshot. It has a "conditions box" and an "action box" where you can build your strategy.

    You can see the condition called "Short" that I created. The first couple of lines make sure that I'm not already in a trade before the conditions can continue. Lines 3-8 pertain to the preceding "green candle" AND the "setup candle", 1 and 0 respectively. These calculations will be made live during the candle movement on the chart. Once the "setup candle" closes, that's where the commands in the "action box" begin.

    The actions would be:
    • Buy contracts on the "action candle" at the LOW of the previous candle which is the "setup candle" -1 TickSize
    • Exit position if the "action candle" price hits the HIGH of the previous candle which is the "setup candle"

    This script actually gets me into the trade correctly, but it will not exit the trade based on the 2nd action in the list above.

    I'm not sure if I have the logic setup correctly or not. Perhaps you can see what I'm attempting to do.

    Click image for larger version

Name:	TD6e0.png
Views:	52
Size:	374.0 KB
ID:	1282077

    #2
    Hello br0ns0n,

    Thank you for your post.

    Your set has an exit and entry on the same pass of OnBarUpdate().

    Be sure not to call an exit and then an entry on the same bar. This would cause the position to become double the opposite direction or cause an overfill.

    https://forum.ninjatrader.com/forum/...16#post1036616

    Your current set is checking for entry conditions and exit conditions and saying to enter and exit at the same time, on the same bar.

    I recommend you split your conditions for entry and your conditions to exit into two different sets. I suggest you add a condition in your exit conditions to check that the current market position is long as well.

    MarketPosition - https://ninjatrader.com/support/help...etposition.htm

    Please let us know if you have any other questions.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Gaby View Post
      Hello br0ns0n,

      Thank you for your post.

      Your set has an exit and entry on the same pass of OnBarUpdate().

      Be sure not to call an exit and then an entry on the same bar. This would cause the position to become double the opposite direction or cause an overfill.

      https://forum.ninjatrader.com/forum/...16#post1036616

      Your current set is checking for entry conditions and exit conditions and saying to enter and exit at the same time, on the same bar.

      I recommend you split your conditions for entry and your conditions to exit into two different sets. I suggest you add a condition in your exit conditions to check that the current market position is long as well.

      MarketPosition - https://ninjatrader.com/support/help...etposition.htm

      Please let us know if you have any other questions.
      Here is my updated logic. Please let me know if this is correct:

      Click image for larger version

Name:	Screen Shot 2023-12-13 at 2.07.08 PM.png
Views:	49
Size:	364.6 KB
ID:	1282098Click image for larger version

Name:	Screen Shot 2023-12-13 at 2.07.50 PM.png
Views:	49
Size:	343.4 KB
ID:	1282099
      Last edited by br0ns0n; 12-13-2023, 01:09 PM.

      Comment


        #4
        Hello br0ns0n,

        Set 1 is the entry conditions, with the 'Action' of that set being your entry method.

        Set 2 is the exit conditions, with the 'Action' of that set being your exit method.

        As long as the conditions are true for the entry, the order is going to keep getting pushed 1 tick below the low on each new bar. If the conditions are not true, the order will cancel.

        Please also note that from your screenshot, the fromEntrySignal in your exit method does not match the signalName of your entry method.

        As a side note, if you only have 1 condition group, the conditions don't necessarily have to be in a group. You can add each one in the Conditions section.

        If you have any other questions, please let us know.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Gaby View Post
          Hello br0ns0n,

          Set 1 is the entry conditions, with the 'Action' of that set being your entry method.

          Set 2 is the exit conditions, with the 'Action' of that set being your exit method.

          As long as the conditions are true for the entry, the order is going to keep getting pushed 1 tick below the low on each new bar. If the conditions are not true, the order will cancel.

          Please also note that from your screenshot, the fromEntrySignal in your exit method does not match the signalName of your entry method.

          As a side note, if you only have 1 condition group, the conditions don't necessarily have to be in a group. You can add each one in the Conditions section.

          If you have any other questions, please let us know.
          Hello - I'm assuming that Set 1 and Set 2 are not being checked simultaneously? Based on my experiments, Set 2 doesn't calculate until a bar is closed from Set 1.

          The goal is to ensure if the entry candle hits the high of the previous candle that the position would be closed and I get stopped out - this could happen before the entry candle has a chance to close. Set 2 doesn't start until the entry candle has closed. Any way around that?
          Last edited by br0ns0n; 12-13-2023, 03:16 PM.

          Comment


            #6
            Hello,

            No, Set 1 then Set 2 is evaluated for each bar update. It is not true that Set 2 doesn't calculate until a bar is closed from Set 1. All Sets are evaluated in order on each pass of OnBarUpdate().

            OnBarUpdate() - https://ninjatrader.com/support/help...nbarupdate.htm

            If your strategy is set to Calculate.OnBarClose, OnBarUpdate() is updated every bar close.

            Calculate - https://ninjatrader.com/support/help.../calculate.htm

            Please let me know if you have any other questions.
            Gaby V.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,788 views
            0 likes
            Last Post aligator  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            837 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,293 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            13 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            11 responses
            63 views
            0 likes
            Last Post halgo_boulder  
            Working...
            X