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

Coding Plot displacement in Ninja Script

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

    Coding Plot displacement in Ninja Script

    I'm trying to create an indicator wherein if something happens on this bar it will modify the plot for the last several bars. Is this possible? If so how is this accomplished in Ninja Script?

    Thanks

    #2
    I don't know if I can help but you will need to be more specific - How do you want to modify it ? What do you want to do with it afterwards? and how long is 'afterwards'? Why are you only modifying it for the last few bars - this makes it unnecessarily complicated?
    Last edited by stocktraderbmp; 04-04-2012, 05:55 PM.

    Comment


      #3
      What I'm trying to do should not be complicated (I think). I want to make an indicator which is basically a flat line until a peak or a valley is identified. Once it's identified I want to draw a 'blip' on the flat line; but that blip will invariably be on a bar in the recent past. Something like Plot[2](blipvalue);
      Thanks for replying..... I hope this explains it more clearly?

      Comment


        #4
        I have to assume that this will not be overlayed on the chart like an MA - so you could simply code your values and then use the Max - Min function when you reference the value for the plot -

        In properties you would use :

        [Description("")]
        [GridCategory("")]
        public int MyValue
        {
        get { return myValue; }
        set { myValue = Math.Max(n, value); }
        }
        I don't know what your likely outputs are but if they are less than 'n' you will always plot 'n' until your 'blip' exceeds 'n' then you will get your 'spike'.

        Alternatively you can use :

        MyValue.Set(Math.Max(myValue, n));

        Again this will plot the maximum of either n or your calculated value.

        Finally you could try

        x = (myValue < n) ? 0 : 1;

        Here you will have already calculated myValue and you are using a condition -
        If myValue is less than 'n' - plot a 0 otherwise plot a 1.

        If 'n' is a calculation you will need to call it as another double first -
        double n = (a + b + c )/ 100

        Hope this is enough to get you started.

        Ben.

        Comment


          #5
          Hawk Arps, you could set a negative displacement for your indicator for example - http://www.ninjatrader.com/support/h...splacement.htm

          However, keep in mind then it would take the displacement set bars in realtime to show the value, as of course it can't predict the values needed.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Thanks... but the displacement is not the same for every occurrence of the signal. It appears to me that an indicator cannot be scripted to plot [n] bars ago, but only on the current bar. Therefor I decided to try the DrawLine(....) method; but it appears that only works on the price panel and not a subgraph.Is it possible to apply DrawLine(...) in an indicator panel instead of the price panel?

            Comment


              #7
              Hi Hawk Arps,

              Yes, you can set DrawOnPricePanel = false; and drawings are then place in indicator panel.

              To give you another idea here, there is PlotColors[][] property. The second index there is the bars ago value for the plot. Here is a simple loop that would color the plot for a few bars preceding the condition.

              Code:
              protected override void OnBarUpdate()
              {
              	if (CurrentBar < 3) return;
              	
              	if (Close[0] == Low[0])
              	{
              		DrawTriangleDown(CurrentBar.ToString(), true, 0, High[0], Color.Green);
              		
                              for (int x = 0; x <= 3;x++)
              		{
              		PlotColors[0][x] = Color.Green;	
              		}
              	}
              	
                  Plot0.Set(Close[0]);
              }
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                It seems that example you gave will change the color of the plot several bars ago, but can I set a plot value for several bars ago.
                BTW I think I can accomplish my goal for this tool using DrawOnPricePanel = false; and using the DrawLine(...) method. Thanks again.

                Comment


                  #9
                  Great that the line solution will work for you. Yes, you can set the value for historical bars by including a "barsAgo" value that represents the number of bars ago that you want the double value to be stored at.

                  This is how you format the set method for this:
                  DataSeries.Set(int barsAgo, double value)
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks, I think that that was the answer I was looking for all along.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by rajendrasubedi2023, Today, 09:50 AM
                    2 responses
                    12 views
                    0 likes
                    Last Post rajendrasubedi2023  
                    Started by geddyisodin, Today, 05:20 AM
                    4 responses
                    28 views
                    0 likes
                    Last Post geddyisodin  
                    Started by geotrades1, Today, 10:02 AM
                    2 responses
                    8 views
                    0 likes
                    Last Post geotrades1  
                    Started by ender_wiggum, Today, 09:50 AM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by bmartz, Today, 09:30 AM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Working...
                    X