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

  • NinjaTrader_Matthew
    replied
    Glad to hear everything is working.

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

    Leave a comment:


  • aventeren
    replied
    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

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    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.

    Leave a comment:


  • aventeren
    replied
    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.

    Leave a comment:


  • aventeren
    replied
    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.

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    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.

    Leave a comment:


  • aventeren
    replied
    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!

    Leave a comment:


  • aventeren
    replied
    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.

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    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.

    Leave a comment:


  • aventeren
    replied
    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!

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    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.

    Leave a comment:


  • aventeren
    replied
    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

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    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

    Leave a comment:


  • aventeren
    replied
    DataSeries vs Array

    Matthew--

    Another question on the DataSeries versus Array approach. From what I understand about DataSeries, the syntax is myMFE[1] is equivalent to the MFE from 1 bar ago. However, my trades will not be keyed to bars ago, but rather a uniquely assigned trade number that will increment each time a trade is made. Therefore I was thinking that myMFE[14] would refer to the MFE for trade #15, which is not the MFE from 14 bars ago. Do you see the distinction?

    Given the above, do you think that a DataSeries is still the best structure or should I instead consider using an Array or an ArrayList?

    Thanks for your help--I REALLY appreciate it.

    All best,

    Aventeren

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    The data series will only hold as many bars you have on the chart. There are no limits i'm aware of beyond.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by SalmaTrader, 07-07-2026, 10:26 PM
0 responses
36 views
0 likes
Last Post SalmaTrader  
Started by CarlTrading, 07-05-2026, 01:16 PM
0 responses
20 views
0 likes
Last Post CarlTrading  
Started by CaptainJack, 06-17-2026, 10:32 AM
0 responses
14 views
0 likes
Last Post CaptainJack  
Started by kinfxhk, 06-17-2026, 04:15 AM
0 responses
20 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Started by kinfxhk, 06-17-2026, 04:06 AM
0 responses
22 views
0 likes
Last Post kinfxhk
by kinfxhk
 
Working...
X