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

best efficiency when one indicator is called by another indicator

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

  • NinjaTrader_MichaelM
    replied
    Hello microsat,

    Thank you for writing in. Koganam is correct, using the named instance will be most efficient.

    For example:
    Code:
    protected override void Initialize()
    {
        ema = EMA(5);
    }
    protected override void OnBarUpdate()
    {
        double x = ema[0];
    }
    Please let me know if you have any further questions.
    Last edited by NinjaTrader_MichaelM; 11-15-2015, 01:20 PM.

    Leave a comment:


  • koganam
    replied
    Originally posted by microsat View Post
    Inside an indicator, I want to call another indicator.
    My code is below

    Code:
    protected override void OnBarUpdate()
    {
        double x = EMA(5)[0];
    }
    My question is
    Suppose CurrentBar be y, each time OnBarUpdate is triggerred, EMA(5) will be calculated from 1 (y bars before) to y (CurrentBar), won't it?

    I guess it will not be recalculated each time. So is the above code same efficient as
    the following code?
    Code:
    protected override void Initialize()
    {
        ema = EMA(5);
    }
    protected override void OnBarUpdate()
    {
        double x = ema[0];
    }
    My second question is
    are the following two codes same efficiency?
    Code:
    protected override void OnBarUpdate()
    {
        if (CurrentBar  % 1000 == 0)    
             double x = EMA(5)[0];
    }
    Code:
    protected override void Initialize()
    {
        ema = EMA(5);
    }
    protected override void OnBarUpdate()
    {
        if (CurrentBar  % 1000 == 0) 
            double x = ema[0];
    }
    Will one of them get jammed in the 1000th bar because it needs to recalculate 1000 bars' EMA in just a short time (suppose the timeframe is one second)?

    My third question is if one of the following two codes will calculate EMA(5) for five times in one bar.

    Code:
    protected override void OnBarUpdate()
    {
        for (int i=0; i<5;i++)
             double x = EMA(5)[0];
    }
    Code:
    protected override void Initialize()
    {
        ema = EMA(5);
    }
    protected override void OnBarUpdate()
    {
        for (int i=0; i<5;i++)
            double x = ema[0];
    }
    Thank you.
    Using the named instance will always be more efficient.

    Leave a comment:


  • best efficiency when one indicator is called by another indicator

    Inside an indicator, I want to call another indicator.
    My code is below

    Code:
    protected override void OnBarUpdate()
    {
        double x = EMA(5)[0];
    }
    My question is
    Suppose CurrentBar be y, each time OnBarUpdate is triggerred, EMA(5) will be calculated from 1 (y bars before) to y (CurrentBar), won't it?

    I guess it will not be recalculated each time. So is the above code same efficient as
    the following code?
    Code:
    protected override void Initialize()
    {
        ema = EMA(5);
    }
    protected override void OnBarUpdate()
    {
        double x = ema[0];
    }
    My second question is
    are the following two codes same efficiency?
    Code:
    protected override void OnBarUpdate()
    {
        if (CurrentBar  % 1000 == 0)    
             double x = EMA(5)[0];
    }
    Code:
    protected override void Initialize()
    {
        ema = EMA(5);
    }
    protected override void OnBarUpdate()
    {
        if (CurrentBar  % 1000 == 0) 
            double x = ema[0];
    }
    Will one of them get jammed in the 1000th bar because it needs to recalculate 1000 bars' EMA in just a short time (suppose the timeframe is one second)?

    My third question is if one of the following two codes will calculate EMA(5) for five times in one bar.

    Code:
    protected override void OnBarUpdate()
    {
        for (int i=0; i<5;i++)
             double x = EMA(5)[0];
    }
    Code:
    protected override void Initialize()
    {
        ema = EMA(5);
    }
    protected override void OnBarUpdate()
    {
        for (int i=0; i<5;i++)
            double x = ema[0];
    }
    Thank you.
    Last edited by microsat; 11-14-2015, 10:44 AM.

Latest Posts

Collapse

Topics Statistics Last Post
Started by gbourque, Today, 06:39 AM
0 responses
2 views
0 likes
Last Post gbourque  
Started by cmtjoancolmenero, Yesterday, 03:58 PM
1 response
17 views
0 likes
Last Post NinjaTrader_Gaby  
Started by benmarkal, Yesterday, 12:52 PM
3 responses
23 views
0 likes
Last Post NinjaTrader_Gaby  
Started by helpwanted, Today, 03:06 AM
1 response
20 views
0 likes
Last Post sarafuenonly123  
Started by Brevo, Today, 01:45 AM
0 responses
12 views
0 likes
Last Post Brevo
by Brevo
 
Working...
X