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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        77 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        109 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        57 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        108 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        65 views
        0 likes
        Last Post PaulMohn  
        Working...
        X