Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting profit & loss for the day (session)

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

    Getting profit & loss for the day (session)

    How can I get that info? I need to write an entry condition that only enter if current day p&l is less than certain amount or percent of account balance.

    Thanks

    #2
    Hello ssg10,

    This sample is great for getting session PnL.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Not working?

      It doesn't seem to work in strategy analyzer. It generates 0 trades:

      if (Close[0] > SMA(Open, MALen)[0]
      && Position.MarketPosition == MarketPosition.Flat
      && Performance.AllTrades.TradesPerformance.Currency.C umProfit - priorTradesCumProfit >= -
      500)
      {
      EnterLong(
      2, "long");
      }

      Any idea?

      Comment


        #4
        ssg10,

        Just running the SamplePnL modifying it with your code in the strategy analyzer generates trades for me. Perhaps if you could post more of your code we could identify the issue.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Thanks... Yes, you are right, it works. It generates trades now, but it does not stop trading after $500 daily limit is hit....

          Check this out:

          World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.

          Comment


            #6
            Hello,

            Scaring me there with that screenshot and all them red bars

            What code do you have for getting our of a trade if PnL is above a threshold? I see that you have code most likely correct for not taking a new one if it is above the treashold but the current trade would go to completion most likely and that may or may not put you over the threshold.

            I look forward to assisting you further.
            BrettNinjaTrader Product Management

            Comment


              #7
              Sorry, I selected only the losers in the picture to make it more obvious to see

              My code to exit is just setstoploss:

              protectedoverridevoid Initialize()
              {

              ....
              SetProfitTarget(
              "long", CalculationMode.Ticks, ProfitTarget1);
              SetStopLoss(
              "long", CalculationMode.Ticks, StopLoss, false);
              SetProfitTarget(
              "short", CalculationMode.Ticks, ProfitTarget1);
              SetStopLoss(
              "short", CalculationMode.Ticks, StopLoss, false);

              Comment


                #8
                Hello,

                Most likely the code is only preventing new entires once the PnL value is violated. Any entries already put into place would still play out.

                You would need code to close any open positions if then PnL value was above a threashold.

                Have you added code to do this?

                -Brett
                BrettNinjaTrader Product Management

                Comment


                  #9
                  Hi,

                  Yes .I think you are right. It looks better now. I will work on this more and if I have more questions, I will post here.

                  Thanks for the great support!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by argusthome, Yesterday, 10:06 AM
                  0 responses
                  20 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  18 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  14 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post TheRealMorford  
                  Started by Mindset, 02-28-2026, 06:16 AM
                  0 responses
                  40 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Working...
                  X