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

Need help with Strategy syntax/coding...

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

    Need help with Strategy syntax/coding...

    Greetings,

    I am working on my first NT8 strategy and need some help with coding. I've built this strategy using the strategy builder wizard.

    The strategy would enter long if the value TrendSignalUp = 1 or short if TrendSignalDown = 1.

    It needs to enter on the open of the next bar if the previous bar was different than the one before it. That is, 2 bars ago is different.

    So, if TrendSignalDown[2] = 1 and TrendSignalUp[1] = 1 then enter long.

    The code below causes a trade to be entered on every bar.

    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (atsTrendFinder1.TrendSignalUp[0] == 1)
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 2
    if (atsTrendFinder1.TrendSignalDown[0] == 1)
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }

    }

    What is the syntax to make this work?

    Thanks

    Andrew

    #2
    Hello ajadams,

    Thanks for your post.

    Your conditions are checking only if the current bar's TrendSignalUp is 1 and if the current bar's TrendSignalDown is 1 to trigger trades. If you would like to check if "TrendSignalDown[2] = 1 and TrendSignalUp[1] = 1" then I would suggest making your condition check both of these in the Strategy Builder. The screenshot attached shows a condition that checks two conditions using AND.

    If you have not already done so, I would recommend viewing the Strategy Builder 301 tutorial and the help guide items below for creating a complete strategy using the Builder.

    Strategy Builder 301 - https://www.youtube.com/watch?v=HCyt90GAs9k
    Conditions Tips - https://ninjatrader.com/support/help...on_builder.htm
    Actions Tips - https://ninjatrader.com/support/help...us/actions.htm

    After you are comfortable creating logic with the Builder, I would then suggest to create a duplicate strategy and click the View Code button with each addition to better observe the syntax created by the Builder. Our NinjaScript Editor 401 tutorial covers some basics behind creating logic with the Builder and creating your own unlocked copy of a strategy for manual code edits.

    NinjaScript Editor 401 - https://www.youtube.com/watch?v=BA0W4ECyVdc

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Jim, thank you for your quick and helpful reply. I have studied the strategy builder support pages closely and now have a better understanding to how powerful the wizard is. Thanks.

      Drew

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Waxavi, Today, 02:10 AM
      0 responses
      3 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by TradeForge, Today, 02:09 AM
      0 responses
      9 views
      0 likes
      Last Post TradeForge  
      Started by Waxavi, Today, 02:00 AM
      0 responses
      2 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by elirion, Today, 01:36 AM
      0 responses
      4 views
      0 likes
      Last Post elirion
      by elirion
       
      Started by gentlebenthebear, Today, 01:30 AM
      0 responses
      4 views
      0 likes
      Last Post gentlebenthebear  
      Working...
      X