• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

best efficiency when one indicator is called by another indicator

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

  • 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.

  • 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:

Latest Posts

Collapse

Topics Statistics Last Post
Started by NinjaCustomer, Today, 12:29 AM
1 response
6 views
0 likes
Last Post NinjaTrader_ChrisSch  
Started by smgrvd, Today, 12:08 AM
0 responses
5 views
0 likes
Last Post smgrvd
by smgrvd
 
Started by ronaldgreene828, Yesterday, 07:50 PM
1 response
12 views
0 likes
Last Post NinjaTrader_EricB  
Started by nailz420, 07-17-2019, 08:38 AM
2 responses
13 views
0 likes
Last Post nailz420  
Started by bouncetherubble, Yesterday, 06:56 PM
0 responses
6 views
0 likes
Last Post bouncetherubble  
Working...
X