Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitLong not exiting

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

    ExitLong not exiting

    Hi I have a strategy the calls ExitLong. However, the position remains open. Position.Quantity remains == 1 after ExitLong is called. The strategy writes records out to the output window. Excerpt below:
    2010-09-09 17:20:09.5370000ES 09-10 Signal: 0 Position.Quantity: 1
    2010-09-09 17:20:09.5370000 ES 09-10 ATMStrategyReaper.ExitPosition ExitLong. Signal: 0
    2010-09-09 17:24:19.7160000ES 09-10 Signal: 0 Position.Quantity: 1
    2010-09-09 17:24:19.7160000 ES 09-10 ATMStrategyReaper.ExitPosition ExitLong. Signal: 0
    2010-09-09 17:28:35.0480000ES 09-10 Signal: 0 Position.Quantity: 1
    2010-09-09 17:28:35.0480000 ES 09-10 ATMStrategyReaper.ExitPosition ExitLong. Signal: 0

    The full strategy is attached. It calls a DLL ( which I'm not providing ). The GetSignal API exposed by the DLL returns -1, 0 or 1 ( short, flat or long ). It's the variable called nSignal in the C# strategy and is want is logged out (above) as "Signal".
    Question: Why would the strategy remain in the position when the signal and the logging shows that ExitPosition was called?
    Attached Files

    #2
    Brillo, are you sure you were correctly synched up strategy vs account position wise as you started up the strategy for trading on this day?

    Please run it with TraceOrders = true in the Initialize() to debug the order behavior you would see.

    Comment


      #3
      ExitLong Not Exiting

      Hi Bertrand,

      Using the strategy builder, I'm trying to build a strategy that I can implement after I have entered a long trade that will exit the long position after a fast exponential moving average (WL) crosses under a slow EMA. I have been using the "ExitLong" Action in the code but am unable to get it to work also. Below is the code in the condition builder:

      CONDITIONS:
      Position.MarketPosition==MarketPosition.Long
      EMA(WL)[0]<=EMA(BL)[0]

      ACTION:
      ExitLong ("XU Exit)", "")

      Can you advise me what the code should be to exit a Long position after a fast moving average crosses under a slow moving average?

      In an effort to get the ExitLong to execute I tried replacing the
      EMA(WL)[0]<=EMA(BL)[0] condition

      with the condition:
      BarsSinceEntry () >= 2

      but that wouldn't close out the long position either.

      Thanks,

      Rob.

      Comment


        #4
        Rob, you can directly setup CrossOver / CrossBelow conditions in the wizard to accomplish this - http://www.ninjatrader-support.com/H...onditions.html

        Please also ensure to tag the correct signal names togehter in your Conditions, for exmaple if your Long entry is named 'Rob Long1' you want to enter this as your 'FromEntrySignal' name in the ExitLong() condition.

        Comment


          #5
          Bertrand,

          I beleive my code for the cross under condition is correct; even if it wasn't then the BarsSinceEntry() >=2 should cause a long exit.

          I enter a Long trade using Chart trader.

          I then want to implement the automated exit strategy by going to the Strategy tab in the control center and starting the strategy I previously described where NT gets me out on a EMA cross under.

          In the NT help guide in the Strategy Guide Exit a Position section says:

          3. Set the "From entry signal" property to a named entry signal within the strategy. Providing a value will exit only the quantity associated to the position created by the named signal. Leaving it blank will exit the total net position.

          Once I have manually entered a long position via Chart Trader I want to go to the control center and Start a strategy that will get me out of the Long position. It seems like activating the strategy I described should exit the position as per the underlined section above.

          If I can't exit the long as described above, can you describe another method to automatically get me out of an existing long position on a EMA cross. (I hope your not going to say NT can't do this)

          Thanks,

          Rob.

          Comment


            #6
            Rob, this will unfortunately not work as you expect - if you trade from ChartTrader manually, the NinjaScript strategy will not pick it up, it would only manage it's own orders, hence the entry would need to come from the NinjaScript strategy here, too.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            630 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            566 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X