Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to stop a strategy after a daily profit target is reached.

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

    How to stop a strategy after a daily profit target is reached.

    Is there a way to stop a trading strategy after a daily profit target is reached. For instance after 4 ticks/$$$/%. I know there is one for each individual trade, but what about for a daily limits?

    Thanks. I will continue to search in the help section to see if its in there.

    #2
    Hello olingerc,

    For this you can work with Trade Performance class and reset values for each day.

    This sample is pretty close to what you're looking for:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Is there anthing in the code to check for "Maximum favorable Excursion" value? that is basically the value I am looking for. I will check out the link to see if I can get what I desire. Thanks.

      Comment


        #4
        I extracted the correct part of the code but when I compile I get this error "priorTradesCount" wherever priortrades" is mentioned it says "does not exist in current context" I imagine in NT 6.5 this existed? What is the equivalent for NT7?

        Thanks

        Comment


          #5
          You should be able to import that sample in either version. It sounds like you are missing the variable declaration.

          #region Variables
          private int priorTradesCount = 0;
          private double priorTradesCumProfit = 0;
          #endregion

          You can custom code MFE if you want it calculated while you're in a trade:

          Understanding Average MFE
          Where MFE (max. favorable excursion) is defined as (best price trade reached – entry price), quantity is defined as the number of contracts traded, and point value is defined as the monetary conversion of each point (e.g. 100 for currency pairs).

          Example with long position:
          if (Position.MarketPosition == MarketPosition.Long)
          myDouble = High[BarsSinceEntry()] - Position.AvgPrice;
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Ryan I am having trouble with this till. I believe I have the correct code in the correct location but during a back test it does not calculate. I can set the profit target to lets say 10,000 and during a back test it will only test up to 10,000 and nothing after. or if its 1000 it would test until a profit of 1,000 is met and nothing after. Why is this so? If I set it to RealtimeTrades would it only calculate the current day's live account information?

            How do I get my strategy to exit during the intraday after lets say a profit of 1,000 is reached.
            This is what I have so far
            // At the start of a new session
            if (Bars.FirstBarOfSession)
            {
            // Store the strategy's prior cumulated realized profit and number of trades
            priorTradesCount = Performance.AllTrades.Count;
            priorTradesCumProfit Performance.AllTrades.TradesPerformance.Currency.C umProfit;

            // NOTE: Using .AllTrades will include both historical virtual trades as well as real-time trades.
            //If you want to only count profits from real-time trades please use .RealtimeTrades.
            }

            //Prevents further trading if the current session's realized profit exceeds $1000

            if (Performance.AllTrades.TradesPerformance.Currency. CumProfit - priorTradesCumProfit >= 1000)
            {
            //TIP FOR EXPERIENCED CODERS: This only prevents trade logic in the context of the OnBarUpdate() method. If you are utilizing
            other methods like OnOrderUpdate() or OnMarketData() you will need to insert this code segment there as well.

            // Returns out of the OnBarUpdate() method. This prevents any further evaluation of trade logic in the OnBarUpdate() method.
            return;
            }
            Last edited by olingerc; 05-06-2011, 03:03 PM.

            Comment


              #7
              Code looks OK and I don't see where you are deviating from the sample at all. just ran the sample here and it's working as expected. You have more than one session, right?

              In a backtest there are no real time trades so that won't work for you. Attach the script (exported zip file) you're using and screenshots of your backtest setup and will give it a run here.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Yes I was having issues with the back testing. No changes were showing up during a back test. Assuming I change it to RealtimeTrades it would actually work live during a intraday cession. But unfortunately if I cant back test this then I am not willing to spend months of playing around with a live account only to realize that I would of made more money if I just hadn't done it to begin with.

                Comment


                  #9
                  I know this is an old thread, but in case anyone else comes along...

                  IncludeTradeHistoryInBacktest = true;

                  That should fix the issue OP was experiencing.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by The_Sec, Today, 02:29 PM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  2 responses
                  30 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by Mindset, 05-06-2023, 09:03 PM
                  10 responses
                  265 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by michi08, 10-05-2018, 09:31 AM
                  5 responses
                  743 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by tsantospinto, 04-12-2024, 07:04 PM
                  4 responses
                  63 views
                  0 likes
                  Last Post aligator  
                  Working...
                  X