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

Time Limit for 2nd condition

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

    Time Limit for 2nd condition

    Hello,

    i'm trying to build an indicator that will give me a signal if CCI
    1. moves from 100 to -100
    2. within 3 candles.

    how do i have to add this second condition?

    thanks a lot!!
    Last edited by Tradexxx; 03-09-2016, 10:09 AM.

    #2
    Hello Tradexxx,

    We have received your inquiry and will look into this further to provide you direction with your request.
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      Hello Tradexxx,

      Thank you for your patience.

      Below is the code for your needed condition.
      Code:
              #region Variables
      		private int period = 20;
              #endregion
      
              protected override void Initialize()
              {
                  Overlay				= true;
              }
      
              
              protected override void OnBarUpdate()
              {
      			if (CurrentBar <= period)
      				return;
      			
                  int positive = period;
      			int negative = period;
      			
      			for (int i = period-1; i > 0; i--)
      			{
      				if (CCI(period)[i] >= 100)
      				{
      					positive = i;
      				}
      			}
      			for (int i = positive-1; i > 0; i--)
      			{
      				if (CCI(period)[i] <= -100)
      					negative = i;
      			}
      			
      			if (positive != period && negative != period)
      			{
      				DrawArrowDown("negative", negative, Low[negative] - 2 * TickSize, Color.Red);
      				DrawArrowUp("positive", positive, High[positive] + 2 * TickSize, Color.Green);
      			}
              }

      Comment


        #4
        thanks patrickh

        i'm looking forward to use it

        Comment


          #5
          I set the period to 20 by the way and passed that as the period of the CCI. So you may wish to set period to 3 and set the CCI period to something else. Just a FYI.

          Comment


            #6
            patrickh,
            looks like i need your help again:

            1.) the signal only appears once in a chart - even if the event (crossing from 100 to -100 in between 3 candles appears more often) -- how can this be changed?

            2.) i have set "period" to 3 (to fullfill the condition and changed the priod of the CCI to 14)

            3.) is there a possibility to include these two paramters ( "3" for the 'period" and the setting "14" for the 'CCI' into the indicator window (to change the settings more easily)?

            i assume it's something pretty easy, but i don't have the experience.....
            if you want, i can attach the indicator.
            thanks a lot

            Comment


              #7
              Hello Tradexxx,

              Thank you for your response.

              1. Change the "tag" string to something like the following:
              Code:
              				DrawArrowDown("negative " + CurrentBar, negative, Low[negative] - 2 * TickSize, Color.Red);
              				DrawArrowUp("positive " + CurrentBar, positive, High[positive] + 2 * TickSize, Color.Green);
              2. Great!
              3. You would need to implement user defined parameters. Please take a look at our information at the following link: http://ninjatrader.com/support/forum...ead.php?t=5782

              Please let me know if you have any questions.

              Comment


                #8
                hi patrickh,

                what could be the reason, that not all possible signals (within the given period) are displayed ?
                thx

                Comment


                  #9
                  Tradexxx,

                  In the case of my code I provided it is only looking for the above and then below condition.

                  Can you attach a screenshot of the chart with the indicator not showing signals you would like to see?

                  Comment


                    #10
                    hi patrickh,

                    attached 2 screenshots.

                    A is with setting period to 4 ( no signals are shown in this example, but there are signals with the same condition)
                    B is with setting period to 5 (than you have the missing signals also)

                    (btw: as i just want to see the entry signal, i have faded out the second signal)
                    Attached Files
                    Last edited by Tradexxx; 03-15-2016, 07:44 AM.

                    Comment


                      #11
                      Tradexxx,

                      May I test the full script you are running?
                      You can attach your indicator to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your Indicator > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.

                      Comment


                        #12
                        attached the indi
                        Attached Files

                        Comment


                          #13
                          Try the attached version and let me know if this is the behavior you are looking for.
                          Attached Files

                          Comment


                            #14
                            hi patrickh,

                            thanks for your assistance.
                            the new one displays each cross.

                            well, the starting condition was:

                            one signal, if
                            1. CCI crosses from +100 to -100
                            and
                            2. the cross from +100 to -100 should be within 3 candles.

                            So, the first indicator solution was ok, except it wasn't working at all times when there was a cross within 3 candles. sometimes it worked, sometimes not.

                            Comment


                              #15
                              Tradexxx,

                              Have you tried out a few conditions or alterations to the code on your end?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by helpwanted, Today, 03:06 AM
                              1 response
                              7 views
                              0 likes
                              Last Post sarafuenonly123  
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by aussugardefender, Today, 01:07 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post aussugardefender  
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              242 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              9 responses
                              385 views
                              1 like
                              Last Post Gavini
                              by Gavini
                               
                              Working...
                              X