Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Hold Closing Price to a Constant Value

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

    Hold Closing Price to a Constant Value

    I am wanting to assign the closing price of a bar to a double variable when certain conditions exist, but I do not want the value to be updated each time the closing price is updated. I want the value to be held constant and used for other calculations in the code. How is the best way to accomplish this?

    #2
    Hello Trader_781,

    Welcome to the NinjaTrader forums!

    You could use a bool to only set the value once.

    private double myDoubleValue;
    private bool doubleSet;

    In OnBarUpdate:

    Code:
    if (doubleSet == false /* && other conditions to set value */)
    {
    myDoubleValue = Close[0];
    doubleSet = true;
    }
    Also, below is a link to a forum post with helpful resources on getting started with C# and NinjaScript.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea B. This information is helpful.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      58 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      34 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      195 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      359 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      281 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X