Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trade Outcome History and First Friday of Month

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

    Trade Outcome History and First Friday of Month

    Two questions:

    1) I would like to be able to output the outcome of the trade history (historical and live) so as to output 1 if the trade was positive and -1 if the trade was negative. So the output file would look something like 1 1 1 1 1 -1 -1 -1 1 1 -1 -1 . . . What is the best way to implement this? I looked at the Sample PNL strategy and other trade data values but did not find this type of idea anywhere.

    2) How would I code the first friday of the month? I understand code such as if (Time[0].DayOfWeek == DayOfWeek.Friday) will show true if it is Friday but how to decipher if it is the first Friday of a month?

    Cheers!

    GT

    #2
    Hi GT,

    1) This is possible working with our trade collection, but you may need some experience working with collections or loops to go through all the available data and send out what you want. You can see a couple examples of this on this page:


    2) The cleanest way I could think of for this is to test the day value at the same time:
    Code:
    if(Time[0].DayOfWeek == DayOfWeek.Friday && Time[0].Day <= 7)
    {
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      OK, I am good on the first Friday of the month, thanks!

      For the trade history, the only thing I need to know if how to tell if it is a new trade so I am only looking for the outcome for a new trades and not the last trade on each bar update. If using the last trade there can be many bars showing the same last trade outcome where I only want to count the outcome for each trade. Is there a way to do this?

      Cheers!

      GT

      Comment


        #4
        Hi GT,

        For this you can capture the count value in your own variable, and then only print or access when count is higher than your captured value.

        Initialize as -1 in Variables region:
        Code:
        #region Variables
        private int 	myCount = -1;
        #endregion
        Access in OnBarUpdate like this:

        Code:
        if (Performance.AllTrades.Count > myCount)
        {
        //accessStatistics here
        myCount = Performance.AllTrades.Count;
        }
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          OK, got it except for how do I program if myCount is great than myCount of a bar ago. Not sure how to compare vars like this.

          GT

          Comment


            #6
            That's what the snippet essentially does -- Only accesses TradePerformance when there's been a new trade.

            Comparing one bar ago seems like a different implementation for the same solution. If you wanted to do this, would need to turn myCount into an IntSeries to reference its prior bar values.

            This sample can help with custom DataSeries. It's identical structure but IntSeries instead:
            Last edited by NinjaTrader_RyanM1; 02-06-2012, 04:32 PM.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

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