• 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

  • 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 Roman_786, 05-16-2019, 05:31 AM
11 responses
206 views
0 likes
Last Post brucerobinson  
Started by Nutricer, Today, 03:24 AM
0 responses
2 views
0 likes
Last Post Nutricer  
Started by DimaFridrich, Today, 01:54 AM
0 responses
8 views
0 likes
Last Post DimaFridrich  
Started by ttodua, Today, 01:12 AM
0 responses
7 views
0 likes
Last Post ttodua
by ttodua
 
Started by NinjaCustomer, Today, 01:01 AM
1 response
12 views
0 likes
Last Post NinjaTrader_ChrisSch  
Working...
X