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 FrancisMorro, Today, 03:24 AM
      0 responses
      1 view
      0 likes
      Last Post FrancisMorro  
      Started by Segwin, 05-07-2018, 02:15 PM
      10 responses
      1,770 views
      0 likes
      Last Post Leafcutter  
      Started by Rapine Heihei, 04-23-2024, 07:51 PM
      2 responses
      31 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by Shansen, 08-30-2019, 10:18 PM
      24 responses
      944 views
      0 likes
      Last Post spwizard  
      Started by Max238, Today, 01:28 AM
      0 responses
      11 views
      0 likes
      Last Post Max238
      by Max238
       
      Working...
      X