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

Trying to figure out how to change Aroon period based on number of crosses

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

    Trying to figure out how to change Aroon period based on number of crosses

    Hi,
    I have a strategy that is based on the Aroon indicator.

    In general, an entry is considered when Green plot crosses above Red plot.

    Problem is, in some occasions when the instrument is range bound and goes sideways, there are too many false posivtives.

    I want to be able to change the period of Aroon to a higher one in the event that there were more than x crosses in x amount of time.

    Then I will optimize both variables.

    I am thinking of adding a Variable1 = 0 ...however I can't figure out how to put formula for the cross counting.

    Any input would be greatly appreciated!

    #2
    Hello Nikolaalx,

    Thank you for your post.

    You would want to create Aroon Indicator objects that you can adjust the values for.

    Example -
    Code:
    private Aroon myAroon1;
    private Aroon myAroon2;
    
    //In OnStartUp()
    myAroon1 = Aroon(14);
    myAroon2 = Aroon(20);
    You can then in your script when you get that scenario to use the higher Aroon values.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thanks.

      I was refraining more to the counting script.

      E.g. Whenever there is an entry in addition to the EnterShort/Long to have a count +1

      And then to be able to reset the counter based on a time range and/or other criteria.

      Do you have any idea how I can do that?

      Comment


        #4
        nikolaalx,

        Apologies.

        With the counter then you would want to create a INT variable and then have the condition that counts it -
        Code:
        private int counter = 0;
        
        if(your cross condition here)
        counter++;
        
        if(counter == x)
        {
        //Perform switch here.
        }
        You would then just need to create another condition that you would use to reset your variables.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Hi,
          sorry for the dumb question, but If I understood properly the ++; can be applied to any integer in the script? And "counter" is just the name for that integer?

          If this is so, then substracting would be --; I assume?




          Also how can I restart that counter based on time since entry. E.g. If time since previous entry > x , counter to be restarted.

          This way I can change the x for the restart to a variable and optimize (and be able to test if the whole thing would actually work).

          Thanks.
          Last edited by nikolaalx; 08-11-2014, 11:44 AM.

          Comment


            #6
            Hello nikolaalx,

            Thank you for the questions I will be happy to help.

            You are correct, when you have a integer value you can use ++ or -- to add or subtract 1 each time it is called.

            As for your time related question there are a few factors with this.

            Do you want to compare the entry time to the current computer clock or to bar timestamps?
            Also you would need to store the time of when your entry happens,

            Here is a simple example of storing the value and then comparing it between 2 times.
            I have pre set the value for entryTime so that you can see how the integer time works. When you use ToTime it converts a DateTime into an int, so 9:00:00 turns into 90000 so you can use it in an if statement.

            This checks if the current pc clock is greater than 10:00am and the initial entry was 9:00am
            Code:
            private int entryTime = 90000; // 9 am
            protected override void OnBarUpdate()
            {
                 if(your cross condition here)
                 {
            	entryTime = ToTime(DateTime.Now);
                 }
            
                 if(ToTime(DateTime.Now) > entryTime + 10000) // add 1 hour to entrytime
            	{
            		//do whatever happens after the time is up
            	}
            }
            There are various other ways to check a time, here are some help guide resources for you

            For the PC clock time, you would need DateTime.Now there is more inforation on how to use DateTime objects in C# here: http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx

            For information regarding Bar Times, please see this document: http://www.ninjatrader.com/support/h....html?time.htm

            Also you can convert DateTimes into integers from NinjaScript allowing you to compare values easy, here is that method:


            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by geddyisodin, Yesterday, 05:20 AM
            7 responses
            45 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by gbourque, Today, 06:39 AM
            2 responses
            5 views
            0 likes
            Last Post gbourque  
            Started by cre8able, Yesterday, 07:24 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by cocoescala, 10-12-2018, 11:02 PM
            6 responses
            939 views
            0 likes
            Last Post Jquiroz1975  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            1 response
            17 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X