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

    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.

    #2
    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.

    Comment


      #3
      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.
      Michael M.NinjaTrader Quality Assurance

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by chbruno, Today, 04:10 PM
      0 responses
      3 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      6 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by frslvr, 04-11-2024, 07:26 AM
      9 responses
      127 views
      1 like
      Last Post caryc123  
      Working...
      X