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

Proper approach to coding an indicator inside another indicator

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

    Proper approach to coding an indicator inside another indicator

    Hello Again:

    I have created an indicator called jelABG that produces a single plotted result. The plot is correct and this indicator is working as intended. the jelABG indicator is a complex calculation involving 3 different types of moving averages at which each extracted datapoint is involved in an equation and stored in a final Series<double> variable (Values[0]), then plotted.

    I am creating a second indicator, called jelSpread for which I wish to pass the high and low along with a period value into the first indicator (jelABG) or obtain a value to perform calculations on in my second indicator.

    To accomplish this, in my second indicator (jelSpread) I created to variables as follows:

    private ISeries<double> dsHigh;
    private ISeries<double> dsLow;
    In the OnStateChange event where State == State.SetDefaults I have the following:

    dsHigh = new Series<double>(this, MaximumBarsLookBack.Infinite);
    dsLow = new Series<double>(this, MaximumBarsLookBack.Infinite);
    In the OnBarUpDate event I am populating those variables as follows:

    dsHigh = jelABG(High, _barPeriod);

    dsLow = jelABG(Low, _barPeriod);
    The dsHigh and dsLow seem to be populating fine, but I am concerned that I am reloading those variables by rerunning the jelABG indicator with each new bar. Is there a better place for this coding other than the OnBarUpDate event? I need to ensure that as each bar is formed, that I get the latest data from the jelABG indicator.

    Don't get me wrong, this works, I just think I might be using too much system resources taking this approach. It will be fine if it was only one chart, but my setup as 12 charts on 2 monitors open at a time - not including the tabs...

    Thanks,

    #2
    Hello jeliner,

    Thank you for your post.

    The OnBarUpdate override would be needed if you want to recalculate this value each bar that is processed.

    Because you are supplying the high and low to the indicator, that will change its input parameters so a cached copy of the indicator would not likely be used. I couldn't really suggest any other location for this logic, however, if you do not need to call this on every OnBarUpdate you could look at ways to correct that using logic.

    Outside of using logic to control how frequently this is called, you would likely need to look into alternate ways to do your calculation in a more efficient way if it is taking too many resources on your PC.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    3 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    1 view
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    6 views
    0 likes
    Last Post Javierw.ok  
    Started by timmbbo, Today, 08:59 AM
    2 responses
    10 views
    0 likes
    Last Post bltdavid  
    Working...
    X