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

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
    BertrandNinjaTrader Customer Service

    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!
        BertrandNinjaTrader Customer Service

        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 rtwave, 04-12-2024, 09:30 AM
          2 responses
          19 views
          0 likes
          Last Post rtwave
          by rtwave
           
          Started by tsantospinto, 04-12-2024, 07:04 PM
          5 responses
          67 views
          0 likes
          Last Post tsantospinto  
          Started by cre8able, Today, 03:20 PM
          0 responses
          6 views
          0 likes
          Last Post cre8able  
          Started by Fran888, 02-16-2024, 10:48 AM
          3 responses
          49 views
          0 likes
          Last Post Sam2515
          by Sam2515
           
          Started by martin70, 03-24-2023, 04:58 AM
          15 responses
          115 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X