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

priorTradesCount and priorTradesCumProfit

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

    priorTradesCount and priorTradesCumProfit

    I understand the idea but I don't get the code. Here is tje example taken from your reference samples:

    #region variables
    private int priorTradesCount = 0
    private double priorTradesCumProfit = 0

    #OnBarUpdate()
    //Store the strategy's prior cumulated realized profit and number of trades
    priorTradesCount = Performance.AllTrades.Count;
    priorTradesCumProfit = Performance.AllTradesPerformance.Currency.CumProfi t;

    I guess here if the strategy makes 3 trades, then the priorTradesCount =3, the same with the cumulated realized profit, if the profit is 1000, then the priorTradesCumProfit=1000

    Is that correct?

    What I don't understand is:
    Prevents further trading if the current session's realized profit exceeds 1000, and also prevent trading if 10 trades have already been made in this session.

    If I write this:
    if(Performance.AllTradesPerformance.Currency.CumPr ofit - priorTradesCount>=1000
    I understand that if in the previous part I wrote:
    priorTradesCumProfit = Performance.AllTradesPerformance.Currency.CumProfi t; and the result is 1000, if now I write if(Performance.AllTradesPerformance.Currency.CumPr ofit - priorTradesCount>=1000, it is like 1000 - 1000 = 0 so it makes no sense.

    The same happens with the number of trades.

    Thank you

    Sincerely

    Daniel

    #2
    Hi Daniel,

    Which reference sample do you want to know more about? If it's the SamplePnL one here, your post is missing the Bars.FirstBarOfSession part. This is critical in capturing these values at the start of the session in order to make comparions on session PnL.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Yes, it is the SamplePnL.
      If (Bars.FirstBarOfSession) is true,I guess the prior cumulated realized profit and number of trades is 0, why don't we write priorTradesCount = 0 and priorTradesCumProfit = 0??

      Can you give me an example with numbers please, I am so confused

      Thank you

      Comment


        #4
        It works like this:
        At the start of each session, your trades performance is captured. Let's say that prior to the current session you made 25 trades, so this value is 25.

        In the current session you make more trades so this increases the total counter. If you make 5 trades, then the total count is 30.

        To identify the total number of trades in a session you subtract the total from your captured first bar of session value to get 5.

        Total - FirstBarOfSessionValue = SessionCount
        30 - 25 = 5
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Perfectly explained. Got it!!!!!!!

          Thanks a lot

          Comment


            #6
            Great to hear. It's one of the trickier samples to follow so I'm glad this explanation helped shed some light.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by techgetgame, Yesterday, 11:42 PM
            0 responses
            8 views
            0 likes
            Last Post techgetgame  
            Started by sephichapdson, Yesterday, 11:36 PM
            0 responses
            2 views
            0 likes
            Last Post sephichapdson  
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,613 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Yesterday, 05:56 PM
            0 responses
            10 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            20 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Working...
            X