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

Question on PLOTS ... similar to ZigZag

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

    Question on PLOTS ... similar to ZigZag

    I'm working on an indicator similar to the ZigZag indicator in NT in which a datapoint is not plotted on every bar, but only under specific circumstances.

    I've opened up ZigZag in the NinjaScript editor and have to admit that it is beyond my programming knowledge to understand exactly how ZigZag works programatically.

    As a working example, I have put together the following code. It plots a dot at the close of a day, but only if that day is an inside day.
    if(CurrentBar < 10)
    return;

    if( Low[0]>Low[1]
    &&
    High[0]<High[1] )
    Plot.Set(Close[0]);
    I want to change this so that it plots a line connecting the datapoints, not just a dot mark at each datapoint. (Please Note: Changing the plot characteristics from Plotstyle.Dot to Plotstyle.Line is not in itself the solution--a line will only be plotted between two consecutive inside days).

    I suspect the solution has something to do with conditionally cycling through days and testing for the presence of an inside day...but unfortunately this is beyond my skill-level.

    Please see the attached .png showing the present plot of the indicator and how it should look.

    Does anyone know how to achieve this?
    Attached Files

    #2
    Hello,

    Unfortunately the section inside the zigzag indicator called public override Plot() section is what allows for this and it is not nativly supported by NinjaTrader.

    However as you have seen this code is fairly complex to do this.

    The only other solution I have for you is to using drawing objects to do what you need.

    You can use the DrawLine() drawing objects to do this.



    Let me know if I can be of further assistance.

    Comment


      #3
      Hi h1000,

      You could implement what you want without the complicated Plot override.
      Just use the DrawLine method.
      I would do something like this:
      store your last price data point and draw a line between the last and your new price data point.
      You need to declare something similar to the following in the variables region, along with your other variables
      #region Variables
      private double lastPriceData = 0;
      private int barCounter = 0;
      private int tagCounter = 0;
      #endregion

      In the OnBarUpdate you would place something similar to this:
      barCounter++; //increment the barCounter after each OnBarUpdate call so we know how far back we //need to draw the line
      if( Low[0]>Low[1] && High[0]<High[1] )
      {
      DrawLine("LineId" + tagCounter.ToString(), barCounter, lastPriceData, 0, Close[0], Color.Blue);
      lastPriceData = Close[0]; //update the lastPriceData with the new one
      tagCounter++; //increment the counter
      barCounter = 0; // reset the bar counter for the next plot
      }

      This code "LineId" + tagCounter.ToString() is needed to give each drawn line a unique string tag. If the string tag is identical then the previously drawn line would be deleted and a new one drawn. This way we change the DrawLine string tag by adding a number to it which is converted to string.

      I hope this will get you started. You need to take care of boundary and initial conditions and so on.
      Last edited by sprad001; 01-08-2012, 03:53 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Option Whisperer, Today, 09:00 AM
      1 response
      2 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by iplaymuzik, Today, 09:13 AM
      0 responses
      1 view
      0 likes
      Last Post iplaymuzik  
      Started by z.franck, Today, 08:37 AM
      2 responses
      5 views
      0 likes
      Last Post z.franck  
      Started by reynoldsn, Today, 09:01 AM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by Gavin45, Today, 08:40 AM
      2 responses
      3 views
      0 likes
      Last Post Gavin45
      by Gavin45
       
      Working...
      X