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 benmarkal, Yesterday, 12:52 PM
            3 responses
            22 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by helpwanted, Today, 03:06 AM
            1 response
            17 views
            0 likes
            Last Post sarafuenonly123  
            Started by Brevo, Today, 01:45 AM
            0 responses
            11 views
            0 likes
            Last Post Brevo
            by Brevo
             
            Started by aussugardefender, Today, 01:07 AM
            0 responses
            6 views
            0 likes
            Last Post aussugardefender  
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            244 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Working...
            X