Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tick recording Indicator Framework

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

    Tick recording Indicator Framework

    Hi,

    Ever dreamed of being able to code tick logic in an indicator, and being able to use on historical bars ? This is for you.

    Here's the GomRecordingIndicator indicator that you just have to derive your own indicator from, implement GomOnMarketData and GomInitialize, and you're done !

    The GomRecordingIndicator class takes care of recording data on real-time ticks, ans sending recorded data to GomOnMarketData like a virtual data source would do.

    Here's how you would code a VWMA for instance :

    Code:
        ///////Derive your indicator from GomRecorderClass
        public class GomVWMA : GomRecorderIndicator
        {
            double volsum=0;
            double vwma=0;
            double currentvwsma;
        
        //////Use GomInitialize like you would use Initialize
            protected override void GomInitialize()
            {    
                Add(new Plot(Color.Orange, "GomVWAP"));
    
                CalculateOnBarClose    = false;
                Overlay                = true;
                PriceTypeSupported    = false;
            }
    
        //////Put your code here in GomOnMarketData 
        //////usr it like OnMarketData, and check firstTickOfBar
        //////TickType is TickTypeEnum=BelowBid,AtBid,BetweenBidAsk,AtAsk,AboveAsk
        /////CAUTION IF NO DATA PRESENT FOR THE BAR YOU WILL RECEIVE (BetweenBidAsk,last known price,0,true) SO VOLUME CAN BE NULL
            protected override void GomOnMarketData(TickTypeEnum tickType,double price,int volume,bool firstTickOfBar)            
            {    
                if ((firstTickOfBar))   
                {    
                    volsum=0;
                    vwma=0;
                }                        
                
                volsum += volume;
                vwma += price*volume;
                
                currentvwsma=(volsum>0?vwma/volsum:price);
                
                Value.Set(currentvwsma);
            }
        }
    10 lines of code to be able to use tick data on historical basis, that's short !

    Caution complete tick info is not recorded, it's limited to price, volume, and ticktype which is : BelowBid,AtBid,BetweenBidAsk,AtAsk,AboveAsk. You can't to bid/ask spread analysis, for instance.

    Implementation of the types is less naïve than a simple >=ask or <=bid method, which doesn't take account of the fact that we can have bid=ask or even bid>ask.
    Here's what I used :
    Code:
                    if (ask<bid) // should not happen but does
                    { 
                        if (e.Price<ask)         tickType=TickTypeEnum.BelowBid;
                        else if (e.Price==ask)     tickType=TickTypeEnum.AtAsk;
                        else if (e.Price<bid)     tickType=TickTypeEnum.BetweenBidAsk;
                        else if (e.Price==bid)     tickType=TickTypeEnum.AtBid;
                        else                     tickType=TickTypeEnum.AboveAsk;
                    }
                    else if (bid<ask) //normal case
                    {
                        if (e.Price<bid)         tickType=TickTypeEnum.BelowBid;
                        else if (e.Price==bid)    tickType=TickTypeEnum.AtBid;
                        else if (e.Price<ask)    tickType=TickTypeEnum.BetweenBidAsk;
                        else if (e.Price==ask)     tickType=TickTypeEnum.AtAsk;
                        else                    tickType=TickTypeEnum.AboveAsk;
                    }
                    else //bid==ask, should not happen
                    {
                        if (e.Price<bid)        tickType=TickTypeEnum.BelowBid;
                        else if (e.Price>ask)    tickType=TickTypeEnum.AboveAsk;
                        else                    tickType=tickType=TickTypeEnum.BetweenBidAsk;
                    }
    File Format can be selected, it's either "Flat" which is user friendly to read but verbose, and "Short" which creates smaller files less easy to read. Default is "Short". Date/Times are stored in UTC so files can be shared.

    There is one file for each Instrument Name and for each file format, so you can use both formats at a time.

    You can use multiple indicators implementing the framework on the same instrument, only one of them per file format will have recording capabilities, identified by "Recording OK". Caution : NT logic is sometimes strange, and depending on what you click in Indicators properties, indicators might lose the writing handle : you get a "Recording KO". Press F5 to refresh an recover the handle.

    That's about it. You'll find below a picture of VWMA and CD indicator, sharing the same file, the GomRecorderIndicator and the example VWMA example
    Attached Files

    #2
    Thank you very much for sharing this with our community gomifromparis!
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks very much gomifromparis,

      your code is a great idea !. It converts to automatic the whole file-manager process.

      I was using some command buttons for this purpose. But your code is best idea

      Best Regards.



      Comment


        #4
        confused

        Gomi,
        I don't understand if whit this indicator i can recorder data from market analyzer and use it for your GomCD indicator.

        Hi Csl71, what kind of indicator is that on your picture? It seems like footprint with delta or something like...
        You'd like to share it?

        Thanks.
        Lubo.

        Comment


          #5
          The GomCD uses this indicator, so if you plan to see CDs, you can just use GomCD and play market Replay to populate the file.

          I released the "bare" GomRecorderInidcator if you want to built other tick related indicators, that will use the same file.

          Comment


            #6
            Originally posted by LuboLabo View Post
            Hi Csl71, what kind of indicator is that on your picture? It seems like footprint with delta or something like...
            You'd like to share it?

            Thanks.
            Lubo.
            I don't know that is footprint. My indicator analyzes the bid-ask and the difference. Sorry, but it is a prototype yet and not work correctly.
            Regards.
            Last edited by cls71; 04-10-2009, 10:03 AM.

            Comment


              #7
              Volume Footprint.

              Originally posted by cls71 View Post
              I don't know that is footprint. My indicator analyzes the bid-ask and the difference. Sorry, but it is a prototype yet and not work correctly.
              Regards.
              Ya, Volume Footprint chart is an indicator that analyze the bid ask and volume, it's derived from MarketDelta platform and it's a great tool. U can try it for 30 days from here http://www.fin-alg.com/volumefootprint_gallery.html.

              Lubo.

              Comment


                #8
                Originally posted by gomifromparis View Post
                The GomCD uses this indicator, so if you plan to see CDs, you can just use GomCD and play market Replay to populate the file.

                I released the "bare" GomRecorderInidcator if you want to built other tick related indicators, that will use the same file.
                Great contribution, Gomi. Any idea how to recover from lost internet connections? As far as I know, NT/Zenfire doesn't have the ability to backfill ask/bid data if your internet connection is lost. That renders the ask/bid method of CD calculation rather impractical for any trading strategy that relies on data to be complete over a certain historical period of time. The Uptick/Downtick method of calculation doesn't have that problem because you can export historical data from NT and then convert it to the GomCD format. Come to think of it, maybe that's a feature request for the recorder? Any ideas what to do with respect to the ask/bid method in face of internet connection failures? Another data feed maybe?

                D.

                Comment


                  #9
                  gomifromparis,

                  Wow thanks for this! I am sure I can find a use for it.

                  Mike

                  Comment


                    #10
                    Originally posted by dosh1965 View Post
                    The Uptick/Downtick method of calculation doesn't have that problem because you can export historical data from NT and then convert it to the GomCD format.
                    1.Come to think of it, maybe that's a feature request for the recorder?
                    2.Any ideas what to do with respect to the ask/bid method in face of internet connection failures? Another data feed maybe?
                    1. Well, yes it could be done, and the tick type would be "between bid&ask". Unfortunately you would have to use tick calculation all the time, even when bid/ask data is correct.
                    2. Apart from buying tick data files and converting them to GomCD format, I don't see any other solution. Or maybe finding a guy who has the good data in a GomCD file and send you the missing data. It would be quite complicated though, nothing very robust unfortunately. Why not use IRT then

                    Comment


                      #11
                      Originally posted by gomifromparis View Post
                      1. Well, yes it could be done, and the tick type would be "between bid&ask". Unfortunately you would have to use tick calculation all the time, even when bid/ask data is correct.
                      2. Apart from buying tick data files and converting them to GomCD format, I don't see any other solution. Or maybe finding a guy who has the good data in a GomCD file and send you the missing data. It would be quite complicated though, nothing very robust unfortunately. Why not use IRT then
                      DTN/IQ now provides a 30-day historical bid/ask tick data (outside market hours). The export format of NT doesn't include those fields (I've submitted a feature request to NT for that), but I/RT does. The costs add up though...

                      One idea here, maybe GomCD recorder can write the tick data (with tick type, of course) to a separate file for each session. A few of us who run NT/Zen can create an online repository where the daily file is uploaded at the end of each session there for others to use in case of failures. This will serve as a long-running failsafe database.

                      Comment


                        #12
                        There's a way to convert tick data to GomCD data?

                        Originally posted by gomifromparis View Post
                        1. Well, yes it could be done, and the tick type would be "between bid&ask". Unfortunately you would have to use tick calculation all the time, even when bid/ask data is correct.
                        2. Apart from buying tick data files and converting them to GomCD format, I don't see any other solution. Or maybe finding a guy who has the good data in a GomCD file and send you the missing data. It would be quite complicated though, nothing very robust unfortunately. Why not use IRT then

                        How to?
                        Maybe with excel?

                        Thanks.
                        Lubo.

                        Comment


                          #13
                          Hi,

                          Here's an application (requiring 3.5 .NET Framework) to convert from GomShort, GomFlat, NinjaExport, IRTExport to GomShort & GomFlat formats.

                          The application creates GomConverterFile in My Documents.

                          If the file to convert does not provide bid/ask information, ticktype is set to "unknown".

                          Please take note you must enter the correct ticksize in the case of using Short format for reading or writing.



                          I also include the (ugly) form source, and the new version of the Recording Framework.

                          I didn't include automatic backfill of an existing file because there could be some very weird results if existing and backfill source files had timestamps offset by 1 or 2 seconds.

                          Enjoy !
                          Attached Files
                          Last edited by gomifromparis; 04-26-2009, 08:59 AM.

                          Comment


                            #14
                            Gomi's File Converter

                            Too Cool..

                            Thanks again!

                            Comment


                              #15
                              Here's a new version of the encoder and File Framework, using a new encoding format : Binary. It creates file 3 times smaller than short, and is binary encoded, so parsing is fast.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              436 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X