Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ending Ninjascript strategy

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

    #16
    ending ninjascript

    Thanks Ray,
    How do I do the Strategy Running false thing, once I have achieved the profit target?

    Comment


      #17
      ending ninjascript

      Sorry Ray,
      I see now where you showed me after my code.
      Thanks,
      Jim

      Comment


        #18
        ending ninjascript

        Hi Ray,
        I have the code entered as below and it doesn't work. I get past $100.00 in profit, and the strategy keeps running/keeps sending orders, etc.


        // If the profit on real-time trades is > $100 stop trading
        if (Performance.RealtimeTrades.TradesPerformance.Curr ency.CumProfit > 100
        )
        Running = false
        ;

        Comment


          #19
          Try "return" after the check for $100.
          RayNinjaTrader Customer Service

          Comment


            #20
            ending ninjascript

            Are you saying instead of Running = false, use return?

            Comment


              #21
              Yes that is correct.
              RayNinjaTrader Customer Service

              Comment


                #22
                ending ninjascript

                Why won't this exit a long position that reaches > $100 profit, and stop the strategy from running.
                It isn't doing either thing.


                // If the profit on real-time trades is > $100 stop trading
                if (Position.MarketPosition == MarketPosition.Long && Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit > 100)
                ExitLong(
                "lg");
                if (Position.MarketPosition == MarketPosition.Short && Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit > 100)
                ExitShort(
                "sht");
                if (Performance.RealtimeTrades.TradesPerformance.Curr ency.CumProfit > 100)
                return;

                Comment


                  #23
                  You will need to debug your code.

                  For example,

                  if (Position.MarketPosition == MarketPosition.Long && Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit > 100)
                  ExitLong(
                  "lg");


                  - Can you confirm this "if" branch is entered?
                  - What's the value of "CumProfit" property etc... does it ever go above 100?
                  RayNinjaTrader Customer Service

                  Comment


                    #24
                    ending ninjascript

                    I have
                    CalculateOnBarClose =
                    false;
                    And I see the unrealized profit go above $100, so it seems it should exit and stop the strategy from running.

                    Comment


                      #25
                      CumProfit is realized PnL not unrealized. For unrealized, see Position.GetProfitLoss().

                      RayNinjaTrader Customer Service

                      Comment


                        #26
                        ending ninjascript

                        The results of closed trades do not seem to be moving into the realized column in Version 6.5?

                        Comment


                          #27
                          ending ninjascript

                          CumProfit is realized PnL not unrealized--
                          In order to stop running a strategy once accumulated profit has reached a certain target level, it would seem that unrealized p&L would need to be adding to or subtracting from the realized P&L while the strategy is in an open trade.
                          Is that what is supposed to be happening in the realized p&l column?
                          Thanks,
                          Jim

                          Comment


                            #28
                            An open trade is not "Realized" PnL since the trade is not closed. Only closed trades make up "Realized" PnL.
                            RayNinjaTrader Customer Service

                            Comment


                              #29
                              ending ninjascript

                              So is there coding that would allow me to check unrealized P&L plus realized p&L to see if a certain CumProfit has been attained in order to close open positions and stop the strategy from running?

                              Comment


                                #30
                                Add the CumProfit to the Position.GetProfitLoss().
                                RayNinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                673 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                379 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                111 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                578 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                582 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X