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

determine profits today

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

    determine profits today

    i want to determine how many points that my strategy has incurred today for this instrument so i can cap my profits for that instrument and stop for the day. its possible that i might stop and start the strategy and so i put in a code in onbarupdate to determine the initial number before it starts using the trading logic. however the initial number is always 0.
    this is my logic. can you point out if this is right or suggest a alternative?
    my logic is to loop the Performance.RealtimeTrades and filter out the trades done today for the current instrument and sum the profitpoints.
    Code:
     if(pointstoday==Double.MinValue)
    				{
    					pointstoday=0;
    					foreach (Trade myTrade in Performance.RealtimeTrades)
    						{
    							if (myTrade.Entry.Instrument.FullName==Instrument.FullName && myTrade.Exit.Time.Date==DateTime.Now.Date)
    							{
    								pointstoday+=myTrade.ProfitPoints;
    							}
    						}
    		
    					 
    					 
    						Print("starting profits " + Instrument.FullName +Instrument.MasterInstrument.Round2TickSize( pointstoday));
    					
    				}

    #2
    Hello junkone,

    The code here looks to be made for multiple instrument series, but does look as if it should print the PnL of all trades that have closed today on the primary instrument, but only if the current value of pointstoday is equal to the smallest possible value allowed for a double.

    if(pointstoday==Double.MinValue)

    Are you setting pointstoday to Double.MinValue to ensure this evaluates as true?

    Have you added any prints to your code to debug and find out if this condition is evaluating as true?
    Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I thought Performance.RealtimeTrades will contain all the trades from the database. it looks like it will only return trades that are executed within the strategy after I enable it. if I disable the strategy, I cannot retrieve the history from the next time I enable it again. is that correct?

      Comment


        #4
        Hello junkone,

        The Performance collection is the performance of the Strategy, not the performance of the account.

        A NinjaScript strategy is only able to see trades that are made by that instance of the strategy. This will apply to the position as well as the performance.

        When you disable a strategy and re-enable this, the strategy will re-process all of the historical data.
        If the Tools -> Options... -> Strategy -> NinjaScript -> 'On starting a real-time strategy' option is set to 'Wait until flat before executing live', then no orders will be matched and the orders will all be part of the historical performance.
        If the 'On starting a real-time strategy' option is set to 'Immediately submit live working historical orders', then NT will attempt to resume any matched trades.

        From the help guide on 'Immediately submit live working historical orders' with Account Sync false.
        • Any active orders on the account previously generated by the strategy that does not match* an active strategy order will be cancelled. Should the strategy be unable to cancel and receive confirmation on the cancellation of these orders within 40 seconds the strategy will not start and an alert will be issued.
        • The matching active orders on the account will then be mapped to the active strategy orders
        • Any remaining active strategy orders that cannot be successfully paired will be submitted live and the strategy will begin managing your Strategy Position assuming your Account Position is in sync with it.

          * A previously generated order is considered to match an active strategy order when the order action, order type, quantity, limit price, and stop price are exactly identical.



        If the order is matched, then that real-time order / trade will be resumed and will show in the real-time performance.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I think this response is a key distinction that needs to be documented.
          The Performance collection is the performance of the Strategy, not the performance of the account.

          A NinjaScript strategy is only able to see trades that are made by that instance of the strategy. This will apply to the position as well as the performance.

          Comment


            #6
            Hello junkone,

            Are you finding the Strategy Position vs. Account Position page in the help guide is inadequate at detailing the strategy's position is independent from any other running strategy's position or the account position?



            How you like this documentation re-worded so that the information is more clearly understood?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              the documentation change is needed in description of the Performance collection object. you can just add the points that you described in this thread which made it crystal clear. If I had known this , I would have saved 1 day of trial/error trying to figure out how to create a daily target.

              Comment


                #8
                Hello junkone,

                I am happy to submit a feature request on your behalf to change the documentation to include the information from the Strategy Position vs. Account Position page with the SystemPerformance page.

                Would you prefer just this SystemPerformance page have the information from the Strategy Position vs. Account Position page added in?
                (I was thinking that the Position, Orders, Performance Metrics, Execution, OnOrderUpdate, OnPositionUpdate, and OnExecutionUpdate are all affected the same as the SystemPerformance and for consistancy should also have this added in as well. But I'm happy to just send the request for the SystemPerformance page.)
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  i agree with you

                  Comment


                    #10
                    Hi junkone,

                    I've submitted a request to our development to add the information from 'Strategy Position vs. Account Position' to these other strategy method pages.

                    It will be up to our development to decide if and when to implement any request.

                    As a heads up, the NinjaTrader 7 help guide is locked. Any changes, if implemented, will be implemented in the NinjaTrader 8 documentation.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by pechtri, 06-22-2023, 02:31 AM
                    9 responses
                    122 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by frankthearm, 04-18-2024, 09:08 AM
                    16 responses
                    66 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by habeebft, Today, 01:18 PM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by benmarkal, Today, 12:52 PM
                    2 responses
                    13 views
                    0 likes
                    Last Post benmarkal  
                    Started by f.saeidi, Today, 01:38 PM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Working...
                    X