Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set custom series data to plot (candlesticks)

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

    Set custom series data to plot (candlesticks)

    Hello NT Team,
    I try to create custom data series (index/basket) based on other instruments. Now, I want to plot the new data series on my chart as candle sticks.

    Question: how can I set the new data series as input for the candle sticks?

    #2
    Hello dontas,
    Thanks for your post.
    How are you creating this custom data series?
    What custom data series are you accessing?
    Who are you connected to?
    BrandonNinjaTrader Customer Service

    Comment


      #3
      Calculate = Calculate.OnEachTick;
      sectorAuto = new Series<double>(this); (as alternative I'm thinking about this instead: new DataSeries(this,MaximumBarsLookBack.Infinite)

      I added instruments by the following function in the OnStateChange() function:
      AddDataSeries()

      Now, based on the instruments I'm going to calculate the index and store it in the sectorAuto variable (data set). Next step would be to set this series as source for the candle sticks in the chart.

      Comment


        #4
        Hello dontas,

        This code is for NinjaTrader 8 which is currently in Beta (8.0.0.14).

        For future reference, below I am providing a link to the NinjaTrader 8 Beta section of the forums.


        If you are trying to do a basket test (test a strategy over several instruments) this can be done by selecting an instrument list in the Strategy Analyzer to test over. By selecting an instrument list, this will test the strategy for each instrument in the instrument list (basket test).


        If you are wanting to add a secondary series to your script to use for calculations, this can be done with the AddDataSeries() method. This adds a secondary series with a different instrument and / or different time frame.


        For example:
        Code:
        protected override void OnStateChange() 
        {
            if (State == State.Configure)
            {
                AddDataSeries("AAPL", BarsPeriodType.Minute, 1);
            }
        }
        This would add a 1 minute apple data series to the script.

        If you are wanting to create a custom series to store data that you are calculating in your script (meaning you would populate this series with values), you can do so by creating a new series.


        For example:
        Code:
        private Series<double> myDoubleSeries;
        
        protected override void OnStateChange() 
        {
            if (State == State.Configure)
            {
                myDoubleSeries = new Series<double>(this, MaximumBarsLookBack.Infinite);
            }
        }
        
        protected override void OnBarUpdate()
        {
        myDoubleSeries[0] = 100.01;
        }

        There is no longer a DataSeries class in NinjaTrader 8. This would be used for NinjaTrader 7.
        Last edited by NinjaTrader_ChelseaB; 10-10-2016, 01:06 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          great and thanks Brandon. I want to create the basket in an indicator, so the basket has after every minute open, high, low and close. What's missing for my solution: How can I plot the basket on the chart instead of the instrument?

          Comment


            #6
            Originally posted by dontas View Post
            Calculate = Calculate.OnEachTick;
            sectorAuto = new Series<double>(this); (as alternative I'm thinking about this instead: new DataSeries(this,MaximumBarsLookBack.Infinite)

            I added instruments by the following function in the OnStateChange() function:
            AddDataSeries()

            Now, based on the instruments I'm going to calculate the index and store it in the sectorAuto variable (data set). Next step would be to set this series as source for the candle sticks in the chart.
            A candlestick requires 4 data points: OHLC. You are talking here of 1 data point. You will never be able to draw a candlestick chart with only one datum per candlestick.

            How are you really going to get all the necessary data points?

            Comment


              #7
              Hello dontas,

              Can you further detail what you mean by basket?

              The Open, High, Low, and Close of the primary series are already available to your script.

              For example try printing:
              Code:
              protected override void OnBarUpdate()
              {
              Print(string.Format("{0} | Open[0]: {1}, High[0]: {2}, Low[0]: {3}, Close[0]: {4}", Time[0], Open[0], High[0], Low[0], Close[0] ));
              }
              Open - http://ninjatrader.com/support/helpG...en-us/open.htm
              High - http://ninjatrader.com/support/helpG...en-us/high.htm
              Low - http://ninjatrader.com/support/helpG.../en-us/low.htm
              Close - http://ninjatrader.com/support/helpG...n-us/close.htm

              Are you wanting to add several instrument's data to an indicator?
              Are you wanting to access the open, high, low, and close of the primary series?
              Are you wanting to create a custom bar type?
              Last edited by NinjaTrader_ChelseaB; 10-10-2016, 01:11 PM.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Here is an example for a M1 candlestick basket (subsector of German DAX, equally weighted index):
                BMW
                Volkswagen
                Daimler
                Porsche

                After each minute each instrument has OHLC prices. By averaging those values I have an index with OHLC as well. Is there a way to plot the index as candlestick chart?
                Last edited by dontas; 10-10-2016, 01:20 PM.

                Comment


                  #9
                  Originally posted by dontas View Post
                  Here is an example for a M1 candlestick basket (subsector of German DAX, equally weighted index):
                  BMW
                  Volkswagen
                  Daimler
                  Porsche

                  After each minute each instrument has OHLC prices. By averaging those values I have an index with OHLC as well. Is there a way to plot the index as candlestick chart?
                  So then, now you will have OHLC data for each candleslot. Good.

                  Now look at the HeikenAshi indicator that ships with NT7 (the forum in which you are posting), for an example of how to draw candlesticks with said data.

                  Comment


                    #10
                    Hello dontas,

                    Thank you for confirming you are wanting to add additional series to the script.

                    In the script add each instrument with AddDataSeries().
                    Also add a plot for the value.
                    Code:
                    protected override void OnStateChange() 
                    {
                        if (State == State.Configure)
                        {
                            AddDataSeries("Symbol1", BarsPeriodType.Minute, 1);
                            AddDataSeries("Symbol2", BarsPeriodType.Minute, 1);
                            AddDataSeries("Symbol3", BarsPeriodType.Minute, 1);
                            AddDataSeries("Symbol4", BarsPeriodType.Minute, 1);
                    
                            AddPlot(Brushes.Blue, "MyPlot");
                        }
                    }
                    In OnBarUpdate(), choose the BarsInProgress this will trigger on, and use Opens[BarsInProgressIndex][BarsAgoValue], Highs[][], Lows[][], and Closes[][] to get the values for each series.

                    For example to print the OHLC for each added series (not including the primary):
                    Code:
                    protected override void OnBarUpdate()
                    {
                    	if (BarsInProgress == 0)
                    	{
                    		for (int i = 1; i < CurrentBars.Length; i++)
                    		{
                    			if (CurrentBars[i] < 1)
                    				return;
                    
                    			Print(string.Format("{0} | BarsInProgress: {1} | Instrument: {2} | Opens[{1}][0]: {3}, Highs[{1}][0]: {4}, Lows[{1}][0]: {5}, Closes[{1}][0]: {6}",
                    				Times[i][0], i, BarsArray[i].Instrument.FullName, Opens[i][0], Highs[i][0], Lows[i][0], Closes[i][0] ));
                    		}
                    	}
                    }
                    Or, as another example if you wanted to average the opens of the 4 added series:
                    Code:
                    protected override void OnBarUpdate()
                    {
                    	if (BarsInProgress == 0 && CurrentBars[1] > 1 && CurrentBars[2] > 1 && CurrentBars[3] > 1 && CurrentBars[4] > 1)
                    	{
                    		Value[0] = (Opens[1][0] + Opens[2][0] + Opens[3][0] + Opens[4][0]) / 4;
                    	}
                    }
                    BarsInProgress - http://ninjatrader.com/support/helpG...inprogress.htm
                    Opens - http://ninjatrader.com/support/helpG...n-us/opens.htm
                    Highs - http://ninjatrader.com/support/helpG...n-us/highs.htm
                    Lows - http://ninjatrader.com/support/helpG...en-us/lows.htm
                    Closes - http://ninjatrader.com/support/helpG...-us/closes.htm

                    AddPlot() - http://ninjatrader.com/support/helpG...us/addplot.htm
                    Value - http://ninjatrader.com/support/helpG...n-us/value.htm
                    Last edited by NinjaTrader_ChelseaB; 10-10-2016, 03:38 PM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by koganam View Post
                      So then, now you will have OHLC data for each candleslot. Good.

                      Now look at the HeikenAshi indicator that ships with NT7 (the forum in which you are posting), for an example of how to draw candlesticks with said data.
                      Thanks koganam, you made my day! Same to you ChelseaB!

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Max238, Today, 01:28 AM
                      1 response
                      22 views
                      0 likes
                      Last Post CactusMan  
                      Started by giulyko00, Yesterday, 12:03 PM
                      2 responses
                      10 views
                      0 likes
                      Last Post giulyko00  
                      Started by r68cervera, Today, 05:29 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post r68cervera  
                      Started by geddyisodin, Today, 05:20 AM
                      0 responses
                      6 views
                      0 likes
                      Last Post geddyisodin  
                      Started by JonesJoker, 04-22-2024, 12:23 PM
                      6 responses
                      38 views
                      0 likes
                      Last Post JonesJoker  
                      Working...
                      X