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

    #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 joemiller, Today, 07:33 AM
      0 responses
      6 views
      0 likes
      Last Post joemiller  
      Started by isnercrypto, Today, 06:42 AM
      0 responses
      4 views
      0 likes
      Last Post isnercrypto  
      Started by Coursocied67, Today, 04:02 AM
      0 responses
      5 views
      0 likes
      Last Post Coursocied67  
      Started by TheGameOfProbabilities, 07-18-2019, 06:56 AM
      7 responses
      37 views
      0 likes
      Last Post DaveS
      by DaveS
       
      Started by claxxical, Yesterday, 10:00 PM
      0 responses
      11 views
      0 likes
      Last Post claxxical  
      Working...
      X