Announcement

Collapse
No announcement yet.

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 CaptainJack, 05-29-2026, 05:09 AM
          0 responses
          176 views
          0 likes
          Last Post CaptainJack  
          Started by CaptainJack, 05-29-2026, 12:02 AM
          0 responses
          93 views
          0 likes
          Last Post CaptainJack  
          Started by charlesugo_1, 05-26-2026, 05:03 PM
          0 responses
          130 views
          0 likes
          Last Post charlesugo_1  
          Started by DannyP96, 05-18-2026, 02:38 PM
          1 response
          210 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          186 views
          0 likes
          Last Post CarlTrading  
          Working...
          X