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

Need Some Help On Lists...

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

    Need Some Help On Lists...

    Howdy All--

    I have been working with Matthew to work through adding lists to an indicator that I have built, and I am running into a few problems.

    Currently I have created the lists in the Variables( ) method.

    My indicator then indicates a trade, and from that trade I am adding the entry price, stop price, MAE and MFE, as well as incrementing a trade counter that was started at 0 and increments by 1 for each trade. Therefore, each trade has a unique trade number between 0 and n.

    I'm then trying to run a for loop (i = 0; i <= list.Count; i++) that runs through some logic to see if the current bar's high and low increase the MFE, decrement the MAE, trigger a stop (which is defined) or do nothing. So the idea is that the for loop runs through each list and refreshes each trades MAE and MFE.

    I am currently able to compile okay, but on the bar immediately after my indicated trade, the indicator stops producing trades and I am getting the "You are accessing an index with a value that is invalid since its out of range." The trade is indicated at bar 63, and the error is triggered on bar 63 (ie, so nothing happens from bar 64 on).

    I do have the following code at the top of the OnBarUpdate ( ) method:

    if(CurrentBar < 1)
    {
    return;
    }

    But clearly this is not the issue.

    Does anyone have any ideas on why this might be happening? This is my first time using lists.

    Thanks for your help in advance. I REALLY appreciate it.

    All best,

    Aventeren

    #2
    Originally posted by aventeren View Post
    Howdy All--

    I'm then trying to run a for loop (i = 0; i <= list.Count; i++) that runs through some logic to see if the current bar's high and low increase the MFE, decrement the MAE, trigger a stop (which is defined) or do nothing. So the idea is that the for loop runs through each list and refreshes each trades MAE and MFE.

    I am currently able to compile okay, but on the bar immediately after my indicated trade, the indicator stops producing trades and I am getting the "You are accessing an index with a value that is invalid since its out of range." The trade is indicated at bar 63, and the error is triggered on bar 63 (ie, so nothing happens from bar 64 on).

    I do have the following code at the top of the OnBarUpdate ( ) method:

    if(CurrentBar < 1)
    {
    return;
    }

    But clearly this is not the issue.

    Does anyone have any ideas on why this might be happening? This is my first time using lists.

    Thanks for your help in advance. I REALLY appreciate it.

    All best,

    Aventeren
    list.Count is the number of elements contained in your list. Therefore your loop should run from i = 0 to i = list.Count - 1.

    Example: If your list contains 5 elements, the loop should run from 0 to 4 (0,1,2,3,4) and not from 0 to 5. When you try to access the sixth element of your list, the code will produce an exception, because your list only contains five elements.

    Just try

    Code:
    for loop (i = 0; i < list.Count; i++)

    Comment


      #3
      Originally posted by Harry View Post
      list.Count is the number of elements contained in your list. Therefore your loop should run from i = 0 to i = list.Count - 1.

      Example: If your list contains 5 elements, the loop should run from 0 to 4 (0,1,2,3,4) and not from 0 to 5. When you try to access the sixth element of your list, the code will produce an exception, because your list only contains five elements.

      Just try

      Code:
      for loop (i = 0; i < list.Count; i++)
      Thanks for your help.

      Did you mean:

      Code:
      for loop (i = 0; i < list.Count-1; i++)

      Comment


        #4
        Harry, well played: this change allows the indi to run. It's now doing some other things that I may post up if I can't figure out how to understand and troubleshoot them, but at this point I'm encouraged to see the first 3 trade's trade number, entry prices, stop prices, MAE price, MFE price and MAE in ticks and MFE in ticks. Now I just need to figure out why the list appears to be stopping at the 3rd bar.

        Comment


          #5
          So I learned something weird today, the Output window was only showing the trades that the chart was showing. In other words, if the Chart was showing trades 21-25, the output window would show the data for trades 1-25 only. Then, if I panned the chart all the way to the hard right edge revealing trades 100-108, the output window would then show data for trades 1-108.

          I'm not sure why it does this, but it does. So hopefully anyone that comes across this will better understand this issue in the future.

          It all works. Amazing.

          Comment


            #6
            Hello aventeren,

            Glad to hear that it is working for you.

            The Output Window is going to show you everything your strategy is doing and running since your Strategy is first started so it should always start at the begging or your first trade and everything after that.

            This is so you can see how your strategy is being processed from start to finish to ensure it is working as you expect and to debug any code if needed.

            Let us know if we can be of further assistance.
            JCNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Barry Milan, Today, 10:35 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by WeyldFalcon, 12-10-2020, 06:48 PM
            14 responses
            1,428 views
            0 likes
            Last Post Handclap0241  
            Started by DJ888, Yesterday, 06:09 PM
            2 responses
            9 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            40 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Today, 08:51 AM
            2 responses
            16 views
            0 likes
            Last Post bill2023  
            Working...
            X