Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to store a value until conditions change.

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

    How to store a value until conditions change.

    Hi all, I want to store the cumulative value between different Close prices, so, e.g. if Close is different in five consecutive ticks, the price difference of each five ticks will be summed until you have two equal Close prices, in that case you´ll plot that last close price (Close[0]).

    e.g. if Close is:
    1.1103 / 1.1104 / 1.1105/ 1.1108 / 1.1109 / 1.1109 / 1.1111 / 1.1115

    The indicator would show:

    none/ 0.0001 / 0.0002 / 0.0005 / 0.0006/ 1.1109 / 0.0002 / 0.0006

    I´m coding this:

    Code:
    If Close[0] != Close[1]
    myDataSeries.Set(Close[0] - Close[1]);
    
    else
    myDataSeries.Set(Close[0]);
    but obviously is wrong and after reading DataSeries class info I keep stuck on this. Any help?
    How can you store a value and update it on each bar until condition set changes?

    #2
    Hello,

    Thank you for the question.

    A dataseries can be set using the syntax you have used or myDataSeries.Set(Close[0]);

    Depending on the CalculateOnBarClose settings, this would be set once per close or once per tick. once per tick would Update the current value of the series on each tick.

    What is currently happening when you execute the code that is not happening as it should? Is it that the plot is only being updated once per bar?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by tomaslolo View Post
      Hi all, I want to store the cumulative value between different Close prices, so, e.g. if Close is different in five consecutive ticks, the price difference of each five ticks will be summed until you have two equal Close prices, in that case you´ll plot that last close price (Close[0]).

      e.g. if Close is:
      1.1103 / 1.1104 / 1.1105/ 1.1108 / 1.1109 / 1.1109 / 1.1111 / 1.1115

      The indicator would show:

      none/ 0.0001 / 0.0002 / 0.0005 / 0.0006/ 1.1109 / 0.0002 / 0.0006

      I´m coding this:

      Code:
      If Close[0] != Close[1]
      myDataSeries.Set(Close[0] - Close[1]);
      
      else
      myDataSeries.Set(Close[0]);
      but obviously is wrong and after reading DataSeries class info I keep stuck on this. Any help?
      How can you store a value and update it on each bar until condition set changes?
      Code:
      private EqualCloses = false; //must be a class variable, placed outside any method or event handler code block
      Code:
      if (Close[0] != Close[1])
      {
      if (EqualCloses) 
      {
      myDataSeries.Set(Close[0] - Close[1]);
      EqualCloses = false;
      }
      else myDataSeries.Set(myDataSeries[1] + Close[0] - Close[1]);
      }
      else
      {
      myDataSeries.Set(Close[0]);
      EqualCloses = true;
      }
      Untested code, but it covers what you described. You described it well enough, but then you did not write your psuedcode to match your description.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by aligator, Today, 02:38 PM
      0 responses
      5 views
      0 likes
      Last Post aligator  
      Started by Stett0002, Yesterday, 11:55 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_ShawnB  
      Started by KasLB, Today, 05:12 AM
      2 responses
      17 views
      1 like
      Last Post KasLB
      by KasLB
       
      Started by LeitoGTR, Yesterday, 06:41 PM
      2 responses
      19 views
      0 likes
      Last Post LeitoGTR  
      Started by Prisalice, Today, 07:07 AM
      1 response
      10 views
      0 likes
      Last Post NT-Roland  
      Working...
      X