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

GetDayBar not working on Seconds timeframe

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

    GetDayBar not working on Seconds timeframe

    Code:
    		PrPrice = BarsArray[0].GetDayBar(1).Close;
    		IndicatorValue.Set(PrPrice);
    this code works fine on 1 minute chart, but shows nothing on 1 second chart. What's the difference?

    #2
    nysetrader,

    Who is your data provider?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Adam,
      IQFeed.

      Comment


        #4
        nysetrader,

        You should be getting second data here then. Could you possible post more of the code including the variables section, the Initialize() method and the OnBarUpdate() method?
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Code:
                  #region Variables
                  // Wizard generated variables
                  // User defined variables (add any user defined variables below)
          		double PrPrice;
                  #endregion
                 protected override void Initialize()
                  {
          			
                       Add("SPY", PeriodType.Minute, 1);
          
                       Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "IndicatorValue"));
                        Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "UpLine"));
          	Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "DownLine"));
                      Overlay	= false;
                  }
                 protected override void OnBarUpdate()
                  {
           			if(BarsInProgress == 0)	
          			{
          				
          				if (Bars.GetDayBar(1) == null)
          				{
          					return;
          				}
          				
          
          				PrPrice = BarsArray[0].GetDayBar(1).Close;
          
          			
          				IndicatorValue.Set(PrPrice);
          				UpLine.Set(PrPrice*1.02);
          				DownLine.Set(PrPrice*0.98);
          			}
          			else
          			{
          				return;
          			}
                  }
          Also can I use this:
          Code:
          Add("SPY", BarsPeriod.BasePeriodType, BarsPeriod.BasePeriodValue);
          instead of this:
          Code:
          Add("SPY", PeriodType.Minute, 1);
          in Initialize section?

          Actually the formula for PrPrice is more complicated, but the problem is in GetDayBar function.

          Comment


            #6
            nyse,

            It looks like its working ok on my end. You may need to ensure you have the historical data availability for the 1 minute series.

            You can also use PriorDayOHLC instead of the method you are using to get the open/high/low/close of the previous day.

            Here is a way to use the BarsPeriod.BasePeriodType and BarsPeriod.BasePeriodValue. Its not specifically supported but it works most of the time.

            Code:
                                    try
            			{
            				Add(Symbol2, BarsPeriod.Id, BarsPeriod.Value);
            			}
            			catch(Exception e)
            			{
            				Print("Warning : BarsPeriod.Id didn't work");
            			}
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              The same with PriorDayOHLC. Works fine on 1Minute Data, shows nothing on 1Second data.
              It works fine on Tick data too.
              Last edited by nysetrader; 05-15-2012, 10:52 AM.

              Comment


                #8
                nysetrader,

                What chart are you using?
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  If you mean symbol I'm using AAPL now. but it happens on all symbols I've tried. On Tick data it works fine too.

                  Comment


                    #10
                    I'm not changing the code. I just switch in chart window timeframes from keyboard from 1M to 1T to 1S. and on 1S it shows no lines.

                    Comment


                      #11
                      nysetrader,

                      Please right click your chart > go to "data series" > Set "Days to load" to a higher number. I had the same behavior until I set it to a few days of data. Most likely this is a historical data limitation.
                      Adam P.NinjaTrader Customer Service

                      Comment


                        #12
                        Seems to work fine now. Thank you. By the way, which function works faster, PriorDayOHLC or GetDayBar, for taking previous daily OHLC?

                        Comment


                          #13
                          nysetrader,

                          That's a good question. I am not sure actually, I suspect they would be about the same since in both cases I believe they are looking back over your chart to calculate the daily values.
                          Adam P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by algospoke, 04-17-2024, 06:40 PM
                          5 responses
                          46 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by arvidvanstaey, Today, 02:19 PM
                          1 response
                          4 views
                          0 likes
                          Last Post NinjaTrader_Zachary  
                          Started by mmckinnm, Today, 01:34 PM
                          3 responses
                          5 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by f.saeidi, Today, 01:32 PM
                          2 responses
                          8 views
                          0 likes
                          Last Post f.saeidi  
                          Started by alifarahani, 04-19-2024, 09:40 AM
                          9 responses
                          55 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Working...
                          X