Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get the entry signal or bars array index for an open position

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

    How to get the entry signal or bars array index for an open position

    I have a multi-timeframe strategy and when it comes to my exit I want it to exit on the same bars array (timeframe)? How can I know what bars array was used for the entry?

    What I'm doing now is I create my entrySignal so that it contains the bars array and I exit using the entry signal parameter so it only exits on the right timeframe. the only disadvantage to this is that I submit exit orders that are not valid (due to the entry signal not matching), and that I don't know ahead of time if the exit will work.

    Is there a better way?

    #2
    Hi cunparis, could you please post some of your entry / exit codes as sample? Also you can also use BarsInProgress() to check which Bars object has called the OnBarUpdate() and then submit your orders - http://www.ninjatrader-support.com/H...BarSeries.html

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Hi cunparis, could you please post some of your entry / exit codes as sample? Also you can also use BarsInProgress() to check which Bars object has called the OnBarUpdate() and then submit your orders - http://www.ninjatrader-support.com/H...BarSeries.html
      Hi Bertrand thank you for your offer to help. Here is my entry & exit:

      Code:
                          EnterLong(1, 1, "L" + BarsInProgress);
      
                          ExitLong("exit", "L" + BarsInProgress);
      What I'm doing is using BarsInProgress to tag my entries so that I can see what timeframe I used in the list of trades and also so I can match up my exit.

      With the exit, when the exit condition is met on each timeframe, it will try to exit. Only the right one will succeed. I think it's a bit sloppy. What I'd like to know is there a way to get the BarsArray of the current position. Like this:

      Code:
      // Made up the next line just for this example
      if(Position.BarsArray == BarsInProgress) {
        ExitLong("exit", "L" + BarsInProgress);
      }
      If this isn't possible then there is another choice: I store the BarsArray of the entry in a variable.

      Thanks

      Comment


        #4
        Hi cunparis, I see thanks - you could check into the Positions array for your code - http://www.ninjatrader-support.com/H...Positions.html

        Although I'm not 100% sure, because it's normally used in a multi instrument context...

        The variable way looks straightforward to me...

        Merry Christmas!

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          Hi cunparis, I see thanks - you could check into the Positions array for your code - http://www.ninjatrader-support.com/H...Positions.html

          Although I'm not 100% sure, because it's normally used in a multi instrument context...

          The variable way looks straightforward to me...

          Merry Christmas!
          The Positions array won't work because it's per instrument. So Positions[0] will contain the position whether it was entered on barsarray 0 or 1.

          Looks like the variable way is the way to go. I'll have to use a hashtable because it's multi-instrument.

          Thanks and Merry Christmas to you too!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          647 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X