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

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 Vikuno1, 11-28-2023, 11:42 PM
                                15 responses
                                357 views
                                1 like
                                Last Post PaulMohn  
                                Started by PaulMohn, Yesterday, 02:06 AM
                                3 responses
                                12 views
                                0 likes
                                Last Post PaulMohn  
                                Started by gertrudeabrams, Today, 12:33 AM
                                0 responses
                                3 views
                                0 likes
                                Last Post gertrudeabrams  
                                Started by NJA_MC, 01-03-2021, 10:34 PM
                                11 responses
                                150 views
                                0 likes
                                Last Post wzgy0920  
                                Started by sidlercom80, 10-28-2023, 08:49 AM
                                173 responses
                                2,367 views
                                0 likes
                                Last Post jeronymite  
                                Working...
                                X