• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Returning lowest value out of x values

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

    Returning lowest value out of x values

    Hi,

    I am trying to gauge what kind of underwater drawdowns (drawdowns on open positions, or drawdown on unrealized profit/loss) I may experience while running my strategy. For this I have made an indicator and an output to Excel, this seems to be working fine. What I need help with, is figuring out how I can return the lowest value out of x number of values.

    Basically what I see on my underwater drawdown 'indicator' is a string of numbers like this:
    0, -2,-5,-9, -21, 0. The numbers representing the entry of a position and how it currently moves against me. Now what I need is to somehow return the lowest value out of those values.

    This is currently how my underwater drawdown code looks like:

    Code:
    // Underwater Drawdown
                                    UDD = 0; // Underwater drawdown
    				// Long Underwater Drawdown
    			if (Position.MarketPosition == MarketPosition.Long){
    				if (Open[BarsSinceEntry()] > GetCurrentAsk())
    				UDD = GetCurrentAsk() - Open[BarsSinceEntry()];
    				else
    				UDD = 0;}
    				// Short Underwater Drawdown
    			if (Position.MarketPosition == MarketPosition.Short){
    				if (Open[BarsSinceEntry()] < GetCurrentBid())
    				UDD = Open[BarsSinceEntry()] - GetCurrentBid();
    				else 
    				UDD = 0;}
    I have thought of placing the values into an array and then return the lowest value from there, however, I didn't get it to work. Anyone have any ideas on how I can do this?

    #2
    Hello Stoop,

    You may use the MIN() method that will return the lowest value over a specified period from a Data Series.

    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by Stoop View Post
      Hi,

      I am trying to gauge what kind of underwater drawdowns (drawdowns on open positions, or drawdown on unrealized profit/loss) I may experience while running my strategy. For this I have made an indicator and an output to Excel, this seems to be working fine. What I need help with, is figuring out how I can return the lowest value out of x number of values.

      Basically what I see on my underwater drawdown 'indicator' is a string of numbers like this:
      0, -2,-5,-9, -21, 0. The numbers representing the entry of a position and how it currently moves against me. Now what I need is to somehow return the lowest value out of those values.

      This is currently how my underwater drawdown code looks like:

      Code:
      // Underwater Drawdown
                                      UDD = 0; // Underwater drawdown
                      // Long Underwater Drawdown
                  if (Position.MarketPosition == MarketPosition.Long){
                      if (Open[BarsSinceEntry()] > GetCurrentAsk())
                      UDD = GetCurrentAsk() - Open[BarsSinceEntry()];
                      else
                      UDD = 0;}
                      // Short Underwater Drawdown
                  if (Position.MarketPosition == MarketPosition.Short){
                      if (Open[BarsSinceEntry()] < GetCurrentBid())
                      UDD = Open[BarsSinceEntry()] - GetCurrentBid();
                      else 
                      UDD = 0;}
      I have thought of placing the values into an array and then return the lowest value from there, however, I didn't get it to work. Anyone have any ideas on how I can do this?
      Make UDD a class variable, so that it will persist over updates, then use:
      Code:
       
      UDD = Math.Min(UDD, GetCurrentAsk() - Open[BarsSinceEntry()]);
      for longs, and
      Code:
       
      UDD = Math.Min(UDD, Open[BarsSinceEntry()] - GetCurrentBid());
      for shorts.

      Comment


        #4
        Thanks a lot, that's very helpful. How would I make UDD into a class variable? I tried
        following tutorials about class variables, but I can't seem to get it to work. Just some pointers would be really nice.

        Comment


          #5
          Originally posted by Stoop View Post
          Thanks a lot, that's very helpful. How would I make UDD into a class variable? I tried
          following tutorials about class variables, but I can't seem to get it to work. Just some pointers would be really nice.
          Simplest way is to add it to the Variables section, following the format. In this case,
          Code:
           
          private double UDD = 0;
          should do it.

          Comment


            #6
            Oh, I see. I thought you wanted me to create a new class. I will get it working now then! Again, thanks a lot for your help, it's appreciated.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ralett, Today, 07:29 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Marco  
            Started by bboyle1234, Today, 10:46 PM
            0 responses
            1 view
            0 likes
            Last Post bboyle1234  
            Started by swcooke, Today, 04:29 PM
            0 responses
            4 views
            0 likes
            Last Post swcooke
            by swcooke
             
            Started by bboyle1234, Today, 04:27 PM
            0 responses
            2 views
            0 likes
            Last Post bboyle1234  
            Started by swcooke, Today, 03:31 PM
            2 responses
            11 views
            0 likes
            Last Post swcooke
            by swcooke
             
            Working...
            X