Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Storing Current Values to use as previous values

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

    Storing Current Values to use as previous values

    Hello, I was finally able to create RTHOHL values that plot until the next RTH trading session. My question is how do I now store those the current values into previous values using the current script?

    Thanks,


    protected override void OnBarUpdate()
    {

    if (!Bars.BarsType.IsIntraday) return;

    lastDate = currentDate;
    currentDate = sessionIterator.GetTradingDay(Time[0]);


    if (Time[0] >= sessionIterator.ActualSessionBegin && Time[0] <= sessionIterator.ActualSessionEnd || Bars.IsFirstBarOfSession)
    //if (Bars.IsFirstBarOfSession)
    //if (lastDate != currentDate || currentOpen == double.MinValue)
    {
    currentOpen = Open[0];
    currentHigh = High[0];
    currentLow = Low[0];

    //Print(Time[0] + "|" + "lastDate" + lastDate + "|" + "currentDate" + currentDate);
    }

    currentHigh = Math.Max(currentHigh, High[0]);
    currentLow = Math.Min(currentLow, Low[0]);

    //Print(String.Format("Time[0]: {0} lastDate: {1} currentDate: {2}",
    //Time[0], lastDate, currentDate));

    if (ShowOpen)
    CurrentOpen[0] = currentOpen;

    if (ShowHigh)
    CurrentHigh[0] = currentHigh;

    if (ShowLow)
    CurrentLow[0] = currentLow;

    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    if (Times[0][0].TimeOfDay >= new TimeSpan(17, 00, 00) || Times[0][0].TimeOfDay <= new TimeSpan(08,30, 00))
    {
    CurrentOpen[0] = CurrentOpen[1];
    CurrentHigh[0] = CurrentHigh[1];
    CurrentLow[0] = CurrentLow[1];
    }
    Print(String.Format("Time[0]: {0} | CurrentOpen[0]: {1} | CurrentHigh[0]: {2} | CurrentLow[0]: {3}",
    Time[0], CurrentOpen[0], CurrentHigh[0], CurrentLow[0] ));
    }
    Attached Files
    Last edited by AdeptistJune; 01-06-2022, 07:15 AM.

    #2
    Hi AdeptistJune, thanks for posting.

    We will not be able to create new code for you. Could you be more specific with your question?

    Comment


      #3
      Good morning Chris,

      No, I don't want you to generate new code for me. I just need information on how to properly store my current days plot value and reference those values going forward.

      Comment


        #4
        Hi, thanks for your reply.

        There are several ways to store information. In NinjaTrader we can set up Series<T> objects that can hold a data point of any type for each bar on the chart:


        Other in-memory storage options:
        Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.



        If you need to store something between sessions when the computer is turned off, you can store values to a .txt file. We have an example here:


        Kind regards,
        -ChrisL

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        576 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X