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

Comparing variable to its own prior value

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

    Comparing variable to its own prior value

    I have an indicator - v basic - where I put my entry and stop price as inputs and then text is placed on the chart with a live update of the points I have made/lost. the variable is called mp but how do I get hold of the maximum fav excursion of this variable?

    Seems a simple enough thing but I am stumped.

    I can't seem to use Math.Max(mp,mp[1]) or Highest(mp,x).

    Code:
    			
    }
    protected override void OnBarUpdate()
    {	
    if (CurrentBar < 2) return;
    				
    			
    	double mp= 0;
    	double maxmp = 0;
    	double temp = 0;
    				
    
    if( EP > Stp )// long
    {
    mp = High[0] - EP;
    temp = High[1] - EP;
    maxmp = Math.Max(mp,temp);[COLOR="Red"]//**** only compares last 2 values[/COLOR]
    }
    else
    {	
    mp = EP - Low[0]; 
    temp = EP - Low[1];
    maxmp = Math.Max(mp,temp);
    }
    
    					
    string mystr =mp.ToString("N2")+ " / " + maxmp.ToString("N2");
    DrawText("tag", false, "    <  "+ mystr, 0, Close[0],Color.Blue,  new Font("Verdana Ref", 9), StringAlignment.Near, Color.Transparent, Color.Transparent, 50);
    				
    		
    			
    }
    Last edited by Mindset; 10-29-2008, 07:13 AM. Reason: spelling

    #2
    Hello,

    Insert:
    Print(mp + " is mp");
    Print(temp + " is temp");

    Right before:
    maxmp = Math.Max(mp,temp);

    To see what values are being used. You can see this in Tools>Output window.

    I also suggest using TradesPerformanceValues class to get AvgMfe. This link will help:
    DenNinjaTrader Customer Service

    Comment


      #3
      Yes as a strategy there are lots of things I can do but it's the principle of how I get a max fav excursion from an inputted price. I might well use this idea in concepts like Boll Band excursion, etc

      So, I just want the code to give me a live readout and "hold" in a separate variable/dataseries the max value it's hit since the price was input.
      Does that make sense?

      The live readout is done - its's simply the max value I can't work out.

      In my sample code I don't mind having the live readout as...

      10/ 14 Ie currently at 10 pts profit with the highest points profit so far being 14.

      Edit - In Easy language I would do something like this
      Temp = Maxlist(temp[1], High[0] - EP);
      Last edited by Mindset; 10-29-2008, 09:18 AM.

      Comment


        #4
        Hello,


        I understand what you are looking for. I don't know exactly what your calculations and values are but try something like this:

        mp = High[0] - EP;

        maxmp = Math.Max(mp,temp);

        if(maxmp > temp)
        {
        temp = maxmp;
        }

        Then use maxmp as your max value, mp is your current value for that tick and temp is just a temporary value used to hold the last max value. This code is not test, so test it first.
        DenNinjaTrader Customer Service

        Comment


          #5
          Intrabar vs interbar

          Ok that measures max excursion intrabar but it doesn't hold the max value from the prior bars (if any) - it resets itself.

          The calculation is as follows

          Entry = 10
          Current price = 20
          Highest price so far = 25

          Display should read < 10 (Current points) / 15 (max points so far)

          Code:
          }
          protected override void OnBarUpdate()
          {	
          if (CurrentBar < 2) return;
          					
          			
          double mp= 0;
          double temp = 0;
          double actual = 0;
          			
          				
          
          if( EP > Stp )// long
          {	
          mp = High[0] - EP;
          actual = Close[0] - EP;	
          						
          }	
          else
          {
          mp = EP - Low[0]; 
          actual = EP - Close[0];
          }
          double maxmp = Math.Max(actual,mp);
          				
          if(maxmp > temp)
          {
          temp = maxmp;
          }
          string mystr = actual.ToString("N2")+ "Temp " + temp.ToString("N2") +" Max " + maxmp.ToString("N2");
          DrawText("tag", false, "    <  "+ mystr, 0, Close[0],Color.Blue,  new Font("Verdana Ref", 9), StringAlignment.Near, Color.Transparent, Color.Transparent, 50);
          			
          		
          }
          Last edited by Mindset; 10-29-2008, 11:38 AM.

          Comment


            #6
            Hello,


            You can always store indexable values in a DataSeries. This link will help:


            That way you can reference the values later.
            DenNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by rtwave, 04-12-2024, 09:30 AM
            5 responses
            37 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by funk10101, Today, 12:02 AM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by GLFX005, Today, 03:23 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by nandhumca, Yesterday, 03:41 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by The_Sec, Yesterday, 03:37 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X