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

Unexpected bar pattern OnBarClose in hosted indicator

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

    Unexpected bar pattern OnBarClose in hosted indicator

    Hi,

    I'm seeing unexpected behavior in an indicator that is running OnBarClose that is hosted from a strategy that is running OnEachTick. When running in Historical state the bar sequence is as expected, but when running in Realtime state I'm seeing a pattern of repeating timestamps and bar indices. Here are snippets of outputs from the indicator:

    Historical:
    ------------------------------
    1217 9/9/2020 6:27:06 PM
    Historical
    Volume 876
    ------------------------------
    1218 9/9/2020 7:18:26 PM
    Historical
    Volume 1610
    ------------------------------
    1219 9/9/2020 7:44:00 PM
    Historical
    Volume 665

    Realtime:
    ------------------------------
    1217 9/9/2020 6:27:06 PM
    Realtime
    Volume 876
    ------------------------------
    1218 9/9/2020 6:27:06 PM
    Realtime
    Volume 1
    ------------------------------
    1218 9/9/2020 7:18:26 PM
    Realtime
    Volume 1610
    ------------------------------
    1219 9/9/2020 7:18:26 PM
    Realtime
    Volume 1
    ------------------------------
    1219 9/9/2020 7:44:00 PM
    Realtime
    Volume 665
    ------------------------------
    1220 9/9/2020 7:44:00 PM
    Realtime
    Volume 1

    There is an additional instance of the timestamp but with the index incremented and with the volume = 1 (not shown here, but with Open[] == Close[] too).

    Details that might be relevant:
    - the strategy has an additional data series added in State.Configure: AddDataSeries(Data.BarsPeriodType.Tick, 1);
    - the strategy calls this indicator only when (BarsInProgress == 0) && (IsFirstTickOfBar == true)
    - the indicator sets Calculate = OnBarClose on State.SetDefaults and State.Historical
    - the indicator only runs this code segment when (BarsInProgress == 0) && (IsFirstTickOfBar == true) although it doesn't have an additional data series added
    - the strategy needs to necessarily run OnEachTick for another hosted indicator. It needs the 1 tick data series for this second indicator
    - the bar type is a renko from a particular vendor. I believe it runs in TickReplay mode by default but I'm not sure. The TickReplay check box is grayed out in the Data Series dialog box
    - The pattern occurs regardless of whether I access one barsAgo when IsFirstTickOfBar or zero barsAgo. It just offset by one from this repeating sequence

    The pattern illustrated occurs for ES and CL. I'm able to work around this but I just discovered that there is a different pattern for YM. Rather than find ways to workaround all this I'd like to get to the bottom of why it's happening and the best way to deal with it. I could get rid of the tick indicator as a last resort and run the strategy OnBarClode but I'd rather not.

    Thanks.

    #2
    Hello silverm3170,

    Thank you for your note.

    This is occurring because you are using IsFirstTickOfBar and Renko bars together. Renko bars redraw the open, so they cannot be used with Renko bars - please see the note on this page: https://ninjatrader.com/support/help...ttickofbar.htm

    Further, an indicator hosted by a strategy will adopt the same Calculate mode as the host strategy. The indicator will also calculate on each tick if the strategy is set to do so.

    You would need to use a bar type that does not remove the last bar in order to utilize IsFirstTickOfBar. It's also worth noting that because Renko bars redraw the open they cannot be used with Tick Replay.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      My understanding from a previous post on this forum is that an indicator can override the OneEachTick running mode of the hosting strategy if it sets Calculate to OnBarClose during State.Historical in OnStateChange, i.e.

      protected override void OnStateChange()
      {
      ....
      else if (State == State.Historical)
      {
      Calculate = Calculate.OnBarClose;
      }

      Is there a way of telling if a specific bar type removes the last bar?

      Thanks.

      Comment


        #4
        I just saw the documentation on IsRemoveLastBarSupported, so no need to get back to me on that. But could you please confirm the OnBarClose during Historical question?

        Thanks.

        Comment


          #5
          Hello silverm3170,

          Thank you for your replies.

          As far as Calculate goes, it would not be supported to set a separate calculate method for a hosted indicator, no. There previously was some incorrect documentation that stated this was possible, but that's been corrected in our help guide here:



          In particular:

          3. Embedded scripts within a calling parent script should not use a different Calculate property since it is already utilizing the Calculate property of the parent script (i.e. the strategy your indicator is called from).

          4. Since the parent NinjaScript therefore governs this setting, it should be set to the highest needed setting satisfying all its childs.

          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by The_Sec, Today, 02:29 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by jeronymite, 04-12-2024, 04:26 PM
          2 responses
          30 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by Mindset, 05-06-2023, 09:03 PM
          10 responses
          265 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by michi08, 10-05-2018, 09:31 AM
          5 responses
          743 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by tsantospinto, 04-12-2024, 07:04 PM
          4 responses
          63 views
          0 likes
          Last Post aligator  
          Working...
          X