Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator that uses Daily Bar in Intraday chats

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

    Indicator that uses Daily Bar in Intraday chats

    I am trying to create an indicator that will show the Daily moving average on an intraday chart. I feel like this should work, but the output seems to be a single value that doesn't change over time.

    protected override void OnStateChange()
    {

    if (State == State.SetDefaults)
    {
    Name = "DailySMA";
    Description = @"Enter the description for your new custom Indicator here.";
    IsOverlay = true;
    IsSuspendedWhileInactive = true;
    Period = 14;
    AddPlot(Brushes.Orange, Name);
    }
    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Day, 1);
    }
    }
    protected override void OnBarUpdate()
    {

    if (BarsInProgress != 0)
    return;

    if (BarsArray[1].DayCount <= 0)
    return;

    Print(Time[0] + " " + BarsArray[1].DayCount);

    Value[0] = SMA(BarsArray[1], Period)[0];
    }


    #2
    Hello BrianARice,

    Thank you for writing in and welcome to the NinjaTrader Support Forum!

    DayCount is an undocumented property. Can you please specify what value you are attempting to obtain with BarsArray[1].DayCount?

    If you are attempting to access the amount of day bars that have elapsed, you'll want to use BarsArray[1].CurrentBar. The count will start at 0 for the first daily bar and increment on each day bar after.

    Additionally, the indicator's value is not going to change intraday because its input series is the daily series you have added. It will change value on a new day. Are you unable to see the indicator value change on your intraday chart after each session close?
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      That is essentially true that it won't change over time. If you set your period to something like "2" then it would always split the difference between yesterday's close and today's close, but if you take any higher number you're not going to see much change.

      You could simply subscribe another data series and refer to that in your indicator as well.

      Comment


        #4
        DayCount > 0 ... I was just trying to make sure there was enough data for the SMA.

        But, yes, that's the point I want the value to remain the same for the entire day... but then change on the next day... but this value is staying the same for all the days.

        Is it possible that my chart is not getting enough data? When I create a new chart I set "Days to Load" to 200... but I still only see 5 days worth of data on the screen... how can I change this?

        Comment


          #5
          @armybender... how would I "simply subscribe to another data series and refer to that in that indicator as well"

          Comment


            #6
            Hello BrianARice,

            If you wish to check if there is at least one daily bar available for the SMA, you'd want to do:

            Code:
            if (CurrentBars[1] < 0)
                 return;
            CurrentBars[0] will equal 0 if there is at least one bar as CurrentBar starts at 0 and increments by one on each bar after.

            Are you connected to a data provider when increasing your days to load setting? What happens when you right-click on the chart and select Reload All Historical Data?

            With this code:

            Code:
            protected override void OnBarUpdate()
            {
            	//Add your custom indicator logic here.
            	if (CurrentBars[1] < 0)
            		return;
            	
            	if (BarsInProgress != 0)
            		return;
            	
            	Value[0] = SMA(BarsArray[1], 14)[0];
            }
            I am able to see the indicator change on every new session. Are you not seeing the values change?
            Attached Files
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              It looks like replacing the DayCount with
              if (CurrentBars[1] < 0) return;

              But unbelievably the likely bigger problem was as you suggested... I wasn't connected to my data provider!

              Comment


                #8
                Hello BrianARice,

                May I confirm that after you connected to your data provider, you were able to load further than 5 days back?

                Does the indicator plot as expected as well?
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  Yes... connecting to the data provider was the problem.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by rtwave, 04-12-2024, 09:30 AM
                  4 responses
                  29 views
                  0 likes
                  Last Post rtwave
                  by rtwave
                   
                  Started by yertle, Yesterday, 08:38 AM
                  7 responses
                  28 views
                  0 likes
                  Last Post yertle
                  by yertle
                   
                  Started by bmartz, 03-12-2024, 06:12 AM
                  2 responses
                  21 views
                  0 likes
                  Last Post bmartz
                  by bmartz
                   
                  Started by funk10101, Today, 12:02 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post funk10101  
                  Started by gravdigaz6, Yesterday, 11:40 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X