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

How to sample intra bar data while backtesting?

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

  • NinjaTrader_Jesse
    replied
    Hello Blaze212,

    It sounds like you may have a problem with your install or have something imported that is causing an issue, you should not be seeing high ram usage with the sample. I would suggest doing a clean install to retest and make sure the ram use is lower.

    Use the following steps to do a clean user folder test.
    1. Exit NinjaTrader
    2. Open the Documents folder
    3. Rename the NinjaTrader 8 folder to NinjaTrader 8 Old
    4. Download the installer from https://account.ninjatrader.com/download
    5. Install the platform, this will create a new user folder.
    6. Open the platform and repeat the sample test
    If you need to revert back to your previous data use the following steps.
    1. Exit NinjaTrader
    2. Open the Documents folder
    3. Rename the NinjaTrader 8 folder to NinjaTrader 8 Clean
    4. Rename the NinjaTrader 8 Old folder to NinjaTrader 8

    NinjaTrader looks for the folder named NinjaTrader 8 for your user data.

    Regarding the indicator drawing, if it uses drawing objects in its code those still have to be created when doing a backtest even if the indicator is not being visually added. Each drawing object is similar to calling an indicator, it produces an instance which you can retrieve values from. Due to that each instance will take some resources. You can see high ram use in an optimization because of this but only when a lot of objects will be drawn.

    Leave a comment:


  • Blaze212
    replied
    So I ran the sampleMACrossOver and it racked up 10GB of RAM for a 6 month run. The seems high but I guess that just the baseline I have to work with. I ran it again with just 1 month and it only hit 2GB. I then added a 15 data series and it essentially hit 2GB again and maybe like 10 or 20MB higher but that's exactly what I expected.

    My follow up question. If my indicator when added to a chart draws, when I run it in the strategy analyzer it it draw even if I'm not calling `AddChartIndicator` in my strategy.
    My expectation is, no there is not rendering logic being hit, and based on my test where I copied trhe sampleMACrossOver and just commented out the `AddChartIndicator` and it used exactly the same amount of RAM.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello Blaze212,

    High ram use can be caused by using items like drawing objects however the ram use heavily depends on what you are doing in code. To figure out why it is using a lot of memory you would need to debug the code to see which part of the code relates to that result. Just as a simple test you can try the sampleMACrossOver in the same use case and that should produce less memory use to confirm some part of your code is causing that to happen.

    In regard to the amount of parameters that you want to optimize, that may not be a realistic test based on how many permutations that would cause the optimizer to create. The optimizer tool is best used for targeting specific ranges for parameters, the less parameters to optimize at once the shorter and less resources the test will take.


    Leave a comment:


  • Blaze212
    replied
    Following up, there is actually a resource leak in the Ninja Trader backtester in general... I can run a single backtest with 6 months of tick data and it consumes 40GB of RAM. When the test finished it does not release the 40GB. I then kick off another backtest and my RAM usage climbs to 64GB of RAM and starts paging to disk. At this point I just kill Ninja Trader....

    I've tried calling to GC.collect() in the State.Terminated state and setting all of my data series to null, but neither seemed to help.

    The only work around is to run a single test, restart ninja, and then run a new test.

    I've attached screenshot to show the issue. My strategy loads in tick data as one of its data series.

    Ninja Start up with a few hundred MB of RAM. When I kick off the strategy it jumps to 6.5GB fairly quickly, paused for a few seconds there then quickly climbs and hold around 40GB. Once the run finishes the 40 GB are never released. I waited 5 plus minutes after a run have finished and never seen it drop, I also tried closing and re-opening the strategy analyzer window. I then kicked off run 2 which jumped to 45GB held for a few seconds there and the ran up until my RAM was at max capacity.

    Ninja never released the RAM from the first run... The attached screenshots document this process.

    Attached Files

    Leave a comment:


  • Blaze212
    replied
    Thanks for the quick reply. I've updated my strategy to not need the intra bar calculation so that I can utilize the backtester.

    I'm using tick level data to run the back test and overflows my 64GB of RAM when running the optimizer at which point it never finished cause paging our of RAM is painfully slow... This appears to be a common problem with ninja trader 8 as I've read many forum posts about huge ram usage but not real solutions....

    My current workaround is to set my parameters to only allow 8 runs and do a 1 month test. What I really want to is run ~1000 different parameter combination over 6 months.

    Is there a way to force the optimization to not use all 16 of my cores and run single threaded? That would allow me to kick off the run and have it eat up 10GB and not start paging our of RAM. It's really painful to have to manually kick of 100's of runs just because the optimizer bring the test to a screeching halt when running 16 items in parallel. I'd be fine kicking off a single run that took a day to complete, but right now I have to sit in front of my computer and kick of each run every 10 minutes which my back testing will take hours of active time...



    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello Blaze212,

    Calling the 1 minute indicator from a 1 second series will always yield the last closed price which will be in intervals of 1 minute. The indicator originally used 1 minute data so it only has values for each 1 minute bar, those won't change for 60 seconds if you are calling that series from the 1 second series. In realtime once you pass historical processing the 0 bars ago value represents the building bar so the value could be updated intrabar at that point, to test this more accurately you would need to use the playback connection so you can play forward in realtime.

    Leave a comment:


  • Blaze212
    started a topic How to sample intra bar data while backtesting?

    How to sample intra bar data while backtesting?

    I have a customer indicator that updates on each tick. While backtesting a strategy my strategy instantiates my indicator with both the 1 minute and 1 seconds bars series.
    I need to sample the 1 minute indicator at 1 second. When I do this during backtesting the returned values is identical for every sample of the 1 minute bar though. It only changes when the 1 minute bar advanced to the next minute.

    This does not mimic the realtime behavior of the indicator because I see it updating the indicator value for each tick when attached to a chart.

    How can I sample the 1 minute indicator at 1 second intervals while backtesting?

    Sample Psuedo Code

    ```OnStateChange()
    {

    ...
    else if (State == State.Configure)
    {​
    vals1Min = MyInticator(BarsArray[ONE_MIN]);
    vals3Min = MyInticator(BarsArray[ONE_SEC]);​
    double[] sampled1Min = double[10];
    ...
    }
    ...
    }

    OnBarUpdate(){


    if (BarsInProgress == ONE_SEC)
    {​
    sampled1MinPrev[idx] = vals1Min[0];

    }


    }

    ```

Latest Posts

Collapse

Topics Statistics Last Post
Started by Mr Bread, Today, 06:21 AM
1 response
11 views
0 likes
Last Post Mr Bread  
Started by tonydavisonline, Yesterday, 08:01 AM
1 response
26 views
0 likes
Last Post tonydavisonline  
Started by cbentrikin, Today, 05:30 AM
1 response
10 views
0 likes
Last Post cbentrikin  
Started by slimtrading, 04-05-2024, 04:23 PM
4 responses
192 views
0 likes
Last Post Sam2515
by Sam2515
 
Started by bltdavid, 03-04-2023, 05:05 PM
13 responses
1,335 views
0 likes
Last Post Gerry-N
by Gerry-N
 
Working...
X