Announcement

Collapse
No announcement yet.

accumulate my indicator?

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

  • accumulate my indicator?

    how can I accumulate an indicator that I wrote my self?
    I wrote 2 indicatores(a,b),
    1- returns a number & its working fine (indicator a).
    in the second indicator(b) i'm writing now I need tow things:
    1- is to add this bar indicator(a) number to the previous bar.
    2 - is to accumulate all of the indicators(a) numbers until this bar.
    pleas advise

  • #2
    accumulation...

    well, you could simply create a variable and add the current indicator A to it...

    for example.....

    var myaccumulationvariable = 0;


    function main() {

    .. do my custom indicator here...

    myaccumulationvariable += mycustomindicatorA;

    }

    now, this is a simple example of accumulation. Your code might be much more complex. If you need specific help on this, post something we can mess with (code). it does not have to be exactly your code (as it is now), but something we can modify as an example for you is the best solution..

    B
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Hello gfuks1,

      I'm not certain this is exactly what you want, but it will show you how to do a cumulative return of an indicator. In this case a EMA value. The key is to use two global variables. One to store the indicator value and the other to store the cumulative sum. Use the bar state, BARSTATE_NEWBAR, to only allow the last value of the indicator to be added to the total once for each bar.

      PHP Code:

      function preMain() {
          
      setStudyTitle("test");
      }

      var 
      0;
      var 
      suma 0;
      var 
      study = new MAStudy(100"Close"MAStudy.EXPONENTIAL);


      function 
      main() {
          var 
      nState getBarState();
          
          
          if (
      nState == BARSTATE_NEWBAR) {
              
      suma += a;
          }

          
      study.getValue(MAStudy.MA);
          if(
      == null) return;


          return (
      suma a);

      Jason K.
      Project Manager
      eSignal - an Interactive Data company

      EFS KnowledgeBase
      JavaScript for EFS Video Series
      EFS Beginner Tutorial Series
      EFS Glossary
      Custom EFS Development Policy

      New User Orientation

      Comment

      Working...
      X