Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

periodically write price data to a file

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

    periodically write price data to a file

    Hello,

    I have a large external body of C# code with many complex indicators
    and want to periodically write quotes and lasts from Ninja into a file
    which can be referenced by those external indicators.

    My search of the forum topics did not turn up any related code examples.

    The code included below illustrates a general outline of what I'm trying to accomplish.
    The problem for me is that I'm not really sure where to put that baseline code within the Ninja Framework.


    Should I try to implement this as a ninja indicator, or should I make it as a stand alone thread, or some other handler?
    Are there any existing examples available which do similar things involving timers and files?

    What is the object name which contains the list of ticker symbols subscribed to level 1 quotes and lasts?
    What is the object name which contains the quote and last prices of those symbols?


    Can you provide any suggestions how to get started?

    Thanks,
    John Devron



    #region this is declared global at the top of the file which will write the quotes
    //declare new instance of a timer
    System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
    #endregion


    #region this goes inside a form load routine
    // Initialize the timer
    timer1.Interval = 500; //timer fires every 500 milliseconds
    timer1.Tick += new System.EventHandler(this.write_quote_data);
    timer1.Enabled = true; //activate the timer to begin
    #endregion


    #region this goes inside some code file
    public static void write_quote_data()
    {
    int sym_num = new int();
    string line_data = null;
    string quotes_file = @"C:\live_quote_data\realtime_quotes.txt";

    int SFM = DateTime.Now.Second
    + (60 * DateTime.Now.Minute)
    + (3600 * DateTime.Now.Hour); //get the time in Seconds From Midnight

    using (StreamWriter filestream1 = File.CreateText(quotes_file)) //Open the file to create a new file
    {
    for (sym_num = 0; sym_num < GlobalVars.num_Intraday_ticker_symbols; sym_num++)
    {
    line_data = SFM
    + "," + GlobalVars.Intraday_watchlist[sym_num]
    + "," + GlobalVars.last_price[sym_num] + "," + GlobalVars.last_size_up[sym_num] + "," + GlobalVars.last_size_down[sym_num]
    + "," + GlobalVars.best_ask[sym_num] + "," + GlobalVars.ask_size[sym_num]
    + "," + GlobalVars.best_bid[sym_num] + "," + GlobalVars.bid_size[sym_num];
    filestream1.WriteLine(line_data);
    }
    filestream1.Close(); //Close the file
    }//using (StreamWriter

    }//write_quote_data()
    #endregion


    #2
    Hello jdevron, thanks for your post, and welcome to the NinjaTrader forum.

    This page has examples of handling the multithreaded nature of NinjaTrader, see the example on writing a file using a dispatcher under the header "Access Violation Exception":



    This could be implemented as either an indicator, an add-on, or as a standalone C# application. Developing as an indicator or addon would be the most straight forward way to access price data. The addon framework example here shows how to access price data from an add-on.

    Please let me know if you have any additional questions.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Waxavi, Today, 02:00 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by alifarahani, Today, 09:40 AM
    5 responses
    23 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Kaledus, Today, 01:29 PM
    5 responses
    12 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by gentlebenthebear, Today, 01:30 AM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by PhillT, Today, 02:16 PM
    2 responses
    7 views
    0 likes
    Last Post PhillT
    by PhillT
     
    Working...
    X