Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Problem with secondary data series in OnRender

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

    Problem with secondary data series in OnRender


    Hello, how are you, I need to place the Main Dataseries in OnRender, I need to place it in OnEachTick and it enters me only in Range 30. Can you help me.



    Example.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class Range30 : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Disp";
    Name = "testOnrender";
    Calculate = Calculate.OnEachTick;
    IsOverlay = true;
    }
    else if (State == State.Configure)
    {
    setChartProperties = true;
    AddDataSeries(Data.BarsPeriodType.Range, 30);
    }
    }
    protected override void OnBarUpdate()
    {
    }



    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    if (BarsInProgress == 0) // Principal
    {
    Print("Processing BIP 1 for bar "+CurrentBars[0] + " OnRender.");
    }

    if (BarsInProgress == 1) // Just enter here!!!!
    {
    Print("Processing Secondary Range for bar "+CurrentBars[1] + " OnRender.");
    }

    // here Here in OnRender only enter the Secondary Dataseries not the Main,
    //I need to place in OnEachTick


    }
    }


    Thanks.


    Last edited by iradielt; 08-28-2022, 08:08 PM.

    #2
    Hello iradielt,

    Thank you for your post.

    BarsInProgress is an index tied to the Bars object that has called OnBarUpdate(). OnBarUpdate() is a data-driven method and OnRender() is not; rendering is synced to the primary bars on the chart, and therefore BarsInProgress should not be used in OnRender(). Ultimately, using OnRender() to render on a secondary data series is not possible because the BarsInProgress index is not reliable in OnRender().

    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      I need to render the primary data (OnEachTick) in OnRender, but the secondary data is rendered to me. How do I represent the PrimaryData?

      Comment


        #4
        Hello iradielt,

        Thank you for your reply.

        I do not fully understand what you are referring to. Can you send a screenshot of what you are seeing and then explain why this is different from what you are expecting to see?
        • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
        • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.

        I appreciate your patience.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          What I mean is that if I make impressions in OnRender to test, it only shows me is.
          In my OnRender code, I only get data from ; BarsInProgress == 1 (Range, 30) ; Which are the ones from the second Dataseries.


          if (BarsInProgress == 1) // Just enter here!!!! Range, 30
          {
          Print("Processing Secondary Range for bar "+CurrentBars[1] + " OnRender."); // in OnRender it only shows me this data. Range, 30
          }



          If you don't understand me, I'll ask you another way, I have my main data series in OnTick, but I also need to obtain the data in a Range of 30, how can I do this?
          Because if I add a second data series (Range30) it doesn't work well for me and I have problems in OnRender.
          If I delete the second dataseries OnRender works fine for me.




          Here you have a problem similar to mine when trying to add a second Dataseries.

          Hi, I'm working on an indicator that plots a vertical line across all panels given a user input time. I also need a secondary data series (1-Minute) to play a sound once at this time. * Without the secondary data series, the indicator renders correctly, but the sound alert well not play at the correct time. * With the


          Thanks.

          Comment


            #6
            Hello iradielt,

            Thank you for your reply.

            As my colleague Kate stated in the post you linked, "The OnRender() method frequently runs once the State has reached State.Realtime in response to market data updates or a user interacting with the chart (e.g., clicking, resizing, rescaling, etc.). It's not based on whether or not OnBarUpdate is currently processing a specific series. It's entirely possible that when OnRender is running based on a change in the primary series that if you tried to access the CurrentBar from there that it could refer to either data series."

            You should not be using BarsInProgress directly in OnRender(); if you need to refer to a specific bar index then you should store CurrentBar or whichever bar index is needed to a variable and access the variable inside of OnRender(). Additionally, you mentioned that "I need to place it in OnEachTick and it enters me only in Range 30" - to re-iterate, OnRender() is not correlated with the calculation of OnEachTick. OnEachTick means that OnBarUpdate() will be called for each tick, but OnRender() does not get called in the same frequency as OnBarUpdate().

            Are you only adding print statements in OnRender() for this test, or do you also have other conditions and actions set up? OnRender() is typically used to render custom lines, shapes, and text to the chart. As stated in Note #7 on the OnRender() help guide page, "Please limit any calculations or algorithms you may be tempted run in OnRender() simply to rendering. You should always favor precomputed values and store them for rendering later as the preferred approach to working with the OnRender() method (e.g., reusing brushes, passing values from OnBarUpdate(), etc.). See also OnRenderTargetChanged() method for more information on reusing Brushes"

            If you want something calculated from the primary series vs. the secondary series, you may need to calculate those values and save them to variables in OnBarUpdate() then use those variables inside of OnRender() to get the desired results. Based on your description, you are not using OnRender() in an intended manner and this is why you are getting unexpected results.

            Please let me know if I may be of further assistance.
            Emily C.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by llanqui, Today, 10:32 AM
            0 responses
            2 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by StockTrader88, 03-06-2021, 08:58 AM
            45 responses
            3,992 views
            3 likes
            Last Post johntraderuser2  
            Started by TAJTrades, Today, 09:46 AM
            0 responses
            8 views
            0 likes
            Last Post TAJTrades  
            Started by rhyminkevin, Yesterday, 04:58 PM
            5 responses
            62 views
            0 likes
            Last Post dp8282
            by dp8282
             
            Started by realblubb, Today, 09:28 AM
            0 responses
            8 views
            0 likes
            Last Post realblubb  
            Working...
            X