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

Draw once a session - OnStartUp()

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

    Draw once a session - OnStartUp()

    I have an indicator that draws the same Fibonacci Retracements at 10 AM each day.

    CalculateOnBarClose = true;

    Still, in real-time it is slow so I have to close it.

    It makes sense why because on each OnBarUpdate() whether its 5 min or 15 min, it is called until the end of the session. Seems inefficient since it never changes.

    I want it to draw once at 10 AM.

    I was reading up OnStartUp() but it is not exactly clear.

    protected override void OnStartUp()
    {
    // Set any variables or logic you wish to do only once at start of your indicator/strategy
    }

    When exactly does it run?
    Would it work at 10 AM if my session starts at 8 or 9 AM?

    #2
    Hello,


    Thank you for your note.


    You would not use OnStartUp() since this is called when you only apply the indicator/strategy to the chart. You cannot access chart objects in OnStartUp() either.

    What you would need to do is only make the modifications or Draw to the chart once a session.

    Best way to do this is with the following check in OnBarUpdate(). This will run at the time that your strategy session template is listed to start.


    if(Bars.FirstBarOfSession)
    {
    //Do Your Drawing
    }

    You can also use this time filter to only draw at a specific time.



    Let me know if I can be of further assistance.

    Comment


      #3
      Originally posted by NinjaTrader_Brett View Post

      You would not use OnStartUp() since this is called when you only apply the indicator/strategy to the chart. You cannot access chart objects in OnStartUp() either.

      What you would need to do is only make the modifications or Draw to the chart once a session.

      Best way to do this is with the following check in OnBarUpdate(). This will run at the time that your strategy session template is listed to start.


      if(Bars.FirstBarOfSession)
      {
      //Do Your Drawing
      }

      I believe I am running into a similar situation. When I hit F5 or when I first bring up a chart, I need to do some actions on existing line objects. I tried putting my logic into OnStartUp(), but, as you mentioned, the objects weren't ready to be accessed.

      I'm needing to do it only one time when the chart is done loading, but I also need this to run if the market is closed. I tried putting the logic into OnBarUpdate() and did an additional test to make sure all bars were loaded (CurrentBar+2 == Bars.Count), but this still requires the market to be open (waits for the next tick).

      Is there a better way?

      Thanks!
      Daniel

      Comment


        #4
        Hello,

        Have you tried doing this on the first bar of the chart? Not sure exactly what you are needing to modify or what data you need to access however therefor that may not work for you.

        As far as telling if a chart is loaded without getting a live tick in there is nothing supported that could be used however what you could do is use a flag to only run the code once. Set the flag to true in OnStartUp(). Then you would need to decide when to run the DrawObjects related code.

        There are many options to do this, you can use your method which you report waits until the first live tick. If (!Historical) would wait for the same.

        What you could try is an unsupported method that may do the trick for you, you could run the code once on the current day loaded.

        Bars.To

        This would output the current end date selected in the data series however it is unsupported as its not documented officially. You could use this to trigger it for example by just checking if you are on the current day may be a solution or something along these lines if you did not want to wait for a live tick for the current day.


        -Brett
        Last edited by NinjaTrader_Brett; 04-03-2012, 08:34 AM.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,602 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        12 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X