Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Goal: MAE & MFE tracker given a stop value; seeking programming ideas

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

    #16
    Originally posted by NinjaTrader_Matthew View Post
    Any data series you create is going to contain the same number of elements as there are bars on the chart.

    If you wish to ONLY store your mae/mfe and would like to access these as per the # of trades, then you'd need to use a list.

    Otherwise using a data series, it will refer to the value at the X barsAgo
    Thanks, Matthew. I did a ton of research last night, and I learned that Arrays are super old school and constrictive in that their size has to be defined up front, which means that if you do not know how many trade signals an indi will end up creating, you're stuck with an array size that will likely have to be unnecessarily huge to allow for not knowing how many trades your array will need to handle. I then looked at ArrayList and List, and from what I am seeing, a List may be the best way to store my MAE and MFE values, as the List size can be increased and decreased as necessary (although I will just need to increase it, as I will not be removing items from my List once they are there). So I've settled on using a List at this time to hold my entry prices, MAEs and MFEs.

    So if my understanding of Lists is correct, I can call a foreach loop in the BarUpdate section to scan my list of entry prices to see if the current tick is:

    1. Doing nothing (ie, price is within the MFE and MAE bounds or the stop has already been hit)
    2. Increasing MFE (ie, price has gone higher than the stored MFE value and the stop has not been hit)
    3. Decreasing MAE (ie, price is continuing to move away from the entry price but the stop has not yet been triggered)
    4. Setting MAE to the stop value (ie, price moved more than the stop value away from the entry price, which will lock the MAE at the stop price--which for backtesting purposes will assume no slippage, which I will take into consideration in Excel)

    I am expecting somewhere in the neighborhood of 200-400 entries per CL contract cycle, and I would expect that when I run this sucker that NT will need to chug on it for a LONG time. However, the time that I have to wait for NT to chug will be nothing compared to my current method of doing this all by hand.

    Do you know of any NT7 indis that use the List class that I could look at to get a better idea of how they work?

    I'm always open to suggestions on ways to improve my ideas, so please let me know if you have any additional ideas.

    I REALLY appreciate your help,

    Aventeren

    Comment


      #17
      Hello,

      Yep - you're on the right track, a list would be the best way to handle.

      We do not have any documentation, however the samples from MSDN should get you started:



      Hope that helps.
      MatthewNinjaTrader Product Management

      Comment


        #18
        Originally posted by NinjaTrader_Matthew View Post
        Hello,

        Yep - you're on the right track, a list would be the best way to handle.

        We do not have any documentation, however the samples from MSDN should get you started:



        Hope that helps.
        Matthew--

        I have a quick question on how NT looks at lists. From what I understand, in normal C# lists are indexed using the [ ], such that one can access the 15th item in the list by calling the myList[14] element.

        My question relates to NT's interpretation of lists: when you call myList[14], is NT looking at the 15th item in the list (regardless of how many bars ago that item was added to the list) or is NT trying to grab the item that was placed in the list 14 bars ago?

        Thanks!

        Comment


          #19
          Lists are not tied into the bars array, which would be the advantage of using a custom list over a NinjaTrader data series class.

          Simply put: myList[14] will call the 15th item in the list.
          MatthewNinjaTrader Product Management

          Comment


            #20
            Originally posted by NinjaTrader_Matthew View Post
            Lists are not tied into the bars array, which would be the advantage of using a custom list over a NinjaTrader data series class.

            Simply put: myList[14] will call the 15th item in the list.
            I'm incredibly pleased that you just wrote that.

            Thanks.

            Comment


              #21
              Matthew--

              Can you use Console.WriteLine commands in NT?

              Also, can you use and create DataGrids in NT (like this: http://www.dotnetperls.com/convert-list-datatable)?

              Do you know of any NT indis that use either Console.Write, Console.WriteLine or DataGrids?

              Thanks!

              Comment


                #22
                You cannot access the console, but you can use the NinjaTrader Print() function to write information to the NinjaTrader Output window (Tools--> Output window).

                It would be technically possible to use a data grid view, but would be beyond what I have experience with. Perhaps another member has created a custom form that could help you here.
                MatthewNinjaTrader Product Management

                Comment


                  #23
                  Matthew--

                  When I attempt to utilize a List, I am getting the "You are accessing an index with a value that is invalid since it's out of range." It's saying this this is happening on Bar 63, which is the bar where my indicator is indicating a trade--and also where I am populating the various lists. My entire indicator then goes blank after this--ie, stops from Bar 64 on...

                  Do you have any idea why I might be getting this error?

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

                  if(CurrentBar < 1)
                  {
                  return;
                  }

                  Thanks for your help.

                  Comment


                    #24
                    Matthew--

                    Should I be creating my lists within the Variables( ) method, Initialize( ) method or the OnBarUpdate( ) method? Currently I've created them in the OnBarUpdate( ) method, which logically seems like it might be causing a problem once the lists are used.

                    When I try and create them within the Initialize( ) method, I get a compile error that my listname does not exist in the current context.

                    When I try and create them in Variables( ) method, I can get it to compile but get the "You are accessing an index with a value that is invalid since its out of range" error.

                    Do you have any ideas?

                    Thanks,

                    Aventeren
                    Last edited by aventeren; 08-30-2013, 03:34 PM.

                    Comment


                      #25
                      You can declare the list in the region variables section so it can be accessed from any event method.

                      You would not be able to access the list items in Initalize() as this is called before any bar or trade data is loaded.

                      OnBarUpdate would be the best area to create/update/access the list.
                      MatthewNinjaTrader Product Management

                      Comment


                        #26
                        Originally posted by NinjaTrader_Matthew View Post
                        You can declare the list in the region variables section so it can be accessed from any event method.

                        You would not be able to access the list items in Initalize() as this is called before any bar or trade data is loaded.

                        OnBarUpdate would be the best area to create/update/access the list.
                        Thanks, Matthew. I ended up getting everything to work late Friday. I'm now in backtesting mode. Thanks a ton for your help--I couldn't have done it without you. After populating my lists, I then ran through a for loop to update each entry's MAE and MFE. On the for loop, I had to set the "until" portion to my < tradecount - 1. I had been using the "until" portion of the for loop to just < tradecount. So after making this one adjustment, everything clicked into place.

                        If any other users have questions on how I got my list to work, please don't hesitate to post up your question here.

                        All best,

                        Aventeren

                        Comment


                          #27
                          Glad to hear everything is working.

                          Please let me know if there is anything else I can do for you.
                          MatthewNinjaTrader Product Management

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          578 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          334 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          101 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          554 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          551 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X