Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            7 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            6 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            3 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Started by GwFutures1988, Today, 02:48 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X