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 qwertyjjj, Today, 06:52 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by NeverDownMoney, 09-25-2020, 09:40 PM
            1 response
            13 views
            0 likes
            Last Post NT-Roland  
            Started by wjadevries, Today, 04:21 AM
            1 response
            10 views
            0 likes
            Last Post wjadevries  
            Started by butt_toast, Yesterday, 01:16 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by jjanguda, 12-22-2017, 10:37 AM
            3 responses
            910 views
            0 likes
            Last Post NinjaTrader_Jason  
            Working...
            X