Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8--Custom Indicator & Indexing doubles

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

    NT8--Custom Indicator & Indexing doubles

    I have a custom indicator (NT8) that outputs a data point on the close of each bar.
    Eg:
    81.123456789
    82.987654321

    These are 'doubles' and need to be doubles in structure.

    Then in another indicator I bring this data in and this plots a line on a panel below panel 1.
    (Sinewave line). All working fine.

    What I am trying to accomplish is compare this outputted data i.e. 81.123456789 for a particular bar (lets say the current bar [0]) with the previous bar [1].

    Then I can run a compare script to check that the previous bar data point is the same or different than the current.
    Example: if(thisbar[0] == previousbar[1])
    'Do something'

    What Im struggling with is the best, most elegant method to capture the data from my custom indicator so I can compare it against previous bars.
    I wish to run the compare code in the receiving indicator not the transmit indicator.

    I've tried using a variable of my data and using 'indexing' like thisbar[0] or thatbar[1] but I get an error saying that you can't run indexing with doubles.

    Hoping for some direction. Thank you.

    #2
    Hello,

    Thank you for the question.

    In general, if you need to access a BarsAgo you would need to either Plot the data or store it in a Series.

    A Double is only a single number, NinjaTrader implements a Series system that can store many doubles over the course of time either as a Visual (plot) or non visual (Series).

    Please see the examples in the help guide here: http://ninjatrader.com/support/helpG...us/seriest.htm

    Essentially you would declare a series variable much like a Plot, and then set values to that series for each OnBarUpdate call. You can then access previous values, and if you choose to make a public property for this series other scripts could access that data as well.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse. Thanks for the rapid reply. I've had a read but not sure if I should use a DataSeries or a plot.

      The data points I refer to are already being plotted (panel 2) into a sine wave line. Values[0][0] = 'data result'
      In my case I'm bringing the data from another indicator: Values[0][0] = otherindicator.variable_from_other_indicator. This happens to result in Values[0][0] = 81.123456789 etc etc.

      How could I compare the data in the current bar (on close) and the previous bar using plots for example?
      Would I have to use the plot name "SinewavePlot[0] and SinewavePlot[1] to access the BarsAgo?

      Comment


        #4
        Hello,

        If you already have plots yes you could just compare those values as you have shown or:

        if(SinewavePlot[0] > SinewavePlot[1])

        or if you are using Values, you can also use that:

        if(Values[0][0] > Values[0][1])


        This type of syntax would work in the case you set the value of this plot on each OnBarUpdate and also that there is at least 1 BarsAgo to work with. For example this logic could be executed on bar 1, but on bar 0 may give a index error.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          I'm now using a DataSeries to gather and hold the 'double' data. I have tested the data series and am Printing to the output window the results.
          My next question is. What would be the best way to plot each of these DataSeries results onto a panel and then have a line drawn between them?
          My challenge is that the data is from another time frame in another indicator. I only want the plots to print in the panel and line drawn between them when there is new data from the higher time frame- not when the current bar updates.
          If the results are plotted on each bar update in the panel the sine wave line is jagged- I'm looking for a smooth line and that will come if the data plots are plotted after each higher time frame update.

          I'm not sure I've explained things very well here so let me know if my question is not clear enough.

          Comment


            #6
            Hello,

            It would depend on the series you are using and what timeframes the data is coming from.

            Could you tell me what the timeframes are being used (chart and the series for the indicators) and provide an image of the result you currently have?

            I can review what you currently have and see if there is a way to get a more smooth line, or at the least we could review what options for plotting there are with the series you are using.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Ok, here goes.

              Chart 500 tick size.
              Indicator 1 has added DataSeries of 1500 tick time frame and another at 4500 tick time frame.

              Indicator 1 does a lot of the grunt work (the engine) and the results are then used and displayed by other indicators.
              The sine wave calculation is computed on the 1500 and 4500tick data series.
              BarsInProgress == 1 and BarsInProgress == 2 gets the results from each data series in Indi 1.

              Indicator 2 is getting the results from these calculations in Indicator 1.
              There are no other time frames (AddDataSeries) added to Indicator 2. Indi 2 only provides the code to display the results from Indi 1.

              The image I've attached is from the Indicator 2. You can see that the lines are jagged, not smooth like in the second image. The reason it's jagged is because on each bar update (500 tick) the results come from the 1500 or 4500tick data series in Indi 1.
              For example: mydataseries[0] = 81.123456789 is the last data point from lets say the 4500 tick time frame. Each time the 500 tick chart updates the 81.123456789 remains the same until the 4500 tick bar closes. Once the 4500 tick bar closes there is a new mydataseries[0] = 82.123456789 and the line is drawn to the next plot giving the jagged lines.


              I'm trying to find a way to stop the Indicator 2 plotting the same mydataseries[0] on each of the 500 tick time frame bars and only plot when the 4500 tick bar closes. This then will plot a smooth line.
              So a number of bars will close on the 500 tick chart but the plot won't follow them until a change of mydataseries[0] is noted from the 4500 tick time frame (AddDataSeries) in Indi 1.

              Does that make sense?



              Comment


                #8
                Q

                Hello,

                Thank you for the post.

                In this case the blocky plot is based on the series being used. Because you are on the most granular of the series as the primary the value of the less granular series is reported over and over. This is due to the faster frequency of the 500 tick chart.

                Here is a simple example that would cause a blocky plot:

                Code:
                protected override void OnStateChange()
                {
                	if (State == State.SetDefaults)
                	{
                		AddPlot(new Stroke(Brushes.Red, 2),PlotStyle.Line,  "Plot0");
                	}
                	else if (State == State.Configure)
                	{
                		AddDataSeries(BarsPeriodType.Tick, 4500);
                	}
                }
                
                
                protected override void OnBarUpdate()
                {
                	if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
                	if(BarsInProgress == 0)
                	{
                		Value[0] = SMA(Closes[1], 12)[0];	
                	} 
                }


                The only ways I can see around this type of problem to create a more smooth line would be to plot from a higher tick chart or to store the non changing values and Average those values. If you try to average the indicator that uses the secondary series, it will also result in a non changing value, instead you could use the sample below:

                Code:
                private Series<double> storedValues; 
                protected override void OnStateChange()
                {
                	if (State == State.SetDefaults)
                	{
                		AddPlot(new Stroke(Brushes.Red, 2),PlotStyle.Line,  "Plot0");
                	}
                	else if (State == State.Configure)
                	{
                		storedValues = new Series<double>(this);
                		AddDataSeries(BarsPeriodType.Tick, 4500);
                	}
                }
                
                
                protected override void OnBarUpdate()
                {
                	if(CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
                	if(BarsInProgress == 0)
                	{
                		storedValues[0] = SMA(Closes[1], 12)[0];
                		Value[0] = SMA(storedValues, 12)[0];	
                	} 
                }
                A new series is created, and the non changing values are stored over and over on each 500 tick OnBarUpdate. Next the SMA is used to average the values of the non changing + changing values together.

                I look forward to being of further assistance.
                Last edited by NinjaTrader_Jesse; 09-09-2016, 10:31 AM.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hi Jesse,
                  Thanks for getting back to me. That's a good solution for now. I hadn't thought of using the SMA to smooth out the lines.

                  In my example I didn't need to add the 4500 data series as the data is pulled from Indicator 1 and used in Indicator 2 in a variable.

                  While the SMA does a good job of smoothing it does affect the results somewhat. It delays the cross over points of the two lines with smoothing added.

                  My next question is. Is there a way to join the plot dots up only to the ones plotted (on the Close of the 4500 tick series)?
                  I am filtering the data to only output when a new result is found instead of printing every result on each 500 tick series bar close.
                  So for example the unfiltered data looks like this:
                  79.9635687408431
                  79.9635687408431
                  79.9635687408431
                  83.0225536924276
                  83.0225536924276
                  83.0225536924276
                  83.0225536924276
                  83.0225536924276
                  83.0225536924276
                  83.0225536924276
                  83.0225536924276
                  83.0225536924276
                  83.690123116308
                  83.690123116308
                  83.690123116308
                  83.690123116308
                  83.690123116308
                  83.690123116308
                  83.690123116308
                  The data prints on each 500 tick bar and changes only when 4500 tick bar closes.

                  I'm filtering it to this:
                  79.9635687408431
                  83.0225536924276
                  83.690123116308
                  This is the filter:
                  if(Leadsine[0] == Leadsine[1])
                  ls = 1;

                  else if(Leadsine[0] != Leadsine[1] && ls == 1)
                  {
                  Print(Leadsine[0]);
                  ls = 0;
                  }
                  Using an if and if else to check if previous results are the same as the current etc etc and only print a change.
                  This is printing to the output window.

                  Other than using the SMA is there a way to plot a line joining each of the filtered results?
                  At the moment the indicator is treating each filtered result as an individual dot and so doesn't see the previous dot to join it up with and therefore there are no lines on the panel.

                  Could we store perhaps the current bar (or date time stamp) the new 4500 result comes in on, in a data series and use that to put a dot in the panel and then have the previous dot and that dot join up with a line?

                  Comment


                    #10
                    Hello,

                    Thank you for the reply.

                    The Plotted line will be a result of the data that is being put into the plot. In the case of the SMA value, this creates a more smooth line because the values are then gradually changed over time rather than changing all at once when the greater bars value changes. The plot is going to be set on each 500 tick bar because the plot is in sync with the Primary series, this creates the blocky look as the greater bars value does not change over this time.

                    For the SMA value, would it be possible to plot the SMA's value to achieve the curved line, and then use the actual value for the conditions instead of the SMA value? Adding the SMA in this case is strictly to change the visual aspect of the plot, because the plot is a direct result of the values being used it could not be curved because the value has no change over the period of time.

                    This would be the same case with the second question related to dots, the plot is going to be a result of the data used in the plot and also the Timeframe in which it is being plotted on. For this question, if you have locations you have filtered out, or have empty values you would need to essentially repeat the value as you had shown in the first example to keep a continuous plot. If you are instead looking for Lines between two Points, I would not suggest using a Plot but instead use a Draw.Line.

                    If you have stored the Filtered results, you could iterate over the filtered results to draw a line from the first to the second, second to third etc through the list of filtered results. This would be the only way I can think of that would keep a continuous line as you have removed indexes by filtering out same prices.

                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Jesse. I've managed to tweak things a little to have the SMA plot close to the actual cross over points.
                      Thank you for your help with this issue.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by DavidHP, Today, 07:56 AM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_Erick  
                      Started by kujista, Today, 06:23 AM
                      3 responses
                      9 views
                      0 likes
                      Last Post kujista
                      by kujista
                       
                      Started by Mindset, Yesterday, 02:04 AM
                      2 responses
                      18 views
                      0 likes
                      Last Post NinjaTrader_RyanS  
                      Started by f.saeidi, Today, 08:03 AM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by samish18, 04-17-2024, 08:57 AM
                      15 responses
                      53 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Working...
                      X