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

Please help - Position Qty ?

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

    Please help - Position Qty ?

    Basically, my issue is that: currently I have 1 short position, and then I enter long 2 contracts. In theory, the position tab should only show 1 contract . however, it still shows 2 long ( after the short 1 was closed). I am wondering why?

    Here is my code:

    if ("condition 1 ok" && Position.Quantity == 0)

    {
    EnterLong( 1, "Buy1" );
    }

    // Condition set 2
    if ("Condition 2 ok" && Position.MarketPosition == MarketPosition.Short)
    {
    EnterLong( 2, "Buy2" );
    }

    Thank you very much!

    #2
    Hello OceanBass,

    Thanks for your post and welcome to the forums!

    With reference to the managed approach in the helpguide: http://ninjatrader.com/support/helpG...d_approach.htm

    The entry method, EnterLong() will reverse a position if one exists.

    In the example of 1 short, condition set 2, the EnterLong(2, "Buy2") would issue one buy market to close the position and then two buy market to enter you into a long position with two contracts.

    edit- added the 2, "buy2" to clarify
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul!

      So if I modified the code as below , should be work, right?

      if ("condition 1 ok" && Position.Quantity == 0)

      {
      EnterLong( 1, "Buy1" );
      }

      // Condition set 2
      if ("Condition 2 ok" && Position.MarketPosition == MarketPosition.Short)
      {
      EnterLong( 1, "Buy2" ); ///change qty=1
      }

      Comment


        #4
        Hello OceanBass,

        Thanks for your reply.

        Correct.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thank you Paul. One more question, sorry.

          The "Position" Tab is showing account position or strategy position? if it is account position, then where is strategy position showing ( as you know , sometimes they are different)?

          Thanks.

          Comment


            #6
            Hello OceanBass,

            Thanks for your reply.

            The positions tab in the control center shows the actual account position.

            The strategies tab in the control center shows the strategy position.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hi Paul,

              if I have 2 short positions for 2 different symbols, like 1 short ES and 1 short CL. Then if I enterLong(), will it close all 2 short positions. how do I make sure it reverse the symbol I want only?

              Thanks.

              Comment


                #8
                someone can help below question? thanks.

                Comment


                  #9
                  Hello OceanBass,

                  Thanks for your post.

                  For your understanding we have skeleton crew available on the weekend and depending on the volume of queries not all questions can be quickly answered.

                  If you have one strategy for CL and one strategy for ES, only the one (with EnterLong) will be reversed. The strategies run independent of each other.

                  If you have both instruments in the same strategy then you would need to use the method overload of (for example): EnterLong(int barsInProgressIndex, int quantity, string signalName) where the variable BarsInProgress points to which instrument to reverse. Reference: https://ninjatrader.com/support/help...?enterlong.htm

                  If you are writing a multiseries strategy please do review: https://ninjatrader.com/support/help...nstruments.htm

                  Don't hesitate to use your sim101 account for testing your various questions as this will help increase your Ninjascript knowledge.
                  Paul H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by wzgy0920, 04-20-2024, 06:09 PM
                  2 responses
                  26 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, Yesterday, 09:53 PM
                  2 responses
                  49 views
                  0 likes
                  Last Post wzgy0920  
                  Started by Kensonprib, 04-28-2021, 10:11 AM
                  5 responses
                  192 views
                  0 likes
                  Last Post Hasadafa  
                  Started by GussJ, 03-04-2020, 03:11 PM
                  11 responses
                  3,234 views
                  0 likes
                  Last Post xiinteractive  
                  Working...
                  X