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

Determining if a stop would have been hit?

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

    Determining if a stop would have been hit?

    Hello community,

    i like to accomplish the following with ninjascript as an indicator:

    Look back for a given PERIOD if the LOW would have hit the VALUE of my stop.
    If yes, adjust the multiplier MULT+1 and try again, until the stop was never hit by a low in the given period.

    Can anybody point me to the right direction? I'd like to have this running in Market Analyzer, so it can provide an optimal multiplier for my stop.

    #2
    Hello puravida,

    Thank you for your post.

    What is the Mult+1 applied to? The Stop Value, Low, or Period?

    I look forward to your response.

    Comment


      #3
      Hi and thanks for the response.

      It should be added to the multiplier for the stop value, which is derived from the ATR of the period.

      something like:
      double MULT = 1.0; // start with 1.0, raise 0.1 steps
      double VALUE = ATR(period)[0] * MULT;

      // no get through all Lows in the given period, calculate the stop and check if
      // it would have been hit. if yes, raise the MULT + 0.1 and run again.

      Comment


        #4
        Hello puravida,

        Thank you for your response.

        The following checks the lows of the look back period (period) to see if the stop value equals the low, if not then it prints that it is not equal. If true it adds 0.1 to the mult.
        Code:
        			if(CurrentBar < 20)
        				return;
        			
        			int period = 20;
        			double mult = 1.0;
        			
        			for(int i = 0; i <= period; i++)
        			{
        				double stop = ATR(period)[0] * mult;
        				Print("Stop value is " + stop);
        				if(Low[i] == stop)
        				{
        					mult = mult + 0.1;
        					Print("Mult is " + mult);
        				}
        				else
        					Print(Low[i] + " does not equal " + stop);
        			}
        However, this never returns true in my tests on the ES 06-13.
        My Output returns the following throughout the test:
        ...Stop value is 16.0406140988393
        1549 does not equal 16.0406140988393
        Stop value is 16.0406140988393
        1549 does not equal 16.0406140988393
        Stop value is 16.0406140988393
        1542.25 does not equal 16.0406140988393...
        Please let me know if this is what you are looking for or if you have any comments here.

        Comment


          #5
          Hi!

          first, thanks for you help i really appreciate it.

          It is not exactly what i was looking for, so i try to make myself more clear (sorry for this).

          I am using an ATR trailing stop, usualy with a multiplier of about 2.5 (ATR(period)[0] * MULT). What i like to know: What would have been the optimal MULT for the given period, if i assume i would have bought the stock at the beginning of the period and trailed it until today. The stops should be derived from the tightest MULT that did not get stopped out by getting hit by a daily Low until today.

          Sample1 shows the chart for a multiplier that was hit 6 days ago, after manual adjustment i get sample2 which is what i want the indicator to do.

          Another way to say it:
          The indicator should do the calculations and tell you what minimal ATR multiplier band will contain 100% of prices in a given period. So it is the "smallest MULT that was not stopped out" i am looking for.
          Attached Files
          Last edited by puravida; 04-14-2013, 04:08 PM.

          Comment


            #6
            Hello puravida,

            Thank you for your response.

            Using MRO (most recent occurrence) you can check to see if any of the Lows over the look back period were less than or equal to the Stop, if so you can add 0.1 to the multiplier and then run the MRO again.

            For example:
            Code:
                    #region Variables
            		private bool runAgain = true;
            		private int period = 20;
            		private double mult = 1.0;
            		private double stop = 0;
            		private int barsAgo = 0;
                    #endregion
            
                    protected override void Initialize()
            		{
            			
            		}
            
                   
                    protected override void OnBarUpdate()
                    {
            			stop = ATR(period)[0] * mult;
            			
            			if(runAgain)
            			{
            				barsAgo = MRO(delegate {return Low[0] <= stop;}, 1, period);
            			}
            			
            			if (barsAgo > -1)
            			{
            				mult = mult + 0.1;
            				runAgain = true;
            			}
            			else if (barsAgo == -1)
            			{
            				runAgain = false;
            			}
            			
            		}
            For information on MRO please visit the following link: http://www.ninjatrader.com/support/h...urence_mro.htm

            Please let me know if I may be of further assistance.

            Comment


              #7
              Thanks a lot, works for me.

              I wasn't aware of the MRO method, neat feature

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by DanielTynera, Today, 01:14 AM
              0 responses
              2 views
              0 likes
              Last Post DanielTynera  
              Started by yertle, 04-18-2024, 08:38 AM
              9 responses
              40 views
              0 likes
              Last Post yertle
              by yertle
               
              Started by techgetgame, Yesterday, 11:42 PM
              0 responses
              12 views
              0 likes
              Last Post techgetgame  
              Started by sephichapdson, Yesterday, 11:36 PM
              0 responses
              2 views
              0 likes
              Last Post sephichapdson  
              Started by bortz, 11-06-2023, 08:04 AM
              47 responses
              1,615 views
              0 likes
              Last Post aligator  
              Working...
              X