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

How to Plot indicator Only on the last day displayed on the chart?

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

    How to Plot indicator Only on the last day displayed on the chart?

    I just want to Plot the results of an indicator on the last day of data on a chart.

    For Example: I have 30 days of the TF 3-15 on a chart and only want to display a SMA13 on the 30th day and not on the previous 29 days.

    What Day or Time logic would I use to Set the plot Only on the 30th day?

    Thank You Very Much in Advance.
    Joe

    #2
    Hello jmca2000,

    If you are first enabling the script and you want the plot on the last bar of historical data, you are able to find a bar count of the historical data and use this to trigger on the last historical bar.

    For example in #region Variables:
    private int historicalBarCount = 0;

    In OnStartUp():
    historicalBarCount = BarsArray[0].Count;

    In OnBarUpdate():
    if (CurrentBar == historicalBarCount-1 && FirstTickOfBar)
    {
    // execute code
    }

    (You will want to do with this calculate on bar close as false as the last bar on a day chart won't close until the new session opens)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for your support.

      I want to plot the indicator on all the bars for the Last day (30th day in the example) on a chart not just the last bar.

      What I want to be able to do is check what the last day displayed is on a intraday chart (30 days of data, 30th day), using some Date logic that tells me what the last day on the chart is so that I can set the SMA.set to plot Only on this day.

      if(CurrentDateonChart == LastDateonChart)

      SMA.set()

      Thanks Again in Advance...
      Joe

      Comment


        #4
        Hi jmca2000,

        When you mention the last day on a chart, do you not mean last day on a chart but instead mean last day of the month?

        If that is the case, try:

        if (Time[0].AddDays(1).Day == 1)
        {
        // execute code
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Again Chelsea,

          What I mean is, if I have 8 days on a chart I only want to plot on the 8th day of intraday data not on the previous seven days of data.

          Will this code accomplish this:

          if (Time[0].AddDays(1).Day == 1)
          {
          // execute code
          }

          Is there a way to return what the Last Day being plotted is on the "Chart" not using Time[0] in case the last day on the chart is not what the current date and time is (not a live chart)?

          Just want to check before you start your weekend...

          Joe
          Last edited by jmca2000; 01-16-2015, 04:36 PM.

          Comment


            #6
            Hello jmca2000,

            I am not sure I understand what you are looking for.

            You mention if you have 8 days you want the 8th day and not the previous 7th. To me this sounds like the last daily bar on a chart.

            Can you explain how this is not the last daily bar on a chart?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Chelsea,

              What I'm trying to say is no matter how many Intraday Days of Data are plotted on a chart, I just want the Indicator plotted on the last day of the Intraday data. Example when plotting the PriorDayOHLC() Indicator....I just what the lines on the last day and do not want them plotted on the previous days.

              Thanks Again...
              Joe

              Comment


                #8
                This can best be achieved via a custom plot. One example is the daily pivots indicator from the SessionPivots (see download section), which has an option to plot for all days or just for the last day.
                Attached Files

                Comment


                  #9
                  Hello Joe,

                  Thank you for your response.

                  Here is a basic example using the PC date and time, keep in mind if the last Day on the chart is not the current PC date this would not work.
                  Code:
                          protected override void Initialize()
                          {
                  			Add(new Plot(Color.Blue, "plot"));
                          }
                  
                          /// <summary>
                          /// Called on each bar update event (incoming tick)
                          /// </summary>
                          protected override void OnBarUpdate()
                          {
                  			if(Time[0].Day != DateTime.Now.Day)
                  				return;
                  			
                  			Value.Set(SMA(20)[0]);
                  		}

                  Comment


                    #10
                    Thank You Very Much Harry (FT's),

                    Really appreciate your multi forum's support and assistance not to mention your indicator's ...

                    Joe

                    Comment


                      #11
                      Hi Patrick,

                      Thank You for your Support...

                      I know that method.

                      But is there a way to check the date and time of the last day on a chart, when the last day on the chart is not the same as the PC Date and Time (such as older Market Replay Charts)?

                      Thanks In Advance....
                      Joe

                      Comment


                        #12
                        Hi Joe, you could also check into the BarTimer indicator, it uses a custom method to adjust the date reference based on either realtime data is used or if the user would be on the replay connection and thus having to work with the 'replay' clock here - thus with Patrick's idea you could find the current replay day you're on and only assign plots if this condition is for example true.

                        Code:
                        DateTime now = (Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay ? Bars.MarketData.Connection.Now : DateTime.Now);
                        BertrandNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by ScottWalsh, Today, 04:52 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post ScottWalsh  
                        Started by ScottWalsh, Today, 04:29 PM
                        0 responses
                        5 views
                        0 likes
                        Last Post ScottWalsh  
                        Started by rtwave, 04-12-2024, 09:30 AM
                        2 responses
                        22 views
                        0 likes
                        Last Post rtwave
                        by rtwave
                         
                        Started by tsantospinto, 04-12-2024, 07:04 PM
                        5 responses
                        70 views
                        0 likes
                        Last Post tsantospinto  
                        Started by cre8able, Today, 03:20 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post cre8able  
                        Working...
                        X