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

Multiple Entries, Single Exit

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

    Multiple Entries, Single Exit

    Hi All,

    I've been customizing a strategy in strategy editor and have hit a wall. Currently its set up to enter and exit when certain indicator criteria is met. Super basic strategy.

    I'd like to be able to add a second buy if the existing position dips and exit all on the existing exit criteria.

    For example, strategy buys 1 contract, position dips 20 ticks, another buy, then all positions are closed at the same time. If the position does not dip, it would stick with 1 contract and exit.

    Any thoughts? Thanks in advance!

    #2
    Hello Deep_ITM_Puts, thanks for your post.

    You might need to set the position quantity as the quantity for exit orders e.g. in your exit action:


    This could be one solution, it depends on how exactly your strategy is written out. Please give this idea a test.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thank you. I'm actually working with the code directly. I'm basically looking to keep everything the same except to buy 1 additional contract if open position decreases by X ticks. Any suggestions?

      protected override void OnBarUpdate()
      {
      // Exit if cross has occurred since entry, or SMAs are no longer in up trend.
      if (!TrailStop && Position.MarketPosition != MarketPosition.Flat
      && (CrossAbove(smaFast, smaSlow, 1) || CrossBelow(smaFast, smaSlow, 1))
      && (smaFast[0] < smaFast[1] || smaSlow[0] < smaSlow[1]))
      {
      ExitLong();
      }

      // Or exit with our trailing stop on the fast (50 period by default) SMA.
      else if (TrailStop && Position.MarketPosition != MarketPosition.Flat)
      {
      if (Close[0] > smaFast[0])
      ExitLongStopMarket(smaFast[0]);
      else
      ExitLong();
      }

      // Enter on smaFast crossing above smaSlow.
      if (CrossAbove(smaFast, smaSlow, 1)
      && Position.MarketPosition == MarketPosition.Flat)
      {
      if (!IncreasingVolume)
      EnterLong(); // No increasing volume factor.
      else if (IncreasingVolume && Volume[0] > Volume[1])
      EnterLong(); // Enter only if volume is increasing since prior bar.
      }
      }

      Comment


        #4
        Figured it out!! I've added this and it worked. Thanks!

        // Buy the dip
        if (Position.GetUnrealizedProfitLoss(PerformanceUnit. Ticks, Close[0]) == -200)
        {
        EnterLong(Convert.ToInt32(DefaultQuantity), "");
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by adeelshahzad, Today, 03:54 AM
        5 responses
        32 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by stafe, 04-15-2024, 08:34 PM
        7 responses
        32 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by merzo, 06-25-2023, 02:19 AM
        10 responses
        823 views
        1 like
        Last Post NinjaTrader_ChristopherJ  
        Started by frankthearm, Today, 09:08 AM
        5 responses
        20 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        43 views
        0 likes
        Last Post jeronymite  
        Working...
        X