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 fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      7 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      159 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X