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

Trying to Create Log File of Realized and Unrealized Gains Every 30 Seconds

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

    Trying to Create Log File of Realized and Unrealized Gains Every 30 Seconds

    Hi, everyone!

    I am new to this whole NinjaTrader and C# thing, and I'm trying to wrap my head around how to start, so please bear with me. I wish to create a daily log file of realized and unrealized gains every 30 seconds throughout the trading day.

    After digging around here and in as many help areas as I could find, I understand that I should likely use the StreamWriter function along with the CustomEvents and Timer functions. I'm just having trouble putting it all together.

    Has anyone done something similar? Do I write this script as an Indicator?

    I do have the SampleStreamWriter.cs and SampleCustomEvents.cs files and have been studying those, but if you have any additional pointers for me, I'd be extremely grateful.

    Thanks much!

    #2
    Hello bigfatdrunk,

    Those samples are good for writing to files and using a timer object. Performance details are only available programatically from the strategy that generates them, so this will have to be integrated into a strategy. This sample can help working with the TradePerformance class and resetting values each day:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your prompt reply, Ryan!

      So, I will need to integrate this code into a strategy... hmmmm, ok... can Timer and StreamWriter both be used within a strategy?

      You also pointed me to the sample that resets values each day, and I'm guessing you did this because of the calculated realized and unrealized gains. Will I need to refresh these two values each new trading day? Otherwise, the strategy wants to carry them over from the previous day? If I've misunderstood your reason for the other sample, please accept my apologies and set me straight!

      Comment


        #4
        Yes, you can use streamwriter and custom timers in a strategy.

        That sample was provided based on your desired "daily log" and because it works with TradePerformance class. I'm not sure which values you'll want to reset each day. Unfortunately we do not have a sample that does exactly what you want, so you will have to custom code it. Additional samples that work with trade performance are here:


        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks for your help, Ryan, but I have a couple of follow-up questions for you.

          As I look at the code - and what it is I can get out of NT - I see a couple of problems. First, I am looking to pull data out of a specific account, not just for a specific investment. For example, I have 20 stocks in my portfolio, and I can get PnL for each on an individual basis. What about for the account as a whole? The getaccountvalue doesn't have a variable (I can find) that allows me to send a specific account number, so does it relay all accounts? The ATMStrategy equivalent does allow me to specify an account here. The .Performance seems to work across multiple accounts, as well.

          Additionally, I can do what I need in Market Analyzer, specifically by adding the ProfitLoss field, and it works very well. Can I spit information from the Market Analyzer? I see in the forums I can't make direct queries into it, but if I could send an alert with the Total ProfitLoss, etc., that would do the same thing. Suggestions?

          In other words, it appears that my roadblock is not with StreamWriter but with NT itself and what I am/am not allowed to query.

          At this point, I'm not sure how to best handle grabbing the PnL every 30 seconds for a specific account aside from kluging together something from Market Analyzer.

          Again, thanks for all of your help!

          Comment


            #6
            GetAccountValue() will access the account details for the account that the strategy is run against.

            This is the only supported method in NinjaTrader for accessing account details programatically.

            The market analyzer source code for @ProfitLoss is available to you, but is not supported. This means we are unable to assist with specific usage or help if there's an issue using it. You can check it out at:
            My Documents\NinjaTrader\bin\Custom\Market Analyzer.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,606 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            15 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X