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

Enter a long position over 12 months | Two Stocks?

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

    Enter a long position over 12 months | Two Stocks?

    Hey there,

    How do I open a long position over (for example) 12 months.
    for example:

    my strategy should enter a long position on the first of january and should close on the first of december.

    opening: first of january

    closing: first of december


    and my other question:

    Is it possible to have one strategy for two stocks?
    for example my strategy should by the S&P AND the NASDAQ at the same time.
    Is this possible?

    #2
    Hello SpaceGrey,

    Thanks for your post!

    You could check the timestamp of the iterating bar in OnBarUpdate() with Time[0]. From the timestamp you could then check what the current date is and use that in your strategy logic to control when you want to get in, and when you want to get out. You would also have to turn off ExitOnSessionClose so the strategy stays in position.

    From the Strategy Wizard, conditions build on time can be accessed in a Condition Builder under Time.

    Once a strategy is created it can be assigned to any number of different instruments. You could make one strategy and have one instance of it use one instrument and have another instance of that strategy use another.

    I've included a link to our Strategy Wizard 301 tutorial which provides excellent reference for using the Strategy Wizard to build simple strategies without having a programming background. I've also included documentation for running NinjaScript strategies.

    Strategy Wizard 301 - https://www.youtube.com/watch?v=FmBiNYsf1e8

    Running NinjaScript Strategies - https://ninjatrader.com/support/help...strategies.htm

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.
      I will watch the video later because it takes 1h

      anyway, I tried it with the strategy builder and my code currently looks like this:

      if (ToDay(2017, 1, 1) < ToDay(2018, 12, 1))
      {
      EnterLong(DefaultQuantity, "");
      }

      but this seems to be wrong(?)

      Comment


        #4
        Hello SpaceGrey,

        In addition to understanding how logic can be written for a strategy there are several other rules that must be understood when creating fully automated NinjaScript strategies. This involves understanding Strategy vs. Account Position as well as how the strategy processes historical data to create a virtual position, and how the strategy's start behavior uses that position when starting the strategy. Since there can be a lot to cover, I highly recommend viewing the training videos to learn everything necessary to use the builder appropriately.

        I also notice you mentioned Strategy Builder but had posted in the NinjaTrader 7 forum. Did you need resources for the Strategy Wizard in NinjaTrader 7 or the Strategy Builder in NinjaTrader 8? I've included some resources for the Strategy Builder 301 tutorial and further reading for running NinjaScript strategies in NinjaTrader 8. I've also included reference to the Managed Approach which is used by the Strategy Builder. This documentation covers creating logic to enter/exit and also explains the internal rules that prevent unwanted positions.

        Strategy Builder 301 - https://www.youtube.com/watch?v=HCyt90GAs9k

        Running NinjaScript Strategies NT8 (Strategy vs. Account Position explained here) - https://ninjatrader.com/support/help...strategies.htm

        Managed Approach - https://ninjatrader.com/support/help...d_approach.htm

        When designing logic and building our strategy, we will have to take debugging steps to better understand the code and how it executes. This can be done by placing prints for the values used to evaluate your conditions, outside of your conditions. This way you can see the same values that the strategy is using to evaluate your conditions.

        Some questions to ask yourself while adding debugging prints would be:
        • Are the values used to evaluate the condition allowing the strategy logic to execute?
        • When you add a print for the current market position, do you see if the strategy is already in a position that prevents you from entering a new position? (This is likely the immediate issue. The strategy is in a position from processing historical, and is not allowed to submit a new order until that position is closed.)
        • Do you see any errors in the log tab of the Control Center?


        I've included a quick demonstration showing how you can set up prints in the Strategy Builder so you can further monitor the strategy logic as it executes.

        Debugging with the Strategy Builder - https://www.screencast.com/t/8uvjfM8h

        I look forward to being of any further assistance.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CommonWhale, Today, 09:55 AM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Gerik, Today, 09:40 AM
        2 responses
        7 views
        0 likes
        Last Post Gerik
        by Gerik
         
        Started by RookieTrader, Today, 09:37 AM
        2 responses
        12 views
        0 likes
        Last Post RookieTrader  
        Started by alifarahani, Today, 09:40 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by KennyK, 05-29-2017, 02:02 AM
        3 responses
        1,285 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Working...
        X