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

Detect all tick replay data loaded

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

    Detect all tick replay data loaded

    Hello,

    This is most probably going to be an easy question for you all, but I'm still a newbie in terms of programming for NT8.

    For my indicator I want to load all tick replay data, so I use OnMarketData.
    Inside I have a dictionary with data of current candle. When base.IsFirstTickOfBar is true - this dictionary is added to the main list of all data and cleared to gather new candle's data.

    At base.IsFirstTickOfBar part, I send candle data to my external data source.
    When all data is loaded - I have 2 collections:

    1) All candles without the current one in the main list (sent externally)
    2) Dictionary with current's candle data inside

    So my problem is - I can successfully send 99,99% of candle data, but the current one (last one) is not being sent, because there is no next base.IsFirstTickOfBar occurence .

    I don't want to send data on each OnMarketData event because that would be terrible during ticket replay data load. I want to enable it when all data is loaded and at the very end - it can start running on every OnMarketData occurence.

    Code:
    protected override void OnMarketData(MarketDataEventArgs e)
            {
                if (e.MarketDataType == MarketDataType.Last)
                {
    				
                    if (base.IsFirstTickOfBar)
                    {
                        previous candle is finished - send data and clear dictionary
                    }
    				
    		if (e.Price >= e.Ask)
                    {
                        add to current's candle collection
                    }
                    else if (e.Price <= e.Bid)
                    {
                        add to current's candle collection
                    }
    I wanted to add sending current's candle data here but during tick replay it would be executed countless times.
    
                }
            }
    I hope I didn't confuse you all...

    #2
    Hello dariuszszyc,

    To confirm, with TickReplay enabled in the Data Series parameters on the chart, you want to trigger an action on the last bar of historical data without waiting for a real-time bar to open, is this correct?

    Use a bool that is set in OnBarUpdate when State is State.Historical and CurrentBar is Count - 2 and IsFirstTickOfBar is true. This would trigger on the second to last historical bar (as the last historical bar is not closed until the real-time bar is opened).

    Then you can have any actions in OnMarketData after this bool is flipped.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello dariuszszyc,

      To confirm, with TickReplay enabled in the Data Series parameters on the chart, you want to trigger an action on the last bar of historical data without waiting for a real-time bar to open, is this correct?
      Yes, that's exactly what I need.

      Originally posted by NinjaTrader_ChelseaB View Post

      Use a bool that is set in OnBarUpdate when State is State.Historical and CurrentBar is Count - 2 and IsFirstTickOfBar is true. This would trigger on the second to last historical bar (as the last historical bar is not closed until the real-time bar is opened).

      Then you can have any actions in OnMarketData after this bool is flipped.
      Is this what you mean ? It never gets executed:

      Code:
      protected override void OnBarUpdate()
      {
      if (base.State == State.Historical && IsFirstTickOfBar && CurrentBar == Bars.Count - 2)
      {
          loaded = true;
          Print("LOADED");
      }
      Not sure if this has any meaning but for the record I'm using Calculate.OnEachTick;

      I also added this to the beginning of OnBarUpdate()

      Code:
      if (IsFirstTickOfBar)
      Print("Current: " + CurrentBar + " | Bars.Count: " + Bars.Count);
      And this is the output (last part of it):

      Code:
      Current: 79 | Bars.Count: 80
      Current: 80 | Bars.Count: 81
      Current: 81 | Bars.Count: 82
      Current: 82 | Bars.Count: 83
      Current: 83 | Bars.Count: 84
      Current: 84 | Bars.Count: 85
      Current: 85 | Bars.Count: 86
      Current: 86 | Bars.Count: 87
      Current: 87 | Bars.Count: 88
      Current: 88 | Bars.Count: 89
      So it seems I am always 1 candle behind instead of 2.
      Last edited by dariuszszyc; 06-17-2018, 11:21 PM.

      Comment


        #4
        Hello dariuszszyc,

        I overlooked that..

        When TickReplay is enabled NinjaTrader behaves as if the data is real-time (though the State is State.Historical) and Count starts at 0 and is incremented. (The Playback with historical tick data works the same way.)

        However, you could trigger an action in OnStateChange when State becomes State.Realtime.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by alifarahani, Today, 09:40 AM
        6 responses
        31 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Kaledus, Today, 01:29 PM
        5 responses
        13 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Waxavi, Today, 02:00 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by gentlebenthebear, Today, 01:30 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X