Announcement

Collapse
No announcement yet.

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:

          https://ninjatrader.com/support/help.../calculate.htm

          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 condorhero, Today, 09:28 PM
          0 responses
          6 views
          0 likes
          Last Post condorhero  
          Started by MaraAnkh, Today, 08:44 PM
          0 responses
          8 views
          0 likes
          Last Post MaraAnkh  
          Started by wooofad, Today, 05:38 PM
          0 responses
          7 views
          0 likes
          Last Post wooofad
          by wooofad
           
          Started by caacapital, Today, 10:10 AM
          2 responses
          18 views
          0 likes
          Last Post caacapital  
          Started by DiverG20, Today, 10:23 AM
          0 responses
          25 views
          0 likes
          Last Post DiverG20  
          Working...
          X