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

  • aventeren
    replied
    Matthew, is a DataSeries limited in how large the array can be? For instance, I'm looking to backtest each CL contract, and my indicator will create somewhere in the neighborhood of 800 possible entries per 30 days. Will a DataSeries be able to hold 800 elements?

    Thanks,

    Aventeren

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    That would be the safest route as it will stop the iteration once it reaches the end of the array. If you used a for loop, you need to specify when you want the loop to end.

    Leave a comment:


  • aventeren
    replied
    Originally posted by NinjaTrader_Matthew View Post
    Oh I see, yes for point #3 of your original point, you would need to loop through the array to see if these values would change. Sorry for any confusion.
    Cool; so a foreach would be best for looping?

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    Oh I see, yes for point #3 of your original point, you would need to loop through the array to see if these values would change. Sorry for any confusion.

    Leave a comment:


  • aventeren
    replied
    Originally posted by NinjaTrader_Matthew View Post
    Hi,

    Yes, that should work as you'd be able to assign the series a value with each bar and access it when needed. It would likely be 'cleaner' to use two different data series for each metric..

    If i'm following correctly, you shouldn't need to to use foreach as OnBarUpdate will run through each series and can be accessed using myMAE[0]. This should give you the current mae for every tick if you've synced to a 1-tick series.
    Matthew, I've been thinking about your OnBarUpdate comment, and I think that I need to run some sort of a loop to cycle back through all of the myMFE and myMAE DataSeries elements to see whether or not the incoming tick will increment all of the open myMFE items, skip the stopped myMAE items, decrement the open myMAE items, correct? Wouldn't this necessitate that I run some sort of loop to cycle through the DataSeries elements (ie, [0], [1], etc) to see how the incoming tick will update the DataSeries?

    Leave a comment:


  • aventeren
    replied
    Originally posted by NinjaTrader_Matthew View Post
    We do not have an example on this topic, but perhaps this link will help:



    You may find it easier to just write to a text file using StreamWriter:

    http://www.ninjatrader.com/support/f...ead.php?t=3475
    Thanks! I'm off to learn about StreamWriter...

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    We do not have an example on this topic, but perhaps this link will help:



    You may find it easier to just write to a text file using StreamWriter:

    Leave a comment:


  • aventeren
    replied
    Originally posted by NinjaTrader_Matthew View Post
    Hi,

    Yes, that should work as you'd be able to assign the series a value with each bar and access it when needed. It would likely be 'cleaner' to use two different data series for each metric..

    If i'm following correctly, you shouldn't need to to use foreach as OnBarUpdate will run through each series and can be accessed using myMAE[0]. This should give you the current mae for every tick if you've synced to a 1-tick series.
    That makes sense. Thanks.

    Okay, how to I go about printing the DataSeries elements (ie, [0], [1], etc) to a CSV file?

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    Hi,

    Yes, that should work as you'd be able to assign the series a value with each bar and access it when needed. It would likely be 'cleaner' to use two different data series for each metric..

    If i'm following correctly, you shouldn't need to to use foreach as OnBarUpdate will run through each series and can be accessed using myMAE[0]. This should give you the current mae for every tick if you've synced to a 1-tick series.

    Leave a comment:


  • aventeren
    replied
    Originally posted by NinjaTrader_Matthew View Post
    The native Performance methods will only give you the Average MAE/MFE from the collection of trades. If you want to calculate these for each trade and update tick per tick, you'd need to develop a custom method for calculating these values and then updating them with each incoming tick.

    For backtesting purposes, you would need to Add() the 1-tick series in order for you to recalculate these values.

    As far as storing them, you should can just store them in an array using the DataSeries class.

    Information on how to Sync a custom data series can be found below:

    Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series<T> (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for


    Please let me know if you have any questions.
    Thanks, Matthew; so you believe that I should use a DataSeries as the mechanism to store, assess and report each trade's calculated MAE and MFE? Do you think I should use two separate DateSeries--one for the MAE and one for the MFE values? For instance, let's say we're talking about trade 15, then if I created two separate DataSeries for the MAE and MFE, then [14] element in each DataSeries would correspond to the 15th trade?

    Also, in terms of incrementing through the DataSeries on each BarUpdate, would I use a "foreach" command to increment through the DataSeries?

    Thanks for your help and advice--I REALLY appreciate it.

    Leave a comment:


  • NinjaTrader_Matthew
    replied
    The native Performance methods will only give you the Average MAE/MFE from the collection of trades. If you want to calculate these for each trade and update tick per tick, you'd need to develop a custom method for calculating these values and then updating them with each incoming tick.

    For backtesting purposes, you would need to Add() the 1-tick series in order for you to recalculate these values.

    As far as storing them, you should can just store them in an array using the DataSeries class.

    Information on how to Sync a custom data series can be found below:

    Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series<T> (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for


    Please let me know if you have any questions.

    Leave a comment:


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

    Howdy all--

    I have built a custom indicator that produces entry signals given some conditions that I was interested in watching. The indicator works great, and it does the thinking for me so that I can focus on context.

    I would like to do a bit of back testing on it, and I am seeking some advice and counsel on how I might go about accomplishing the following high level objectives:

    1. I want to assign each indicator entry with an entry price, Maximum Adverse Excursion ("MAE") and Maximum Favorable Excursion ("MFE") for each incoming tick.

    2. Then, for each incoming tick, I want each entry's MAE and MFE to be updated.

    3. If the incoming tick pulls price through a user defined stop value (in ticks) for one of the entries, I would like the "stopped" entries to set the MAE to the stop loss value, and then stop incrementing the MFE because the stop has been hit and therefore that trade would be finished.

    4. Therefore, with each incoming tick, entries that had a MAE equal to the stop value would be skipped over.

    5. I then want to export the entries' MAE and MFE to a csv file--or if that is too difficult, to a output window where I could copy the results and then paste them into excel, where I could massage the data to extract the entry number, MAE and MFE from the copied data.

    Given the above, it seems that some sort of an array or DataSeries would be the best vehicle to use, but I'm not quite sure how to go about this. So I'm looking for some high level structure advice and recommendations that I can use to get going. I would hope that the initial high level advice would then allow me to get going, at which point I would ask progressively more detailed questions as necessary.

    So to start off, I'm looking for initial direction (ie, use an array or use a DataSeries or use an ArrayList or whatever), at which point I can google my google off to get going.

    Please do not hesitate to shoot me any questions.

    Thanks in advance!

    Aventeren

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