This free NinjaScript strategy will place simulated trades behind the scenes to feel out the current market conditions. When your defined tracking time starts each day, the Shadow Probe will enter and track hundreds of simulated positions with every stop/target combination in a range you define (e.g. if you set the range to 2-100, the Shadow Probe will run simulated trades with a stop/target of 2/2, 2/3, 2/4…… all the way to 100/99, 100/100. With this Shadow Probe data you will know the most profitable S/T combination for the day, the most profitable S/T combination under certain conditions (i.e. the S/T combo that performs the best when the ADX is at a certain level), the most profitable S/T combo over the last x minutes, and an infinite number of other ways you can think of to utilize the probe data. It comes out of the box with generic entry criteria (see the “entry logic” region), so you’ll need to add whatever criteria you like to use for direction filtering. The “entry logic” region is where you’ll want to start, just replace the example logic there to start experimenting.
If you’re looking for an indicator version you can find that here. The indicator version has properties that are accessible via strategy builder or manually coded strategies.
This NinjaScript download is a single zip file that you import directly into NinjaTrader. It’s not assembled which means you have full access to view and change the source code either in NinjaScript Editor or your preferred way to edit .cs files.
Free vs. Premium Version:
This free version is fully functional and ready for you to use or build off of, but it’s missing a few advanced/powerful features that you will find in the premium version. The free version only places simulated trades serially (i.e. a new 5/6 S/T combination probe trade will only be entered after the last 5/6 S/T trade has been exited. This means that on a wide stop/target combination like 25/25 you might only get a data point every 10 minutes or more for that combo. The Premium version can track multiple probe positions for a single S/T combo simultaneously. You define a time offset variable that will determine the number of seconds between simultaneous probe entries. This means you can sample a new trade every second for a 25/25 S/T combination if you want – this higher sample rate gives you a more realistic view of the current market conditions. The premium version also comes with built in tools to track only the most recent (last x) probe trades instead of keeping a running total for the whole day. You’ll also find tools to clear the probe tracking history on certain events (e.g. every 30 minutes, when MACD hits a certain value, when SMAs crossover), and more. The tools are fully explained in comments in the code.
Details / Instructions:
This strategy must be ran on a 1 tick data series. If you need to access a different time series in the same strategy you can copy and paste this free code to add a secondary time series.
When you enable this strategy with the NinjaScript Output window open, you will immediately see a printout of every stop/target combination that will be tested along with its corresponding index. Technically this index refers to the index of the array that stores your Shadow Probe trades. This information will be handy if you dig deeper and augment the code. As the strategy runs the output window will update with every real-time entry, showing its stop, target, and index. By default, these entries are based on the best-performing Shadow Probe stop/target combination for the day, but you can add to or change the entry criteria in many ways and change the Print() commands to reflect what you want to see. At the end of the day the output window will show you the S/T combination that had the highest daily net profit, both for longs and shorts.
Example output window:
Observing the Print() statements in the NinjaScript code will help you understand how to access the different data available in the Shadow Probe array.
Ideas to augment the probing:
Try lowering the stopTargetMax variable so it’s not tracking S/T all the way to 50.
You could also change this dynamically based on the current volatility or magnitude of recent swings. Leave the stopTargetMax at 50. In the Analyzing Shadow Data region there’s a for loop that finds the max net profit. By default, that loop runs through the whole array to find the max net profit, but you could rewrite that so that it only looks at S/T combos in the array that are <= the size of recent swings.
Try tracking volatility and only run the shadow tracker when volatility is < x. See attached txt for volatility tracking code.
Entering per max recent net profit is just a basic example. You can analyze the array in many other ways other than looking at net profit. You could try entering based on:
A S/T that has a 100% win rate over the last n trades (some might say this is the gambler’s fallacy, but you could say that a S/T with a 100% win rate over the last x trades is more dialed into the current conditions).
Use the break even values of each S/T and enter with the S/T that has the greatest win % over the break even %
Max average profit.
And all of these things (I believe) should only be tracked over a finite moving window (like what profitHistLength does).
One thing you might consider is tracking the time between shadow trades. A high S/T like 50/50 might go an hour before it’s hit depending on your market, which makes it irrelevant when the time frame you’re interested in is in minutes/seconds.
This code will not work with releases prior to NinjaTrader 8. Click here if you don’t know how to install NT strategies. Use at your own risk, and backtest backtest backtest before you go live with any strategy.