Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Difficult trying to get Strategy Builder to enter on 2 conditions in specific order

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

    Difficult trying to get Strategy Builder to enter on 2 conditions in specific order

    I have watched a lot of videos and most examples to have 1 condition needed in order for an entry and the difficulty I'm having is that I have 2. Right now, I am simply trying to create a strategy that goes long when this happens:

    1. Candle closes above the 50 SMA
    2. The next candle breaks above that candle by 1 tick. It has to be the next candle, no other candles.

    I don't see a way of telling the strategy builder to do it in that order which is what needs to happen. When running playback to test the strategy, it is going long immediately at the close of the candle crossing the 50 SMA. I need it to not do anything untl the next candle breaks it.

    I am trying to do this with Strategy Builder since I'm not experienced enough with the coding part. Attached is what I have so far.

    Click image for larger version  Name:	simplestrategy.jpg Views:	0 Size:	59.8 KB ID:	1281991
    Last edited by Moraha; 12-12-2023, 09:56 PM.

    #2
    Hello Moraha,

    Thank you for your post.

    Please see the attached screenshot.

    To achieve both conditions, you'll want to check (1) if the Close of 1 bar ago is greater than a 50 period SMA 1 bar ago and (2) if the Open of the current bar is greater than the Close 1 bar ago.

    Please let me know if you have any other questions.
    Attached Files

    Comment


      #3
      Originally posted by NinjaTrader_Gaby View Post
      Hello Moraha,

      Thank you for your post.

      Please see the attached screenshot.

      To achieve both conditions, you'll want to check (1) if the Close of 1 bar ago is greater than a 50 period SMA 1 bar ago and (2) if the Open of the current bar is greater than the Close 1 bar ago.

      Please let me know if you have any other questions.
      Hi Gaby. This unfortunately did not work. It took incorrect trades during testing. I added an attachment showing a clearer picture of what I'm looking to have this strategy do. If you look at the bar I labeled as 1. That broke above the blue line (let's say it's the 50 SMA in this example) and closed above that line. I want bar 2 to trigger an entry long once it breaks the high of that bar 1 where I have that arrow pointing, which is 1 tick above Bar 1.

      As you see on the 2nd to last bar, the code you gave me took an entry there and I can't figure out why it did that. Click image for larger version  Name:	entry.jpg Views:	0 Size:	18.5 KB ID:	1282437
      Last edited by Moraha; 12-15-2023, 08:47 PM.

      Comment


        #4
        I have been working on this all weekend and I just can't get it figured out. It seems so simple but I just can't get it to work properly. Attached is what I created but on every bar, it's opening a position. I changed it to use a 20SMA in this instead of the original idea for the 50SMA.
        Attached Files

        Comment


          #5
          Hello,

          To understand why the script is behaving as it is, such as placing orders or not placing orders (or drawing objects or other actions) when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

          In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

          This will print to the output window. Backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.


          Output from prints will appear in the NinjaScript Output window.

          NT8: New -> NinjaScript Output


          The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very helpful to include labels and operators in the print to understand what is being compared in the condition sets.

          Below I am providing a link to videos that demonstrate adding prints to a script to get further information about the behavior of the script.

          NT8 —

          https://youtu.be/H7aDpWoWUQs?t=2577&...We0Nf&index=14



          If you are using the Strategy Builder in NinjaTrader 8, you can also build prints in the Actions window under Misc -> Print.

          NT8 Strategy Builder —

          https://drive.google.com/open?id=1CC...D4JjJgEIwJKv6L



          To copy a script and modify the copy (allowing the original to remain in the Strategy Wizard):

          NT8 —

          https://www.youtube.com/watch?v=BA0W...utu.be&t=8m15s



          It is also helpful to set TraceOrders to true in State.Configure as well as print the order object in OnOrderUpdate().

          TraceOrders will output to the NinjaScript Output window a message when orders are being submitted, ignored, cancelled, or rejected.

          Printing the order object in OnOrderUpdate() will allow you to track the progression of the order from submitted, to working, to filled, cancelled, or rejected.

          These tools will let you know what happens to the order.

          TraceOrders - https://ninjatrader.com/support/help...raceorders.htm

          OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

          I'm also including a link to a forum post with further suggestions on debugging a script.

          https://ninjatrader.com/support/foru...956#post671956

          Save the output from the output window to a text file. Let me know if you need assistance creating a print or enabling TraceOrders.

          I am happy to assist with analyzing the output from prints and TraceOrders.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          52 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X