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 rwlink3z8, Today, 06:17 PM
                                0 responses
                                2 views
                                0 likes
                                Last Post rwlink3z8  
                                Started by diegomezhur, Today, 05:33 PM
                                0 responses
                                2 views
                                0 likes
                                Last Post diegomezhur  
                                Started by amichalska, Today, 01:23 PM
                                2 responses
                                14 views
                                0 likes
                                Last Post amichalska  
                                Started by GreyKerns09, Today, 03:42 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post GreyKerns09  
                                Started by PrTester, 12-29-2008, 05:27 PM
                                133 responses
                                96,731 views
                                0 likes
                                Last Post aligator  
                                Working...
                                X