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.

    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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      154 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      307 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      244 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      345 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      176 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X