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 vs Buy

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

    EnterLong vs Buy

    After a lot of tinkering I think I learned that EnterLong and EnterShort don't mean what I thought they do. I thought they meant the same as buy or sell, but now I think they mean:
    * EnterLong(1) actually means: if you're already short, buy the number of shares required to get you to 1 long
    * EnterShort(1) actually means: if you're already long, enter the number of shares required to get you to 1 short.

    Is that correct?

    I know this is supposed to simplify things, but I find it pretty confusing, and feel like I must be overlooking something very basic. If I have a strat where I just need to buy or sell a unit regardless of what my position is, and attach stops to each individual transaction, what is the best way to do this?

    Also, I've seen some conversations around selling vs selling short, but when I trade futures manually with my broker I don't need to specifiy... I think i just enter a sell and then presumably they check to see if i have adequate margin, etc..., but since they're futures no locate, etc is required. So in my framework, would i need to specify if it is a long sale vs a short sale?

    Thanks,
    Colin

    #2
    Hello stewarco,
    Thanks for your post.

    You are correct in what you could expect to see in those situations. If you are long and then submit a short order it is going to exit your long position and then go short. To simply go flat you would want to use the appropriate exit order. I expect this is already the best way to immediately buy or sell no matter what your position is.

    There are multiple way you can set up your stops and targets, and they will depend on your specific circumstance. I think the simplest way to do this would look something like the following:
    Code:
    if (Close[0]>Open[0])
    {
    	EnterLong(1, "longEntry");
    	SetStopLoss("longEntry", CalculationMode.Ticks, 5, false);
    	SetProfitTarget("longEntry", CalculationMode.Ticks, 5);
    }
    In regards to selling versus selling-short— I believe selling-short is only for margin trading because you typically do not own it if you are shorting it. If you own something it would simply be a sell. I am not sure what you mean by a "long sale".
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      thanks.. a few clarifications

      Thanks a few more questions:
      Please tell me if below is correct.
      I start flat.
      If I EnterLong(1) then I own one unit.
      If I EnterLong(1) again then I own two units.
      Correct?

      Now suppose I want to initiate a third trade, where I want to sell 1 unit. However, I don't want to exit the existing two long units. Those have their own associated stops and profit levels which will dictate when they are closed, and each will only be closed when it hits its individual stop/ or profit. In other words, there may indeed be times where my position is flat but I still have (say) four individual trades outstanding (2 long, 2 short) and each of those has independent stop/profit levels.

      So what would the command be to sell one unit as opposed to exiting one of the existing trades? Most of the feedback I've gotten is that this requires an Unmanaged framework which I'm fine with but just want to be sure.

      Thanks

      Comment


        #4
        You can never be both LONG and SHORT in the same instrument in the same account.

        Comment


          #5
          bltdavid is correct. You would need another account to do what you're describing..
          Josh G.NinjaTrader Customer Service

          Comment


            #6
            thanks

            Thanks Josh and bitdavid. To be clear, I'm not looking to be long and short literally (though i have noticed there are strats out there that do that). I'm just trying to manage the overall position at the individual trade level, where in my head I might be thinking of a flat position as consisting of 1 long trade and 1 short trade with different stops/profits etc, whereas my broker and the strategy will just see it as a flat position with a couple stop/profit orders outstanding. So yes, it will always only be long, short, or flat in actuality.

            Sounds as though the Unmanaged is way to go for this sort of approach.

            Thanks again, and special thanks to bitdavid, it's always cool when other users help out. I hope as I relearn to code after a 25 year hiatus I'm able to help other newbies.

            Comment


              #7
              Originally posted by stewarco View Post
              Sounds as though the Unmanaged is way to go for this sort of approach.
              I'm not sure Unmanaged mode will make a difference here.

              If your account is LONG 1 contract and you will wish to also open a "second position" for the same instrument in the same account going SHORT 1 contract, NinjaTrader will send the "SELL 1" order to your broker. We're talking futures here, not stocks.

              Your futures broker has no clue that you want to open this 'second position'. Why? Because it simply doesn't work that way. Your broker sees the SELL 1 order as as exit of the LONG 1 position -- you are now FLAT at your broker. In NinjaTrader parlance, we call that your account position, and we say that your account position is FLAT.

              In futures, there is no such thing as a "second position" in the same instrument in the same account.

              Consider it this way, the ordering system employed at your broker is dumb, I mean really dumb. Your broker effectively only understand 2 commands: BUY and SELL.

              Your account position is very important in how these 2 commands are interpreted by your broker. Remember, your account position is the only thing your broker knows, your BUY/SELL commands affect your account position. Your account position is effectively a per instrument kind of thing.

              When your account position is FLAT then a BUY or SELL order will open a new position.

              But when you are already LONG, the BUY command adds to the position and the SELL command subtracts from that position.

              When already SHORT, it is the opposite, the SELL command adds to the position and the BUY command subtracts from the position.

              Thus, for the same instrument, when you're already LONG 1 contract, your broker receives the SELL 1 order, and you are now FLAT at the broker.

              Let's say you wish to get around this by running the same strategy twice, the first strategy only takes LONG positions and the other only takes SHORT positions. When you run these 2 strategies in the same account on the same instrument, you will have problems, because the strategy position will not be the same as account position.

              Starting as FLAT, assume strategy #1 sends a BUY 1 order, we have,

              Strategy #1 position is LONG 1
              Strategy #2 position is FLAT
              Account position is LONG 1 <-- this is only 'position' that matters

              A few minutes later let's assume strategy #2 (which handles all your short positions) sees a great opportunity and sends a SELL 1 order to your broker. What happens?

              Strategy #1 position is LONG 1
              Strategy #2 position is SHORT 1
              Account position is FLAT <-- this is the only 'position' that matters

              The strategy positions for both strategies are now out of sync with the account position. What caused this? Remember, those dumb BUY and SELL orders blindly executed by your broker? He has no clue you're running 2 strategies, and he doesn't care, he only understands 2 commands: BUY and SELL. The SELL 1 order sold the position that was LONG 1, and you are now FLAT at your broker. This is not NinjaTrader's fault.

              [Things get really hairy when strategy #1 or #2 try to close their position, to exit the strategy position NinjaTrader sends the appropriate BUY or SELL order, but because your account position was FLAT, you effectively opened a new account position, but that strategy thinks you're flat ... it's a big mess, you are basically screwed if you do it this way.]

              How to fix this?
              Easy. Run each strategy in a separate account.

              You can never be both LONG and SHORT in the same instrument in the same account.

              Read this, it applies to both NT7 and NT8,

              Last edited by bltdavid; 06-01-2018, 05:01 PM.

              Comment


                #8
                Here is the same link for NT8,

                Comment


                  #9
                  I said,

                  In futures, there is no such thing as a "second position" in the same instrument in the same account.

                  If strategy #1 holds a LONG 1 position and strategy #2 holds a LONG 2 position for the same instrument for the same account, this appears to be a 'second position'.

                  From the point of view of NinjaTrader, it is a second position. There are two strategies executing independently and each keeps track of their own strategy position.

                  But from the point of view of your broker, there is only one account position and it is LONG 3.

                  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, 04-23-2024, 09:53 PM
                  2 responses
                  49 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