Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I have a problem with fetching the current day ohl

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

    I have a problem with fetching the current day ohl

    I want to send the current day OHL and prior day OHL to an api on my server but the problem that i get is that i don't get the correct values of the current day.

    I started by duplicating the CurrentDayOHL prebuilt and i added a custom function to send the data it works perfectly it sends the data with no problem, but the values it send are not the current values that are ploted on the screen.

    I also noticed that it sends a lot of request to the api when i reload ninjaScript is it normal? doesn't need to only send the latest value?

    And for the values i take them from the Values variable in the OnBarUpdate() function

    I'm still new to coding indicators so it might be not the most efficient or the best way of doing this if you know another way i would be happy to hear the solution.

    here is the function i use to send data:

    Code:
    static async Task sendDataAsync(Series<double> openV, Series<double> highV, Series<double> lowV)
            {
                var url = "https://link/to/my/server/api?";
    
                if (openV[0] != 0 && highV[0] != 0 && lowV[0] != 0)
                {
                    try
                    {
                        string postData = "open=" + Uri.EscapeDataString(openV[0].ToString().Replace(",", "."));
                        postData += "&high=" + Uri.EscapeDataString(highV[1].ToString().Replace(",", "."));
                        postData += "&low=" + Uri.EscapeDataString(lowV[2].ToString().Replace(",", "."));
    
                        var client = new HttpClient();
                        var content = await client.GetStringAsync(url + postData);
    
                        Console.WriteLine(content);
    
                    } catch (Exception ee) {
                        Console.WriteLine("Error: "+ee.ToString());
                    }
                }
    
            }​
    I know i should use a POST request but i couldn't manage to make it work to i stuck with using GET to send data.

    and here the OnBarUpdate where i use the function:
    Code:
    protected override void OnBarUpdate()
            {
                if (!Bars.BarsType.IsIntraday) return;
    
                lastDate         = currentDate;
                currentDate     = sessionIterator.GetTradingDay(Time[0]);
    
                if (lastDate != currentDate || currentOpen == double.MinValue)
                {
                    currentOpen        = Open[0];
                    currentHigh        = High[0];
                    currentLow        = Low[0];
                }
    
                currentHigh            = Math.Max(currentHigh, High[0]);
                currentLow            = Math.Min(currentLow, Low[0]);
    
                if (ShowOpen)
                    CurrentOpen[0] = currentOpen;
    
                if (ShowHigh)
                    CurrentHigh[0] = currentHigh;
    
                if (ShowLow)
                    CurrentLow[0] = currentLow;
    
                sendDataAsync(Values[0], Values[1], Values[2]);  // here is where i call that function
            }​
    and just so you know IM NOT INTO TRADING i'm just a normal dev and an acquaintance of mine wanted some help that's why i'm here, so if possible if you use some trading term or some sort please explain it thanks in advance!

    #2
    Hello SwirX,

    Thanks for your post.

    The CurrentDayOHL() system indicator method could be used to get the current day (session) Open, High, or Low value.

    The PriorDayOHLC system indicator method could be used to get the previous day (session) Open, High, Low, or Close value.

    You could consider sending that information to a text file by using a StreamWriter. A StreamReader could be used to read information from a text file

    When you reload a NinjaScript, it will reprocess all historical data that is on the chart window. If you want the script to skip historical processing, you could add if (State == State.Historical) return; to the top of your OnBarUpdate() logic.

    See the help guide documentation and reference sample linked below for more information and sample code.

    CurrentDayOHL(): https://ninjatrader.com/support/help...nt_day_ohl.htm
    PriorDayOHLC(): https://ninjatrader.com/support/help...r_day_ohlc.htm
    StreamWriter: https://ninjatrader.com/support/help...o_write_to.htm
    StreamReader: https://ninjatrader.com/support/help...o_read_fro.htm

    Note that sending that data to an external application or program goes beyond the support we would be able to provide you with in the Support department. We also do not provide C# education services in our support.

    This forum thread will be open for other community members to share their insights on the topic.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      I'd like to ask a small adjustment to thoses OHCL indicators, if I may, please.

      Would it be possible to add a check box in the properties panel that could allow us to select the day session only (9h30 to 16h00) OHLC please? Those levels are more relevant than the levels of the OHLC of the entire session (From 18h00 to 17h00 the next day). I think these indicators would be a little bit more complete with this choice.

      Just a suggestion for the development team with a few lines of code to add to reflect this upgrade.

      Thank you.

      Comment


        #4
        Hello Bricolico,

        Thanks for your notes.

        The Current Day OHL indicator will calculate the OHL of the current day based on the Trading Hours template the chart is using.

        For example, if we open a chart for the ES 12-23 instrument with its default Trading Hours template and add the Current Day OHL indicator to the chart, we can see the OHL values are calculated from 5:00PM to 4:00PM (Central Time) the next day since these are the start and end times of that Trading Hours Template (CME US Index Futures ETH).

        If we change the chart's Data Series Trading Hours template to CME US Index Futures RTH, we can see the Current Day OHL indicator will calculate values from 8:30AM to 4:00PM (Central Time).

        You could view what default Trading Hours an instrument uses by going to Control Center > Tools > Instruments, searching and selecting the instrument, and noting the Trading Hours field.

        To view the start time and end time of Trading Hours templates, go to Control Center > Tools > Trading Hours, select the Trading Hours template, and note the start time and end time.

        See the help guide documentation below for more information.

        Instruments: https://ninjatrader.com/support/help...nstruments.htm

        Trading Hours: https://ninjatrader.com/support/help...ding_hours.htm
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        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