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

Strategy Array out of Bounds Error or Output CancelAllOrders: BarsInProgress = 0

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

    Strategy Array out of Bounds Error or Output CancelAllOrders: BarsInProgress = 0

    After many different attempts at this I figure it is time to ask the experts.

    I am building a multi-timeframe strategy that uses 2 timeframes on 1 instrument. The shorter timeframe is BarsArray[0] and the longer is BarsArray[1].

    The strategy has 4 entry conditions and 4 exit conditions which create limit orders. The limit orders use a calculated double as the entry price. The Entry and exit conditions use data from both BarsArray[0] and BarsArray[1]. The Entry and Exit price targets use data from BarsArray[1]. Please see the sample code below for EntryTarget1, ExitTarget1, Entry Condition 1 and Exit condition 1 as a sample.

    When I run the strategy, I either get the log error:
    Strategy Array out of Bounds Error (If I start the strategy with BarsInProgress == 0
    or Output CancelAllOrders: BarsInProgress = 0 (If I start the strategy with BarsInProgress != 0

    Do you have any suggestions on how to get this strategy to run on a single instrument referencing a couple of timeframes? (I've gone through Help and the forum numerous times already)

    protectedoverridevoid OnBarUpdate()
    {
    if (BarsInProgress == 0)
    return;
    {
    // Set Target Limit Trigger Price for Long Entry 1 (Referred to as "LEa" on charts)
    double longEntry1 = IndicatorValuesfrom(BarsArray[1]);




    // Set Exit Target Limit Trigger Price for Long Exit 1 (Referred to as "LX1" on charts)
    double longExit1 = IndicatorValuesfrom(BarsArray[1]);




    // Condition set 1 Entry Condition1
    if (BarsInProgress == 0)
    {
    if (Entry conditionA from BarsArray[1] and ConditionsB-D from BarsArray[0] are true)
    {
    EnterLongLimit(DefaultQuantity, longEntry1,
    "LEa");
    }



    // Condition set 2 ... Exit Condition 1
    if (BarsInProgress == 0)
    {
    if (Position.MarketPosition == MarketPosition.Long
    && Exit ConditionsA-C from BarsArray[0] are true)
    {
    ExitLongLimit(longExit1,
    "LX1","");
    }
    }

    #2
    Hi Learning1,

    Did you manage to get you strategy to compile?
    Code:
    [FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (BarsInProgress == [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])
    [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];
    {[/SIZE][/FONT][/SIZE][/FONT]
    This should have already provided you with errors. You need another if statement or an else statement to use that bracket. If you don't mind could you provide some more precise code for debugging. Please attach a simple as possible strategy demonstrating your issue and I will take a look for you.

    Last edited by NinjaTrader_JoshP; 09-19-2007, 09:25 PM.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank for the help and here is the generic code.

      Hi Josh,

      Thanks for the willingness to help. I've pasted the code below (after making a bunch of indicators, plots and variables generic which in my hastiness created a bunch of poor syntax in calling the indicators - this all compiles fine in the code itself). I'm thinking the core challenge is in the way different targets, entry and exit signals are calling data from the 2 different BarsArrays. Both BarsArrays are on the same instrument and BarsArray[0] is a shorter timeframe than [1].

      Thanks for giving this some thought and expertise!

      Learning1
      Attached Files

      Comment


        #4
        Okay Learning1. I don't know how your compiler is compiling the txt file you provided. I'm not sure of the exact behavior you are describing so can you create a super simplified version of your strategy that displays the challenge you are facing then please upload the .cs file for me. It is hard to decipher what exactly you are doing from the code snippets you provided.

        I think I have an idea of what you are seeing, but if you could provide the .cs file I will know exactly what you are experiencing and can provide further assistance from there.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Sorry about that Josh, The code in the txt file doesn't compile.

          Here is a simplified attached cs file that has the same sort of structure, though with only 2 entries and exits. The concept is to have limit orders (entry and exit) start at when conditions on both the lower and higher timeframe are met for the entry and conditions on the lower timeframe for the exit conditions. As you can see, the target entry prices are determined by indicators that draw only from the higher timeframe.

          Thanks for your patience,

          Learning1
          Attached Files

          Comment


            #6
            Thanks for the file Learning1. I will look into this with more depth for you today and report back with my findings.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Hi Learning1,

              The immediate thing that comes to attention is still your very first if statement. At the very start you are asking the strategy to see if it is BarsInProgress 0. If it is 0 you return or do nothing. This means it stops processing the rest of your algorithm completely. The later parts in your code you go
              Code:
              if (BarsInProgress == 0)
              again. This does absolutely nothing because it will never be processed. You already told the strategy to stop if BarsInProgress == 0 so it will never reach that point in your code to ever enter any orders. I suspect this is why you are getting the CancelAllOrders thing. You have no possibilies of any orders being sent with the current strategy.

              I have reattached your sample code with my changes. You will find that the strategy now does take trades and also outputs trace orders as expected.
              Attached Files
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Thanks Josh,

                Good points. I'll make the suggested changes to my strategy and let you know how the multiple entry / exit conditions process. Thanks for all the help,

                Learning1

                Comment


                  #9
                  Hi There,

                  I made the suggested changes and everrything works nicely on the entry side of things. However, once there is a postion, there should immediatley be a stop order and a target limit order. The stop order is placed and the limit order is also placed (and modified as the trade progresses).

                  However, the target limit order is also immediately ignored with a string of messages in the output window each saying:

                  Ignored PlaceOrder () Method .... Reason: 'There already is a matching, terminal exit order in place'

                  However, there is no limit exit order in the orders tab.

                  Suggestions?

                  Comment


                    #10
                    Instead of placing an ExitLongLimit() order for your profit target take a look at using SetProfitTarget().
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      From what I could see in the link, the SetProfitTarget is a specific number of ticks. In the strategy, the profit targets move with market conditions and are driven from indicators. This was the rationale for the Limit Exit Orders. I can certainly try the SetProfitTarget, but I'm a bit confused how that would create any different behavior than the limit exit orders that are being ignored and cancelled. Can you think of any reason the output window would be returning "Ignored PlaceOrder () Method .... Reason: 'There already is a matching, terminal exit order in place'?"

                      Comment


                        #12
                        SetProfitTarget() can be calculated from either ticks, price, or even percentages. Check out the CalculationMode parameter. As for why you are getting the already existing terminal exit log trace, I cannot comment on it without seeing the complete trace log. I would suspect it has to do with an order already in the pending or working state that is already tied to your particular entrySignalName. If you don't mind could you provide me with the strategy, trace order log, trace log, and NT internal logs? I also suspect it could be related to a previous bug we were able to find and are working on fixing.
                        Last edited by NinjaTrader_JoshP; 09-24-2007, 07:50 PM.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          You can change the price of targets as well. See the following reference sample for some ideas.

                          RayNinjaTrader Customer Service

                          Comment


                            #14
                            Thanks for the learning guys. The SetProfitTarget Method is working fine on the multiple exits. Is there a way to name a specific profit target exit? (As there are multiple exits, it would very helpful as I am refining strategy to know which part of the exit logic is triggering the ProfitTarget price at which exit). As I have currently coded it, the exit looks like this:
                            // Condition set 5 ... Exit Condition 1
                            if (BarsInProgress == 0)
                            {
                            if (Position.MarketPosition == MarketPosition.Short
                            && Other conditions are met
                            )
                            {
                            SetProfitTarget(CalculationMode.Price, shortExit1);
                            }
                            }

                            This is executing the order, but does not label the chart with a unique identifer to distinguish this exit from one generrated by the logic from an exit generated by shortExit2 or ShortExit3.

                            It isn't critical to label each unique exit, but it would be helpful.

                            Thanks for all you help.

                            Learning1

                            Comment


                              #15
                              Unfortunately I am not aware of a way to uniquely label the profit target order labels on the chart, but you could set unique profit targets associated with your various entry orders.

                              Code:
                              SetProfitTarget(string fromEntrySignal,  CalculationMode mode, double value)
                              So if your entry logic was
                              Code:
                              EnterLong(100, "Enter1");
                              you could limit your profit target to only handle that case with
                              Code:
                              SetProfitTarget("Enter1", CalculationMode.Ticks, 10);
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by tkaboris, Today, 08:01 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by Lumbeezl, 01-11-2022, 06:50 PM
                              31 responses
                              817 views
                              1 like
                              Last Post NinjaTrader_Adrian  
                              Started by xiinteractive, 04-09-2024, 08:08 AM
                              5 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by swestendorf, Today, 11:14 AM
                              2 responses
                              6 views
                              0 likes
                              Last Post NinjaTrader_Kimberly  
                              Started by Mupulen, Today, 11:26 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post Mupulen
                              by Mupulen
                               
                              Working...
                              X