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

bar period is incorrect.

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

    bar period is incorrect.

    Easy cloud file sharing for Mac, Windows, and iOS.

    as you can see from screenshot i am running on 5 minute bars.
    however this code prints the data as 1 minute. why?

    protected override void OnStartUp()
    {
    Print("base period id" + BarsPeriod.BasePeriodType.ToString());
    Print("BarsPeriod.BasePeriodValue " + BarsPeriod.BasePeriodValue.ToString());

    if(!( (BarsPeriod.BasePeriodType==PeriodType.Minute) && (BarsPeriod.BasePeriodValue ==5)))
    {
    // Throw warning that i got the wrong base period and this will screw up my stratgegy.
    // Generates a log message with a notification window

    Log("Wrong base period used", NinjaTrader.Cbi.LogLevel.Alert);



    }

    Called initialize
    **NT** Enabling NinjaScript strategy 'A0001/98ab3039586a4d3bbfa9d997d971df86' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
    **NT** Disabling NinjaScript strategy 'A0001/98ab3039586a4d3bbfa9d997d971df86'
    **NT** Enabling NinjaScript strategy 'A0001/3f002409b8184aefadca70320c06702b' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
    **NT** Disabling NinjaScript strategy 'A0001/3f002409b8184aefadca70320c06702b'
    **NT** Enabling NinjaScript strategy 'A0001/3f002409b8184aefadca70320c06702b' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
    base period idMinute
    BarsPeriod.BasePeriodValue 1
    **NT** Disabling NinjaScript strategy 'A0001/3f002409b8184aefadca70320c06702b'
    Called initialize
    **NT** Enabling NinjaScript strategy 'A0001/d5408f944f4541eca7ee14cb652e7ad0' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
    base period idMinute
    BarsPeriod.BasePeriodValue 1

    i can see from the print statements that it is thinking its running on 1 minute. why is this odd behaviour happening and how to prevent it.

    #2
    Hi Junkone,

    The property you're using is not for minute charts. Please see the following link:


    You'll want to use instead BarsPeriod.Value
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I could have a bars added using Add() leading to a multi instrument bars array, can i find out what the interval is for each of these bars array using runtime. or does it provide only base interval.

      Comment


        #4
        You can use BarsPeriods[ ] for accessing these properties in a multiseries context.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Trying to test for BasePeriodType.

          Within a multitimeframe indicator I want to know, whether the primary bars series is time based (minute or second chart) or built from tick charts.

          I therefore tested for

          Code:
          BarsPeriods[0].BasePeriodType == PeriodType.Minute 
          || BarsPeriods[0].BasePeriodType == PeriodType.Second
          However, this condition always returned the value "true", even on tick charts. Where is my mistake?

          Indicator for testing added.

          Another problem I encountered, is that this indicator will produce an error message, if the tick chart has less than 3 days of data. Why is this?
          Attached Files

          Comment


            #6
            Hi Harry,

            These properties are what you should check for instead:
            Code:
            if (BarsPeriods[0].Id == PeriodType.Minute
            || BarsPeriods[0].Id == PeriodType.Second)
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Thanks, that works. Did not correctly understand that help file, actually I had checked the same page as you have indicated.

              Comment


                #8
                Great to hear - Thank you for the followup. The properties you were using are for the special bar types - Kagi, LineBreak, PointAndFigure, and Renko.
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by ETFVoyageur, Today, 02:15 AM
                1 response
                13 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by lorem, 04-25-2024, 09:18 AM
                21 responses
                89 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by mlprice12, 12-21-2021, 04:55 PM
                5 responses
                307 views
                0 likes
                Last Post paypachaysa  
                Started by Human#102, 05-08-2024, 09:54 AM
                4 responses
                17 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by ETFVoyageur, Today, 06:11 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Working...
                X