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

Understanding ExitLong vs EnterShort

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

    Understanding ExitLong vs EnterShort

    Hi,

    (1) Suppose my strategy has a code that wants to go Long 100 contracts and after some time wants to go short 120 contracts.

    What would be the difference between CASE 1, and CASE 2

    ---

    (a) CASE 1

    if (condition1) EnterLong(100);

    if (Position.MarketPosition == MarketPosition.Long & condition2)
    {
    ExitLong(100);
    EnterShort(120);
    }

    ---

    (b) CASE 2


    if (condition1) EnterLong(100);

    if (Position.MarketPosition == MarketPosition.Long & condition2) EnterShort(220);

    ---

    (2) A separate question, I searched a bit on this forum, but I couldn't find where can the "string signalName" be useful. Is the primary use for "signalName" for tracking the Order history (say in a collection of Orders) or something like that ?


    #2
    Hello uday12,

    With case 1, the position will first be long 100.
    Then an exit order will be placed to exit the 100 long for the ExitLong(100) call, before this fills, a second order is placed to exit the 100 long for the EnterShort(120) call, then a third order is placed to enter 120.
    The position would become 220 short or an overfill will occur and the strategy will become disabled.

    Below is a link to a forum post about overfills.


    With case 2, the position will first be 100 long.
    Then the position will be exited first by the EnterShort(220) call and a second order will be placed to enter a position of 220 short.
    The position would become 220 short.

    The signal name is used to attach an exit order to a specific entry order by having the from entry signal of the exit order match the from entry signal of the entry order.

    Below is a public link to the Strategy Builder 301 course which covers this.
    https://www.youtube.com/watch?v=HCyt...tu.be&t=52m38s

    As well as a link to the help guide on ExitLong() where you can read about the from entry signal.
    https://ninjatrader.com/support/help...s/exitlong.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea

      I had three follow up questions.

      (A) What happens when the ExitLongStopMarket or ExitLongStopLimit has a quantity that is larger than the Position.Quantity?

      Suppose I am long 100 contracts. I send a Stop order via ExitLongStopMarket or ExitLongStopLimit for 120. Am I short 20 contracts, or does it merely ignore any excess quantity larger than the Position.Quantity?


      (B) Suppose I am long 100 contracts. Market is at $95.

      For the next bar, I want to do two things:

      1. I want to send a stop order to exit the long if the Market falls to $93
      2. I want to further send a stop order to enter short N contracts if the Market further falls to $91.

      (i) Now, if N > 100, e.g. say N = 120, then I presume I can issue the following order for the next bar to achieve the effect:

      1. ExitLongStopMarket(100, 93)
      2. EnterShortStopMarket(N-100, 91)

      (ii) But, if N < 100, e.g. say N = 80, then what can I do? Would this work?

      1. ExitLongStopMarket(100, 93)
      2. EnterShortStopMarket(100, 91) + EnterLongStopMarket(200-N, 91) ... would it enter short sell 200 contracts (100 short + 100 to close the long) while also enter long buy 200-N contracts, giving me the desired net effect of N short contracts at $91 ??


      (C) Suppose I am long 100 contracts on a SignalName = "LongEntry"

      now I issue an order EnterShortStopMarket of 120 with a different SignaName = "ShortEntry", will it still first exit the long 100 contract, then go short 120, or will it just go short 120?



      Thanks
      Last edited by uday12; 04-18-2019, 11:16 PM.

      Comment


        #4
        Hello uday12,

        A) When using the managed approach exit orders will only exit up to the amount of the open position.

        An order will be ignored if there is already a working order and the new order is in the opposite direction.
        From the help guide:
        "Methods that generate orders to enter a position will be ignored if:
        •A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction"


        So you would want to wait until the first working order fills before placing the second order.

        B) If you are waiting until there are no working orders before placing the next order, then each order will fill its total quantity in order. So if you were long 100, then exited 100 you would be flat, then a short order would be placed for whatever N-100 is and when that fills, you would be short that amount..

        When you mention "EnterShortStopMarket(100, 91) + EnterLongStopMarket(200-N, 91)" this will not be possible.

        C) Yes, calling an entry in the opposite direction will first close a position in the opposite direction automatically. This is not tied to signal names. You will want the signal names to be different.
        Chelsea B.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
        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