08-30-2010, 02:47 PM
|
#1
|
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Indicator: Ensuring indicator plots are valid before programmatically accessing them
Reference sample for NinjaTrader 7.0.xxxx.x or greater.
When accessing NinjaScript indicators in other scripts it is important to check if the hosted indicator's plot values are already set prior to use in the hosting script. This check ensures that proper values are always used and that irrelevant values do not throw off the script logic. This reference sample demonstrates how to run these checks in a hosting indicator by checking another hosted indicator for set plot values.
Another example for when you would want to use this is if you were trying to access the Pivots indicator, but did not have enough days loaded to properly calculate those values yet. Basing logic on the Pivots in such a scenario would yield values that are not useful and can be detrimental if not handled correctly in your code.
This reference sample demonstrates the following concepts:- Checking indicator plots for valid values
- Handling logic for when the indicator plots are not valid
Important methods and properties used include:Import instructions for NinjaTrader 7.0.XXXX.X or greater:- Download the file contained in this thread to your PC desktop
- From the Control Center window, select the menu File > Utilities > Import NinjaScript
- Select the downloaded file
Attached archive contains two indicator files.
- SampleEveryNBarTest is the hosting indicator
- SampleEveryNBar is the hosted indicator
Note: When hosting an indicator in an Indicator column in the Market Analyzer you will need to manually ensure enough bars back are loaded for the indicator to calculate correctly.
Josh
NinjaTrader Customer Service
|
|
|