Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Prior Trade Date

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

    Prior Trade Date

    Hi,

    I'm trying to build a filter into my strategy that will stop trading during the current month after xx number of losses. I know how to access the current month using DateTime. My thought was to use a counter for losses during the current month. I need to figure out a way to reset the counter.

    Since the first day of the month isn't always a market day, I thought I might be able to just count trades which have a trade date in the current month.

    Any thoughts on the best way to accomplish this?

    Thanks,

    Rich

    #2
    Hi Rich, for backtesting the work needed to be done would need to be more involved as you have to setup custom tracking for example in a list / method of holidays influencing the first business day of month tracking via C#. For generally determining business days, those methods published should come in handy - http://businessdaysfunc.blogspot.de/

    For currently trading the strategy you could setup a user input simply that would let you set when to do the counter reset in your code.

    Comment


      #3
      Is there any way to access the trade date of the last 2 trades? I could compare them and if the months were different, then I could reset the counter.

      Comment


        #4
        Why not:
        if (Time[0].Day < Time[1].Day) reset..

        Comment


          #5
          Originally posted by richp6 View Post
          Is there any way to access the trade date of the last 2 trades? I could compare them and if the months were different, then I could reset the counter.
          Yes, you could access the entry / exit times from the Performance class for a comparison as well - http://www.ninjatrader.com/support/h.../nt7/trade.htm

          Comment


            #6
            I understand how I can access the order information for a trade that happens in real-time, but how would I access the trade information for the past 2 trades?

            Comment


              #7
              Hi richp6,

              Trades are put into a collection. The last two trades will be at index position Count - 1 and Count. This sample can help you work with this collection:


              Here's a useful comment from this sample that may help here:
              /* The Performance.AllTrades array stores the most recent trade at the highest index value. If there are a total of 10 trades, this loop will retreive the 10th trade first (at index position 9), then the 9th trade (at 8), then the 8th trade. */
              Last edited by NinjaTrader_RyanM1; 04-14-2012, 06:53 PM.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Thanks for your help. I got it working, and I thought I would share the code in case anyone else was interested.

                for (int idx = Math.Min(Performance.AllTrades.Count, 10); idx >= 1; idx--)
                {
                Trade trade = Performance.AllTrades[Performance.AllTrades.Count - idx];
                trade_profit = trade_profit + trade.ProfitCurrency;
                if (trade.Entry.Time.Month != Time[0].Month)
                {
                trade_counter = 0;
                trade_profit = 0;
                }
                Print("trade profit is " + trade_profit.ToString());
                if (trade.Entry.Time.Month == Time[0].Month && trade.ProfitCurrency < 0)
                {
                trade_counter++;
                Print("trade counter is " + trade_counter.ToString());
                }
                }

                Then for my disqualifier I used:

                if(trade_counter >= maxlosscount && trade_profit < maxloss)
                {
                Print("Maximum Loss for the current month has been reached");
                return;
                }

                Rich
                tradethepulse.com

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                659 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                374 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                110 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                574 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                579 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X