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

Occurence indicator

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

    Occurence indicator

    Hi everyone , i'm looking for creating an indicator that plot the occurence of close prices ; so the X-axis will have the close prices and Y-axis will have the number of occurrence .

    so my first problem is how to change des X and Y axis so that they have the values of close prices and number of occurence .

    and my second problem is i have an error after trying this code :


    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.


    for(j = 0 ; j < 259 ; j ++ )
    {

    for(i = 1 ; i < 259 ; i ++ )
    {
    if(Close[j] == Close[i] )
    {
    sum = sum + 1 ;

    }

    Print("Close : " + Close[j] + " Nbr d'occurence : " + sum + "Current Bar " + CurrentBar) ;

    }

    }





    }

    Indicator 'Occurenceprix': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    #2
    Hello tarikghost,

    Thanks for your post.

    The charts X - axis is fixed to be a time based so you would be unable to change to anything else. You may be able to accomplish your goal through custom plotting. Please review the indicator CustomPlotSample.cs in your NinjaTrader for code example. You may want to look at the indicator VolumeProfile which plots the buy/sell volume at price through custom plotting.

    The code example will fail until the CurrentBar is >= 259. What is happening is that when J=0 and I = 1, on the first bar loaded, the statement will be Close[0] == Close[1] and on the first bar loaded there is no bar 1 (previous bar). You would need to wait until you have a minimum of 259 bars loaded, this can be done with a current bar check like: if (CurrentBar < 259) return; // first statement in the OnBarUpdate() method.
    http://ninjatrader.com/support/helpG...currentbar.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply Paul , i just tried the Volume Profile it didn't plot anything , my only purpose is to do so as described in this image .

      if it's possible to help me calculate the number of occurence of each price and plot it in ninjatrader . Thanks
      Attached Files

      Comment


        #4
        Hello tarikghost,

        Thanks for your reply.

        The VolumeProfile indicator is a real time indicator that basically starts when you apply it to a chart so to see it in action you would need to let it run for a period of time (assuming you are connected to a realtime or market replay data feed). Please see: http://ninjatrader.com/support/helpG...indicators.htm

        As previously advised you would need to create a custom indicator using custom plotting techniques if you need to show this on a chart in NinjaTrader. (see links in first reply) NinjaTrader does not provide custom coding service or debugging services and we can refer you to 3rd party coders upon your request.

        An alternative to suggest here is to output the close prices to a text file that you could then import into a spreadsheet program for your analysis. There are a couple of ways to do this, one way is to use the Historical Data Manager to export the tick, minute or daily bars, please see: http://ninjatrader.com/support/helpG...?exporting.htm If you need bars other than 1 tick or other than 1 minute then another approach is to use an indicator that can export the data from a chart where the chart has formatted the bars to your needs. We have a working example of this here: http://ninjatrader.com/support/forum...ead.php?t=3475
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by tarikghost View Post
          Thanks for your reply Paul , i just tried the Volume Profile it didn't plot anything , my only purpose is to do so as described in this image .

          if it's possible to help me calculate the number of occurence (sic) of each price and plot it in ninjatrader . Thanks
          You will have to use a Custom Plot and standard c# graphics, DrawString() to do that.

          Comment


            #6
            Thanks for your reply ,

            actually i want to compare Close[0] with all the other Close[barsAgo] , and if he finds a value

            the counter increments by one .

            so :

            if(Close[0] == Close[AllbarsAgo]) Counter ++ ;

            my problem is there nothing such as AllbarsAgo , i tried with a loop :

            OnbarUpdate ()
            {
            for(i=0 ; i < (NumberofBars) ; i ++ )
            {
            if(Close[0] == Close[i] ) Counter ++ ;
            }

            }

            and at this point , on each bar it does the loop wich is not my purpose . Please if you can help me on this one i would appreciate it .

            Comment


              #7
              Hello tarikghost,

              Thanks for your reply.

              You may want to review the code within VolumeProfile indicator as this gives an example of using a SortedDictionary where the price is checked to see if it is in the dictionary and if not it is added and then the volume for each price level is added. (So you would simply add or increment the count for each price).

              Here is an alternative reference: http://www.dotnetperls.com/sorteddictionary Further examples are available via searching the internet.
              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Aviram Y, Today, 05:29 AM
              4 responses
              11 views
              0 likes
              Last Post Aviram Y  
              Started by algospoke, 04-17-2024, 06:40 PM
              3 responses
              26 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by bmartz, 03-12-2024, 06:12 AM
              3 responses
              30 views
              0 likes
              Last Post NinjaTrader_Zachary  
              Started by gentlebenthebear, Today, 01:30 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by cls71, Today, 04:45 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X