Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding plots/values dynamically within indicator

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

    Adding plots/values dynamically within indicator

    Bug maybe.

    Ultimate goal is an indicator which plots where all rays extending into the future intersect with the present moment so orders can be attached to them. Need multiple rays to attach multiple varied entries, stops, targets, etc.

    Below code is almost there. It plots the EndAnchor.Price. Eventually, I'll put a slope calculation in to MoveAnchor to the intercept at the present moment.

    The code gets all rays pointing to the future. Filters those which are user drawn. And for each pulls the EndAnchor.Price.

    Below code compiles, but does not plot anything or expose any values to the databox.

    Previous versions of the code, where I added a single plot and put a single ray anchor's price into a single value worked fine.

    Leads me to believe the hang-up is with the way the plots are dynamically added. I've tried dynamically adding them in State.SetDefaults, State.Configure, and OnBarUpdate(), all to no avail.

    My search of other NT8 threads suggests my code is doing it correctly, just not sure why it's not plotting.

    Any suggestions?
    PHP Code:

    public class Raycator Indicator
        
    {
            protected 
    override void OnStateChange()
            {
                if (
    State == State.SetDefaults)
                {
                    
    Description                            = @"Grabs the price where any ray crosses the current market time.";
                    
    Name                                "Raycator";
                    
    Calculate                            Calculate.OnEachTick;
                    
    IsOverlay                            true;
                    
    DisplayInDataBox                    true;
                    
    //DrawOnPricePanel                    = true;
                    
    IsSuspendedWhileInactive            true;
                                    
                }
                else if (
    State == State.Configure)
                {
                    
    int i=0;
                    foreach (
    DrawingTool draw in DrawObjects)
                    {
                        if (
    draw.IsUserDrawn && draw is DrawingTools.Ray)
                        {
                            
    DrawingTools.Ray tempRay draw as DrawingTools.Ray;
                            if (
    tempRay.StartAnchor.Time tempRay.EndAnchor.Time)
                            {
                                
    AddPlot(Brushes.GreentempRay.Tag);                            
                            }
                        }
                        
    i++;
                    }
                }
            }

            protected 
    override void OnBarUpdate()
            {
                
    int i=0;
                foreach (
    DrawingTool draw in DrawObjects)
                {
                    if (
    draw.IsUserDrawn && draw is DrawingTools.Ray)
                    {
                        
    DrawingTools.Ray tempRay draw as DrawingTools.Ray;
                        if (
    tempRay.StartAnchor.Time tempRay.EndAnchor.Time)
                        {    
                            
    Values[i][0] = tempRay.EndAnchor.Price;
                        }
                    }
                    
    i++;
                }
            }
        }

    Last edited by pesudoalias; 05-02-2016, 05:13 AM.

    #2
    Does it give you any error in the Log tab? Does it actually add the plots? Try adding Print just above AddPlot to confirm it is reaching the code.

    Comment


      #3
      Hello pesudoalias,

      Thank you for your post.

      I tested out your code and I was able to see the plots added if I had the Rays drawn on the chart manually first.

      Attached is the file I used to test. Does it work on your end? Do you draw the Rays before adding the indicator to the chart? Do you see any errors as gregid asked? And what version of NinjaTrader 8 are you running? For example: 8.0.0.10, found under Help > About.
      Attached Files

      Comment


        #4
        Version is 8.0.0.10 64-bit (Standard) - BETA

        Test1508663.cs plots on my tick charts with previously-drawn rays. It does not plot on minute chart.

        If I move a ray that is plotting, the plots do update to reflect that move.

        Databox has to be reloaded to show plot values.

        Adding a ray destroys plots as soon as the next tick occurs after the ray is added. Error then says "Error on calling OnBarUpdate method on bar ... Index was outside bounds of the array." Reloading the indicator restores plots on rays already on chart.

        No plots, no errors when chart is clear and rays are drawn after loading indicator.

        I am looking to avoid reloading the indicator to plot newly drawn rays.

        Thanks so much.
        Last edited by pesudoalias; 05-02-2016, 07:00 PM.

        Comment


          #5
          Hello pesudoalias,

          Thank you for your response.

          I have to right click in the chart and reload NinjaScript to get the plots to update. Unfortunately, there is not a work around for this. Dynamically adding the plots would not be supported in this manner (using drawing objects to determine the plots).

          Comment


            #6
            Originally posted by NinjaTrader_PatrickH View Post
            Hello pesudoalias,

            Thank you for your response.

            I have to right click in the chart and reload NinjaScript to get the plots to update. Unfortunately, there is not a work around for this. Dynamically adding the plots would not be supported in this manner (using drawing objects to determine the plots).
            Thanks. Given that AddPlots may be called only in State.Default or in State.Configure, can't say I'm surprised.

            If you know of a way to programmatically reload the indicator (which I'd call as soon as Values.Length is not equal to Plots.Length), I'd be forever grateful.

            Many thanks again.

            Comment


              #7
              Hello pesudoalias,

              Thank you for your response.

              You can look into SendKeys and sending F5 to the chart to reload the script, but there would not be any native functions to do this in NinjaScript.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rtwave, 04-12-2024, 09:30 AM
              4 responses
              29 views
              0 likes
              Last Post rtwave
              by rtwave
               
              Started by yertle, Yesterday, 08:38 AM
              7 responses
              28 views
              0 likes
              Last Post yertle
              by yertle
               
              Started by bmartz, 03-12-2024, 06:12 AM
              2 responses
              21 views
              0 likes
              Last Post bmartz
              by bmartz
               
              Started by funk10101, Today, 12:02 AM
              0 responses
              6 views
              0 likes
              Last Post funk10101  
              Started by gravdigaz6, Yesterday, 11:40 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X