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

  • koganam
    replied
    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.

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    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.

    Leave a comment:


  • tomaslolo
    started a topic How to store a value until conditions change.

    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?

Latest Posts

Collapse

Topics Statistics Last Post
Started by MacDad, 02-25-2024, 11:48 PM
7 responses
158 views
0 likes
Last Post loganjarosz123  
Started by Belfortbucks, Today, 09:29 PM
0 responses
6 views
0 likes
Last Post Belfortbucks  
Started by zstheorist, Today, 07:52 PM
0 responses
7 views
0 likes
Last Post zstheorist  
Started by pmachiraju, 11-01-2023, 04:46 AM
8 responses
151 views
0 likes
Last Post rehmans
by rehmans
 
Started by mattbsea, Today, 05:44 PM
0 responses
6 views
0 likes
Last Post mattbsea  
Working...
X