Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to store a value to recall later?

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

    How to store a value to recall later?

    Hi,
    I just want to store a value when a particular condition is met, and be able to recall that specific value later in the script (to exit a position)...i tried myDataSeries.Set, but was not able to store the value. please help


    example:
    double value1 = ATR(100)[0]*500;
    If a condition is met
    {
    store the value1
    EnterLong("");
    }
    if (Close[0] >= value1 + 100)
    {
    ExitLong("");
    }

    #2
    Your variable declaration should be in the Variables region of the code as private double. If you did it in OnBarUpdate() you would be overwriting it on every single bar update event.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      u r right, i am declaring them on OnBarUpdate()...but i am not sure how i can define variables in region variables, when i am using barsarrays & indicators

      would i just simply add this in the region variables section??
      private double value1 = ATR(100)[0]*500;

      Comment


        #4
        Just declare it in the Variables region with a 0 as the initial value. Then you can overwrite it when necessary in OnBarUpdate().
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Declaring the variable in region variables with 0 as the initial value solved it.

          Thanks a lot for your help Josh!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          648 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          574 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X