Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Optimization running very slow...
Collapse
X
-
Optimization running very slow...
I am running an optimization that includes a custom New High/New Low indicator, as well as, an Adv/Dec ratio custom indicator in the program. Problem is that when I run the optimizer, NT pulls in the respective data each and every scenario. What use to take seconds to run 100 scenarios, now take about 1 seconds for each scenario. This makes testing 1000+ scenarios damn near impossible because it is taking over an hour and half, as well as, almost overheating my CPU. Any ideas on what I may be doing wrong? I broke down the indicators and rebuilt in the specific backtest program itself, but that did not speed anything up. Thanks for opinions/help...Tags: None
-
Here is the Strategy.
No Bool Inputs, but don't know about the enums. Could it be that I am running ratios on the indicators that is slowly it down?
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Enter the description of your strategy here
/// </summary>
[Description("Enter the description of your strategy here")]
public class NHNLAdvDecQQQ : Strategy
{
#region Variables
// Wizard generated variables
private double enterAdvBear = 0.47; // Default setting for EnterAdvBear
private double enterAdvBull = 0.42; // Default setting for EnterAdvBull
private double exitAdvBear = 0.37; // Default setting for ExitAdvBear
private double exitAdvBull = 0.365; // Default setting for ExitAdvBull
private double enterNHNLBear = 0.61; // Default setting for EnterNHNLBear
private double enterNHNLBull = 0.66; // Default setting for EnterNHNLBull
private double exitNHNLBear = 0.50; // Default setting for ExitNHNLBear
private double exitNHNLBull = 0.44; // Default setting for ExitNHNLBull
private double ratio50vs200 = 1.01;
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (DailyImpulseNASD(10).Signal[0] >= EnterAdvBull
&& NHNLnasd(10).Plot0[0] >= EnterNHNLBull
&& EMA50vs200(200, 50).Plot0[0] >= Ratio50vs200)
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (DailyImpulseNASD(10).Signal[0] >= EnterAdvBear
&& NHNLnasd(10).Plot0[0] >= EnterNHNLBear
&& EMA50vs200(200, 50).Plot0[0] < Ratio50vs200)
{
EnterLong(DefaultQuantity, "");
}
// Condition set 3
if (DailyImpulseNASD(10).Signal[0] <= ExitAdvBull
&& NHNLnasd(10).Plot0[0] <= ExitNHNLBull
&& EMA50vs200(200, 50).Plot0[0] >= Ratio50vs200)
{
ExitLong("", "");
}
// Condition set 4
if (DailyImpulseNASD(10).Signal[0] <= ExitAdvBear
&& NHNLnasd(10).Plot0[0] <= ExitNHNLBear
&& EMA50vs200(200, 50).Plot0[0] < Ratio50vs200)
{
ExitLong("", "");
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public double EnterAdvBear
{
get { return enterAdvBear; }
set { enterAdvBear = Math.Max(0.1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double EnterAdvBull
{
get { return enterAdvBull; }
set { enterAdvBull = Math.Max(0.1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double ExitAdvBear
{
get { return exitAdvBear; }
set { exitAdvBear = Math.Max(0.1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double ExitAdvBull
{
get { return exitAdvBull; }
set { exitAdvBull = Math.Max(0.1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double EnterNHNLBear
{
get { return enterNHNLBear; }
set { enterNHNLBear = Math.Max(0.1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double EnterNHNLBull
{
get { return enterNHNLBull; }
set { enterNHNLBull = Math.Max(0.1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double ExitNHNLBear
{
get { return exitNHNLBear; }
set { exitNHNLBear = Math.Max(0.1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double ExitNHNLBull
{
get { return exitNHNLBull; }
set { exitNHNLBull = Math.Max(0.1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public double Ratio50vs200
{
get { return ratio50vs200; }
set { ratio50vs200 = Math.Max(0.1, value); }
}
#endregion
}
}
Comment
-
Thanks for the code snippet. Right, no bools or enums there. There have been fixes in this area to improve performance but it will also depend on how many combinations you're testing at a time. Optimizing by its nature can be a time consuming task and sometimes best left to do while your computer is unattended.
I would first make sure you are running the latest release (10) from here:
If you find that optimization is still slow even with a reasonable amount of tests, please post a screenshot of your optimization setup (showing the parameters and ranges you're testing) so we could setup a similar test here.Ryan M.NinjaTrader Customer Service
Comment
-
Do you just want the Strategy?
I can zip it and upload it. It's a simple NewHighs/NewLows Ratio and Adv/Dec Ratio... Buy Sell test. I am using some custom Instruments and inputting data via Kinetics
Comment
-
Snapshot
Attached PNG. Now, I know I have been a piker and have not purchased NinjaTrader yet. I have been trying to learn all the programming language and work out my High Prob trades in trial mode before going live with actual cash. I REALLY appreciate all the support your company gives. That being said, I have many, many strategies that use built in indicators: ADX, BB, EMAs, Trails... I have even built a few myself 50vs200ema, ROC, etc. None of these run slowly, even when I am running an optimization with 10,000 variables. Once I add the McClellan Osc or these two indicators, it slow the system down to a crawl. It seems any data with New Highs and New Lows takes forever. I have included the indicator for your trial. Let me know what you think. Thanks!
Comment
-
I did not know you mean LITERALLY...
Here it is again, in Optimization Mode. As you can see, I have asked NJT to run 3x5x4x3= 180 scenarios. The estimated time to complete the task eventually leveled of to 10:32. That means it is running one scenario every 3.5 seconds. Now if you look at the 2nd PNG, you will see that I set up 270 combinations. This scenario ran in 6 seconds TOTAL. This ran at 1 scenario every .02 seconds. This is the problem. Any ideas. Thank you!!
Comment
-
I see, thanks for the updated screenshot. I haven't been able to setup a similar test since the strategy you posted uses different indicator than the ones you shared. If you can post one .zip file with everything I need I'm happy to check it out.
One step you could take here is try with a new database. If you do not gain any performance here with new db, then it can be restored.
Please rename your database with the following steps :
- Shutdown NinjaTrader and Go to the Start Menu
- Select My Documents--> NinjaTrader 7--> DB--> NinjaTrader.SDF.
- Right click on NinjaTrader.SDF and select "Rename." *Name it "OLDNinjaTrader.SDF."
- Then restart the software and NinjaTrader will create a fresh database file to use
- Unfortunately the following items stored in the old database will be lost – ATM Strategy templates, Session templates, Instrument Lists / Custom Instruments and historical trade execution data
To prevent running into situations where you can potentially lose important data, we advise to run regular backups via our inbuild backup feature in NinjaTrader - http://www.ninjatrader.com/support/h...up_archive.htmRyan M.NinjaTrader Customer Service
Comment
-
Here it is...
Please see if you can replicate they delay. Please check the code of indicators since I think I have a set of custom symbols.
Also, you are suggesting that the database is corrupt. If so, it should delay ALL the opti runs, should it not? Just wondering before I go through that step.
*** I THINK they delay may be caused by the McClel Osc program or the need to compile the NHNL ratio/ AdvDec ratio. I just don't know why THAT is a particular data problem, when other indicators also pull in price data to compile their output without a problem ***Attached Files
Comment
-
Ok, I am really confused now...
Did what you said. Started with new database. Updated Indicators to reflect default NYSE Adv and NYSE Decl symbols and New Highs/New Lows. Ran an optimization which would run 180 scenarios and, unfortunately, again, it was going to take 10minutes.
Did you run an optimization with more than 1 scenario? I am about to give up
I am uploading just the Daily Impulse strategy, it is using default instruments. Run a scenario that scans Adv from .40 thru .60 at .02 intervals. Also, Dec, the same, .40 thru .60 at .02 intervals. Please tell me what your time required to complete the task is. I am running this on a Quad core AMD processor with 16GB RAM. It is a very fast machine. Again, it would take 10 minutes...Attached Files
Comment
-
It takes a couple minutes now to optimize for one instrument. Nothing really seems excessive and the bulk of this is spent downloading data. If you are connected, then it will request this data each time. If you already have the data though, then this step is unnecessary and you can likely speed up by first disconnecting from any data providers and then optimizing.Ryan M.NinjaTrader Customer Service
Comment
-
Still VERY slow...
Sooooo, I ran the Opt while not connected and that did not help any. From your comments, you too are experiencing a long lag to process a relatively few scenarios, as well. Do you know the WHY that is causing this. EMA crosses, RSI enter/exits, etc do not require the same length of time to run each scenario. WHY do you think asking the system to run NewHighs vs. NowLows slows things down so much. Thank you again for all your time on this...
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
666 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
377 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
110 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
575 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
580 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment