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

EnterLong with barsInProgressIndex issue

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

    EnterLong with barsInProgressIndex issue

    I have a strategy that trades several stocks at the same time.
    Each stock # of shares could increase or decrease over time.
    I am using :

    To add shares:
    EnterLong(int barsInProgressIndex, int quantity, string signalName)


    to reduce shares:
    ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)

    I was using unique signalNames for entries of the same stock but that doesn't working for exits.
    Can I use the same signalName for all entries for the same stock? so that I can exit with the same entry signal?

    Would this work?

    #2
    Hello afshinmoshrefi,

    Thank you for writing in.

    When you say that the number of stock shares could increase or decrease, are you referring to an existing open position or new trades?

    Would you provide the exact statements for your Enter and Exit methods rather than the syntax form? For example, EnterLong(0, 1, “Buy HOG”); etc.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Alan. Here is an example of what would happen:

      BarsInProgress for MSFT = 2
      BarsInProgress for AAPL = 3

      Strategy buy 10 shares of MSFT and 20 shares of AAPL
      EnterLong(2, 10, “Buy MSFT”);
      EnterLong(3, 20, "Buy AAPL");

      The next day strategy will buy 20 more shares of MSFT and Buy 20 more shares of AAPL
      EnterLong(2, 20, “Buy MSFT”);
      EnterLong(3, 20, "Buy AAPL");

      now there are 30 share of MSFT and 40 shares of AAPL open

      on the third day strategy will sell 28 shares of MSFT and 18 shares of AAPL

      ExitLong(2, 28,"Sell MSFT", "Buy MSFT");
      ExitLong(3,18, "Sell AAPL", "Buy AAPL");

      in the above both EnterLong for MSFT have the same signal name "Buy MSFT";

      Question is:
      Is it valid to use the same buy signal name for buying the same stock multiple times?

      Comment


        #4
        Hello afshinmoshrefi,

        It would be suggested that the second round of entries would carry a different signal name, for example,

        Code:
        EnterLong(2, 20, “Buy MSFT[B]Two[/B]”);
        EnterLong(3, 20, "Buy AAPL[B]Two[/B]");
        For your exit calls you would then want to break up your quantities, so that your exit long for MSFT of 28 shares becomes,

        Code:
        ExitLong(2, 20,"Sell MSFT", "Buy MSFT");
        ExitLong(2, 8,"Sell MSFT[B]Two[/B]", "Buy MSFT[B]Two[/B] ");
        And since your opening trade for AAPL was 20, the call below would leave you with 2 shares as part of this AAPL position, you would not need to break it up.

        Code:
        ExitLong(3,18, "Sell AAPL", "Buy AAPL");
        You could also see Scaling out of a position reference example,


        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          That will make my strategy impossible in NinjaTrader 8. If there is no workaround this is a huge limitation of NT8.
          for example I may have 107 shares of long AAPL while the entry signals spanned across 10+ different enterLong trades. How can I track the entry signals and number of shares for every share that is outstanding. In the next trade I may want to exit 43 shares, which entry signals would I use?

          The way I need to process partial exit requires that I specify exitLong with barsInProgressIndex but without fromEntrySignal; or to be able to specify all orders for the same stock EnterLong with the same exact EntrySignal.
          Last edited by afshinmoshrefi; 03-15-2017, 07:06 AM. Reason: additional information

          Comment


            #6
            Now I understand I have to switch to Unmanaged approach.

            Comment


              #7
              Hello afshinmoshrefi,

              Yes, the Unmanaged Approach would be better suited for what you are looking to do.

              Please let us know if you need further assistance.
              Alan P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              27 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              32 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 04-23-2024, 09:53 PM
              2 responses
              64 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              193 views
              0 likes
              Last Post Hasadafa  
              Started by GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,235 views
              0 likes
              Last Post xiinteractive  
              Working...
              X