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

Custom live data filter

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

    Custom live data filter

    Hello,

    Is it possible to create a more specific live data filter? For example, to exclude ticks under certain volume? Or is there any other way to effectively achieve this so that an indicator would ignore same data, like with a bar type that would essentially be a 1 minute bar (for example), but it would not create a bar if there was less than a specified volume within a minute?

    Thanks!

    #2
    Hello RobotSyndicate,

    i am not sure if there is an item like that already but you could make either an indicator or bars type that does that kind of logic. An indicator would be if you wanted to do that calculation over existing bars. A BarsType would be if you wanted to form bars that look a certain way based on the data that populates the bar.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jesse! I made a custom bars type to accomplish it and I'm pretty sure it is working as desired. This is my first stab at a custom bars type, but it seems to me like this should do the trick? Would you mind glancing at it to see if I missed something?

      In a nutshell, I do a lot of equity trading outside of regular trading hours, and there is a lot of data that can throw off indicators and backtesting fills from small ticks at prices that I can't actually get filled at live, and then if the next tick jumps back to a more realistically available price, it totally throws off the historical fill algorithm to give VERY unrealistic results. So I made a little program that will go through data files and erase any lines with volumes < 500 or if high = low. Then it looks for gaps between the prior close and current open and fills them in (editing the current high or low if needed), so that backtesting my limit orders is much more realistic specifically for low volume equity trading. It works well, BUT its a process and can't be used live...

      So the purpose of this is to accomplish the same task, but from within NT as bars are being created or not created, to filter out the data points I don't want!

      Specifically I'm wondering if this new bars type is actually going to actually ignore the data I don't want or will it still Update it to existing bars until volume > 500, and will it act the same live vs historical? As it is my understanding that on historical data OnDataPoint would be called every minute (since this is based on the minute bars type), whereas live it would be called every tick. Even when live, I would like it to ignore the data if volume is < 500 during a minute interval.

      The bars type is an altered MinuteBarsType. Here is the OnDataPoint code:

      protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
      {
      if (SessionIterator == null)
      SessionIterator = new SessionIterator(bars);

      if (bars.Count == 0)
      AddBar(bars, open, high, low, close, TimeToBarTime(bars, time, isBar), volume);
      else if (!isBar && time < bars.LastBarTime)
      UpdateBar(bars, high, low, close, bars.LastBarTime, volume);
      else if (isBar && time <= bars.LastBarTime)
      UpdateBar(bars, high, low, close, bars.LastBarTime, volume);

      //ignore this period if less than 500 volume or if high equals low, both of which are frequently seen outside of the regular trading session and they tend to throw off indicators and not be a price that could realistically be filled anyway.

      else if (volume >= 500 && high != low)
      {

      //Fill in gaps so that backtesting with limit orders in thin equity markets is remotely accurate. Obviously this won't work for all strategies.

      var previousClose = bars.GetClose(bars.Count - 1);
      open = previousClose;
      if (open < low)
      {
      low = open;
      }

      if (open > high)
      {
      high = open;
      }
      time = TimeToBarTime(bars, time, isBar);
      AddBar(bars, open, high, low, close, time, volume);
      }
      }​
      Last edited by RobotSyndicate; 06-08-2023, 09:27 PM.

      Comment


        #4
        Hello RobotSyndicate,

        You would need to test the bars type to know if its working right per what you coded, that is not something I would be able to do for you.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by PaulMohn, Today, 05:00 AM
        0 responses
        1 view
        0 likes
        Last Post PaulMohn  
        Started by ZenCortexAuCost, Today, 04:24 AM
        0 responses
        5 views
        0 likes
        Last Post ZenCortexAuCost  
        Started by ZenCortexAuCost, Today, 04:22 AM
        0 responses
        2 views
        0 likes
        Last Post ZenCortexAuCost  
        Started by SantoshXX, Today, 03:09 AM
        0 responses
        15 views
        0 likes
        Last Post SantoshXX  
        Started by DanielTynera, Today, 01:14 AM
        0 responses
        3 views
        0 likes
        Last Post DanielTynera  
        Working...
        X