Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

tracking stragey positions after exit

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

    tracking stragey positions after exit

    I have set up a strategy that runs fairly frequently, and I want to set up a) Profit and Loss targets (easy to do) b) calculate post exit numbers, like the maximum onside the strategy would have been after 30mins.

    I was wondering if anyone had any ideas of how to track b) easily. I was setting dummy variables to calculated max price obtained after the strategy started, but I am running into problems if the strategy fires say twice in 30mins, then my dummy variable has to set and reset and the code starts to get messy and confusing.

    Any ideas would be greatly appreciated.

    #2
    eurostoxx,

    What sort of calculation are you attempting to do? Could you clarify?

    Are you looking for the maximum price that an instrument achieves or profit that trades achieve?

    I would be happy to give you my suggestions once I understand what you are trying to do.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply AdamP. I am trying to get both! The profit target (by setting a stop and profit order) and also what the max/min price will be after 30min of the strategy executing

      Currently I can get either one pretty easily, I'm just trying to figure out how to get both, without making the code overly complicated.

      I use a barcounter to the max/min after XX bars elapse. Or I use a EnterLong, set stop/profit target. The problem is that if I use a profit target, it might get filled before the barcounter is finished. Also, with using barcounter, if I want to get the max/min price say after 40min from entry, my strategy can only execute every 40mins, otherwise I have to figure out how to initialize/reset multiple barcounters ( which I can do, but my code is not pretty here). Just wondering if anyone had any ideas other than attaching an object of bar counters to each entry position (and even doing that I am not exactly sure how to do)

      Comment


        #4
        eurostoxx,

        I am not sure I totally understand what you are trying to do with your stop loss / take profit, but here is a suggestion for getting Max/Min price since the strategy first started running. You may want to swap out Close[0] in the two if statements for High[0] and Low[0] respectively, as Close[0] is not necessarily the highest or lowest price that was ever achieved. If you use "CalculateOnBarClose = False" then it should work just fine.

        Code:
        //Global variables 
        
        double maxPrice = 0;    //alternatively double.NegativeInfinity but price is never below 0.
        double minPrice = double.PositiveInfinity;
        
        
        protected override void OnBarUpdate()
        {
        
            if ( Close[0] > maxPrice )
            {
               maxPrice = Close[0];
            }
        
            if ( Close[0] < minPrice )
            {
               minPrice = Close[0];
            }
        
            //Other code
        }
        For your stop loss and take profit, are you trying to wait X number of bars until there is a stop loss and take profit on your order?

        Please let me know if I may assist further.
        Last edited by NinjaTrader_AdamP; 12-09-2011, 11:54 AM.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Adam, I have similar code right now that I am using. The problem I am encountering is that if I run the code you have now, I have to re-set the max/min price everytime the strategy enters a new order (otherwise, I will use a maxprice from a prior entry order). I do reset the variables on the entry order. The problem is that if I want to keep track of the max/min price AFTER the strategy is closed and perhaps a new entry is entered, I wont be able to.

          For example. At 8:30am, I generate an entry signal. EnterLong, reset counter, max/min variables, and start counting. At 8:35, my Stop /profit target is hit, my enteryorder is closed and I dont have a positoin. Then at 8:45, if I get another entry signal, I start the process again, enterlong, reset counter/max. But since I am resetting the counter max/min I havent let the bar counter reach 30 (assuming 1min bars)

          Comment


            #6
            eurostoxx,

            If you could outline exactly what you are trying to do in steps I could comment further. Unfortunately I am not sure what you are trying to use the Max/min for, and why you are counting 30 min intervals, especially if you are allowing it to enter orders inbetween the intervals. I would be happy to help out once I understand.

            From what I understand based on your responses, you may need to use 2 counters and 2 sets of Max/Min, then use whatever logic you need to identify which is most relevant to your strategy for the calculations you need.

            If you are resetting every time an order is open, I am not sure why you need to keep track of the max/min for the last 30 minutes. Vice verci, if you are only keeping track of the max/min for the last 30 minutes then why reset it when the strategy submits a new order? Could you please clarify?
            Last edited by NinjaTrader_AdamP; 12-09-2011, 12:45 PM.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Sure let me try to explain. Say I have a strategy that goes long on an MA cross

              if (OrderEntry_Conditions)
              {
              EnterLong()
              maxPrice = 0;
              minPrice = positive.infinity;
              counter = 0
              SetProfit & Stop Loss order
              }

              If ( market.position != market.position.flat)
              {
              counter++;
              maxPrice = Math.Max(High[0], maxPrice);
              min = ....
              }

              if (barcounter > 30)
              {
              ExitLong
              Print(Max Onside = maxOnside.ToString() .... );

              }

              OrderEntry_Conditions = if (EMA(2).Plot[0] > EMA(5).Plot[0] && Market.position==flat)

              I can run this code, but I will be limited to entering order only after 30mins have elapsed from the last entry order (that is when my positions are closed and therefore the second part of my OrderEntry_Conditions are true). I want to be able to keep track of the same variables, but be able to enter order say after 10mins from the last order entry. If I keep the same code, and simple remove the Market.Position == flat requirements, on each new entry, I will re-set max/min and counter so it messes stuff up from the prior entry order. Are you following.

              Meh, if not I will just make two strategies and combine them outside of NT, perhaps that might be easier

              Comment


                #8
                eurostoxx,

                I think I understand.

                So for each order you want to make sure its active for no more than 30 minutes, and meanwhile keep track of the highest and lowest prices achieved while this order was active.

                However, you want to be able to enter into more than 1 order at a time, so you must keep track of the highest/lowest price and number of bars for each unique order.

                My first thought is that you can create your own class that has a IOrder object, and int, and two doubles in it. You can create a queue of these objects, and iterate through them each OnBarUpdate() updating their BarTimes and Max/Min prices. Once one of the objects in the queue has a BarTimer > 30, you can close the order and remove it's associated object from the queue.

                The queue makes sense since orders are entered one after another, and if one order enters the queue before another, using your strategy for closing, it will always exit the queue first.

                I would recommend perhaps considering the unmanaged approach for this as I believe there will be limitations in the managed approach.

                Here is some information on queues : http://msdn.microsoft.com/en-us/libr...ons.queue.aspx

                Here is some information on making your own classes : http://msdn.microsoft.com/en-us/library/ms173109.aspx
                Last edited by NinjaTrader_AdamP; 12-09-2011, 02:37 PM.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Cheers... I was going to make my own class and store the max/min and barcounter, I was just hoping thier might be an easier way. Hopefully it isnt too much work. I just find when making classes with NT, it gets annoying having to pass all the references to the class (as I can't put Close[0] in my class, instead I have to pass it to the class)

                  But thanks for the tip on the cue... I probably would have used and arraylist, but cue is probably better. Thanks!

                  Comment


                    #10
                    eurostoxx,

                    This was the only way I could think of doing it that would be reliable short of using an array and max number of orders. If you never plan on using more then 5 orders lets say, you can get by with one 5 element int array, and two 5 element max/min arrays.

                    Another idea would be to store orders and use date-time objects to check if 30 minutes have elapsed since entry, then check each time what the min/max price between the opening date time and current date time is.

                    Perhaps someone else has another solution.
                    Last edited by NinjaTrader_AdamP; 12-09-2011, 04:57 PM.
                    Adam P.NinjaTrader 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
                    577 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