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

strategy to determine occurences of DAILY high and low prices

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

    strategy to determine occurences of DAILY high and low prices

    Hi All,
    I am trying to write a simple strategy or indicator where I want to count the number of times the DAILY high/low closed at certain prices over the last 14(x) number of days e.g.

    HIGHs
    2601 - 3 times
    2600 - 6 times
    2595 - 5 times

    LOWs
    2533 - 4 times
    2527 - 5 times
    2520 - 5 times

    This can on DAILY bars, but technically could be any bar 5 min, 30 min etc too

    If someone has come across something like this before or has done it themselves, would appreciate pointing me in the right direction.

    Thanks,

    #2
    Hello SuperDriveGuy,

    Thanks for the note.

    You can use a loop to iterate through historical bars as your indicator/strategy runs.

    Please see this indicator tutorial that demonstrates how to implement an SMA indicator:



    To count the number of occurrences, you can do something like the following:

    Code:
    int sum = 0; 
    double threshold = 9999.99;
    for (int barsAgo = 0; barsAgo < Period; barsAgo++) 
    { 
       if(Close[barsAgo] >= threshold)
       {
           ++sum;
       }
    }
    If you do not need to constantly check for this condition in real time, you can just check this condition as the indicator or strategy runs through all of the historical bars of the chart when you start up the script.

    Code:
    		int High2601 = 0;
    		int High2600 = 0;
    		//...
    	protected override void OnBarUpdate()
            {
                if(Historical)
    			{
    				switch (Close[0])
    				{
    					case 2601:
    						++High2601;
    						break;
    						
    					case 2600:
    						++High2600;
    						break;
    					//...
    				}
    			}
    ...
    Below are links to all the material used here.

    https://docs.microsoft.com/en-us/dot...e/keywords/for - For loop

    https://docs.microsoft.com/en-us/dot...eywords/switch - Switch statement

    https://ninjatrader.com/support/help...historical.htm - The Historical property

    This page describes the difference between historical and real-time data:


    Please let us know if you have any questions.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,
      Thanks for the quick and helpful response.

      I am indeed looking to collect these statistics on historical data and so the historical example is very useful.

      As far as the case example is concerned, I think, the example I gave was misleading I don't have the numbers in mind before 2600, 2601 etc, those would depend on the instrument. The occurences would need to be picked from the within the data itself.

      example output for FDAX would look something like..
      HIGHs
      12600 - 5 times
      12590 - 1 times

      LOWs
      12400 - 4 times
      12390 - 1 time

      Thanks

      Comment


        #4
        Hi Chris,
        Whilst researching, I came across https://msdn.microsoft.com/en-us/lib....aspx#Examples

        Do you think, I can use this to store the Highs and Lows and then perform a count of the keys? is that possible?

        Thanks

        Comment


          #5
          Hello SuperDriveGuy,

          Thanks for the reply.

          That is correct, a dictionary would be the ideal structure to use if you wanted to store values as they come in.

          A good demonstration of this is the Volume Profile indicator. While that indicator only works in real time, you can gain some insight from the Dictionary that it uses to store arbitrary price values.

          If we may be of any further assistance, please let us know.
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Thanks Chris.

            Very helpful. I am having a look.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by guillembm, Yesterday, 11:25 AM
            2 responses
            9 views
            0 likes
            Last Post guillembm  
            Started by junkone, 04-21-2024, 07:17 AM
            9 responses
            68 views
            0 likes
            Last Post jeronymite  
            Started by trilliantrader, 04-18-2024, 08:16 AM
            4 responses
            18 views
            0 likes
            Last Post trilliantrader  
            Started by mgco4you, Yesterday, 09:46 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by wzgy0920, Yesterday, 09:53 PM
            0 responses
            10 views
            0 likes
            Last Post wzgy0920  
            Working...
            X