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 HOLD a value in "OnBarUpdate"..

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

    How to HOLD a value in "OnBarUpdate"..

    I have a dot plot on the upper line of a Donchian Channel when it slopes down.
    I need it to maintain the plot level until it slopes down again.

    protected override void OnBarUpdate()
    {
    Value.Set((MAX(High, Period)[0] + MIN(Low, Period)[0]) / 2);
    Upper.Set(MAX(High, Period)[0]);
    Lower.Set(MIN(Low, Period)[0]);

    if((MAX(High, Period)[0]) > (MAX(High, Period)[-1]))
    {
    Dip.Set(MAX(High, Period)[-1]);
    }
    else
    {
    ** Not sure what needs to go here to maintain last value ???
    It simply doesn't plot anything if the above "IF" statement is not utilized.
    {
    }

    Thx in advance for any guidance...

    #2
    Hello Randwulf,

    Thank you for the post.

    One problem I can see is that you are using Negative BarsAgo, the BarsAgo system works with Positive numbers. You should change the [-1] to [1] if you meant 1 BarsAgo or the previous bar.

    To retain the value you could likely use the prior plot value for this purpose:

    Code:
    Dip[0] = Dip[1];
    You would also need to check that you have at least 1 bar before doing a BarsAgo check of 1 bar:

    Code:
    if(CurrentBar < 1) 
    {
    Dip[0] = some value for the first bar;
    } else {
     // logic you have shown in the sample 
    }

    I look forward to being of further assistance.


    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you for the timely reply Jesse.
      I knew it should be positive numbers for "bars back" but couldn't seem to get it to work.
      I will continue to correct this.
      In the meantime, I simply created a "double" variable and assign the change to it and on each bar update it assigns the plot value to it.
      Great idea about insuring I have at least 1+ bars first... It's been a long time since I've dabbled in NinjaScript and had forgotten that.
      Thanks again for your ever appreciated support...

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Haiasi, 04-25-2024, 06:53 PM
      2 responses
      16 views
      0 likes
      Last Post Massinisa  
      Started by Creamers, Today, 05:32 AM
      0 responses
      4 views
      0 likes
      Last Post Creamers  
      Started by Segwin, 05-07-2018, 02:15 PM
      12 responses
      1,785 views
      0 likes
      Last Post Leafcutter  
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,407 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Working...
      X