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

Last Plot of Day

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

    Last Plot of Day

    Hello NT-Team,

    I have programmed an Indicator which delivers a plot value for every bar on the chart. The problem ist that the last bar of the day is not calculated in the indicator. Though it is the same problem with intradaybars, I also want to use the indicator on daily bars. At the end of the day I need a calculation of the current daily bar for sending me an email with the report.

    I have attached a picture to show the problem with the last intradaybar. For solving the problem I need the calculation of the last bar of the day in the indicator.

    How can I solve this problem?
    Attached Files

    #2
    Hello Redmoon22,

    Thanks for opening the thread.

    As it sounds, you are calculating the indicator on bar close and would like to get the value of the indicator's close at the end of a session.

    One solution would be to create your own Series<double> to keep track of the daily OHLC values you wish to use for your indicator. You could update this Series<double> with each OnBarUpdate() of your primary series and have it use that Series to calculate that indicator. You could then check during the interval for the last bar to send the email notification.

    Another approach would be to update the plot for the indicator on each tick, and then to send the email when the primary data series approaches the last bar update before it passes the session end.

    Components that can be used to accomplish this are documented below:

    Series<T> - https://ninjatrader.com/support/help...us/seriest.htm
    IsFirstBarOfSession - https://ninjatrader.com/support/help...rofsession.htm
    IsLastBarOfSession - https://ninjatrader.com/support/help...rofsession.htm
    AddPlot() - https://ninjatrader.com/support/help...us/addplot.htm
    SendMail() - http://ninjatrader.com/support/helpG...s/sendmail.htm

    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks for your fast help, but is there really no other easier way to send an email after the finishing of a daily bar?

      It is such an easy task, there should be another solution for that. I just want a calculation after end of day.

      I am planning to find a walk around with changing from "Calculate.OnBarClose" to "Calculate.OnEachTick" in the last minute to session end. In combinaton with if-conditions which only calculate one time in this special case.

      Is there a method which can access at a certain timestamp or do I have to use 1 minute timeframe (with an added daily timefrime) to be able to react a minute before session close.

      "sessionIterator.ActualSessionEnd" give me the session end, is it possible to calculate minus 1 minute on the given end time?
      Last edited by Redmoon22; 05-23-2017, 03:41 AM.

      Comment


        #4
        Hello Redmoon22,

        Thanks for making that clearer.

        What you would like to do would be a lot easier by adding an additional data series for daily bars with a trading hour template of your choosing. You could then get the send the email from OnBarUpdate() for the BarsInProgress of that data series.

        For example, you could use the following syntax for adding the data series with a trading hour template:
        Code:
        AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName)
        Please see AddDataSeries() and documentation on using additional data series for more details. We also have a sample strategy that uses an additional data series for intra bar granularity that can be used as a good example of a multi-series strategy.

        AddDataSeries() - https://ninjatrader.com/support/help...dataseries.htm

        Multi-Series NinjaScripts - https://ninjatrader.com/support/help...nstruments.htm

        Intrabar granularity sample - http://ninjatrader.com/support/forum...ead.php?t=6652

        If you have any additional questions, please don't hesitate to ask.
        JimNinjaTrader Customer Service

        Comment


          #5
          Thanks, but this is still not satisfying..

          The real problem is this:

          " True Event Driven OnBarUpdate() Method
          Since a NinjaScript script is truly event driven, the OnBarUpdate() method is called for every bar update event for each Bars object added to the script. "

          Calculations on the bar close of the last bar, will be done if a new bar is updated in the chart.

          Is there any way to trigger calculations outside the OnBarUpdate() method? I am searching for a way to do calculations after 1 minute of the session end, also with using the last bar of the day. This is not such a difficult task and should be able in NinjaTrader.

          Comment


            #6
            I need a way to trigger a sendmail() action outside the OnBarUpdate() medthod to be able to make calculation of the daily bar. Or to send me calculation depending on the last 60-minute bar.


            Maybe this threat could be a way, but I'm not sure how to set it up..

            below is the code from the thread:

            protected override void OnMarketData(MarketDataEventArgs event)
            {
            if (event.MarketDataType == MarketDataType.Last)
            {
            // do stuff
            }
            }


            Does this if-condition "if (event.MarketDataType == MarketDataType.Last" trigger, at the session end ?
            Last edited by Redmoon22; 05-23-2017, 10:37 AM.

            Comment


              #7
              Hello Redmoon22,

              Thanks for the notes.

              Getting the daily OHLC values would be easiest to get inside OnBarUpdate() after the close of the daily series. Could you provide a little bit more detail on what you would like to accomplish exactly, or why using the close of the daily bar is not an adequate solution to getting the daily OHLC values?

              It is possible to create a custom timer event to perform some logic outside of OnBarUpdate(). We have a sample that describes this here: http://ninjatrader.com/support/forum...ead.php?t=5965

              TriggerCustomEvent() - https://ninjatrader.com/support/help...ustomevent.htm

              Code:
              protected override void OnMarketData(MarketDataEventArgs event)
              {
                if (event.MarketDataType == MarketDataType.Last)
                {
                  // do stuff
                }
              }
              As per the help guide, OnMarketData() will be called for each Bars object added to the strategy. This would mean that you will see the last price for each bars series added to the strategy.

              With multi-time frame and instrument strategies, a subscription will be created all bars series added in your indicator or strategy strategy (even if the instrument is the same). The market data subscription behavior occurs both in real-time and during TickReplay historical


              I look forward to being of further help.
              JimNinjaTrader Customer Service

              Comment


                #8
                This was useful. I just want to be able to trigger an event after session end (without changing the trading hours of the instruments).

                I have an acceptable solution way.. I am using the simple timer event. Doing the custom event with an in interval of 60 seconds.. the custom event has an if-condition which checks for a certain time "if ( ToTime(DateTime.Now) >= ToTime(22 , 0 , 0 ) ) ... I will try to combine this if-condition with the sessionIterator.ActualSessionEnd.. the triggered if-condition contains "Calculate = Calculate.OnEachTick;" which helps to get the Daily Close.. And also in the if conditions are the needed indicator calculations and the sendmail() method. After things are done the Calculation method is set back to "Calculate.OnBarClose"..

                This is a "long" walk around, but it should work
                A more elegant way would be to have a daily time schedule after the daily session end.
                Is it possible to make a custom event trigger which triggers at a daily time schedule?

                A custom triggered event depending on this if condition would be the best solution
                ""if ( ToTime(DateTime.Now) >= ToTime(22 , 0 , 0 ) )"

                Comment


                  #9
                  Hello Redmoon22,

                  I'm glad the custom timer event was an adequate solution for your needs.

                  Code:
                  if ( ToTime(DateTime.Now) >= ToTime(22 , 0 , 0 ) )
                  I agree that this would be the simplest/best solution. As you are using DateTime.Now instead of the Times object, you would not have to worry about any issues with indexing the correct bars ago from the event handler. For example, you should not have any issue doing this in MyCustomHandler() in the provide sample.

                  You may wish to use bools to add additional control to the logic depending on your implementation.

                  Please let me know if I may assist you further.
                  JimNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by AttiM, 02-14-2024, 05:20 PM
                  11 responses
                  184 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by fernandobr, Today, 09:11 AM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by timmbbo, Today, 08:59 AM
                  1 response
                  3 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by KennyK, 05-29-2017, 02:02 AM
                  2 responses
                  1,281 views
                  0 likes
                  Last Post marcus2300  
                  Started by itrader46, Today, 09:04 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Working...
                  X