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

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 jaybedreamin, Today, 05:56 PM
      0 responses
      7 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      4 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      12 views
      0 likes
      Last Post Javierw.ok  
      Started by timmbbo, Today, 08:59 AM
      2 responses
      13 views
      0 likes
      Last Post bltdavid  
      Working...
      X