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

Summation of previous bars

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

    Summation of previous bars

    Can someone point me in the right direction to learn how to create a loop (or whatever is necessary) to do the following:

    While a certain condition is met, add the result of an indicator (such as volume) on each successive bar and store it as a double or int that can be plotted.

    Thank you for any tips.

    #2
    Originally posted by jmflukeiii View Post
    Can someone point me in the right direction to learn how to create a loop (or whatever is necessary) to do the following:

    While a certain condition is met, add the result of an indicator (such as volume) on each successive bar and store it as a double or int that can be plotted.

    Thank you for any tips.
    Though you could use a loop, that looks like a straight accumulation scheme is what you need: loops are generally inefficient, and I avoid them if I can find another method.

    Code:
     
    private double TotalSum = 0;
    Code:
     
    bool ConditionMet = false;
     
    // code to evaluate and set ConditionMet goes here
     
    if (ConditionMet)  TotalSum += Volume[0];
    else TotalSum = 0;
    For Volume, you probably do want to use int: double is just a more general illustration of the principle.

    Comment


      #3
      koganam, as always, thank you for your help

      Comment


        #4
        If I have an indicator that plots both in a separate indicator panel (using plots) and then places lines on the chart, how do I set this up in the script?

        Thank you

        EDIT: With a quick search, it looks like that is not possible. I'll create two indicators
        Last edited by jmflukeiii; 07-07-2012, 01:16 PM.

        Comment


          #5
          Originally posted by jmflukeiii View Post
          If I have an indicator that plots both in a separate indicator panel (using plots) and then places lines on the chart, how do I set this up in the script?

          Thank you

          EDIT: With a quick search, it looks like that is not possible. I'll create two indicators
          Look up DrawOnPricePanel.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by maybeimnotrader, Yesterday, 05:46 PM
          1 response
          18 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Perr0Grande, Yesterday, 08:16 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by f.saeidi, Yesterday, 08:12 AM
          3 responses
          24 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by algospoke, Yesterday, 06:40 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by quantismo, Yesterday, 05:13 PM
          1 response
          14 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X