• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I duplicate the calculations below for an additional DataSeries?

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

    How can I duplicate the calculations below for an additional DataSeries?

    Hi Support,
    I am new to C# coding and still learning it on-the-fly. Please help with this multi-DataSeries question: How can I duplicate the calculations below for an additional DataSeries?

    Background: I'd like to send buy/sell orders when the RSqueeze indicators on both DataSeries cross the respective zero line.
    1st. I add a DataSeries to the code, but not to the chart. For example: 500-tick NQ to the 100-tick NQ chart.
    2nd. I add the code below to calculate the RSqueeze values for the 100-tick chart
    3rd. I add the same set of code to calculate the RSqueeze values for the 500-tick DataSeries. I know I need to use a second set of variables and "Closes[1] and CurrentBars[1]" for that price data. But where I got stuck are in two places: "Input" and "new DataSeries(this)", which I could not find an explanation that I could understand on these two items.

    Thank you in advance,
    Raymond


    The code below is part of the RSqueeze Indicator, see thread:

    https://ninjatrader.com/support/foru...49&postcount=5

    Actual code:

    #region Variables
    private DataSeries myValue2;
    public double SqueezeValue = 0 ;

    #endregion

    protected override void Initialize()
    {
    Overlay = true;
    CalculateOnBarClose = true;
    myValue2 = new DataSeries(this);
    }
    protected override void OnBarUpdate()

    {
    double avtrrg = ATR(20)[0];
    double sd = StdDev(Close, 20)[0];
    double bbsInd = (1.5 * avtrrg) != 0 ? 2 * sd / (1.5 * avtrrg) : 1;

    myValue2.Set(Input[0] - (((DonchianChannel(Input, 20).Mean.Get(CurrentBar)) + (EMA(Input, 20)[0])) / 2));
    SqueezeValue = LinReg(myValue2, 20)[0];
    }

    #2
    Hello raymondwins,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    The line in your code that reads as "myValue2 = new DataSeries(this);" in the Initialize() method would sync that DataSeries to the primary bar series which in this case is the 100 tick bar series.

    You would want to instead sync the DataSeries to the secondary series (the 500 tick bar series) added in your code. We have a reference sample that details exactly how to sync the DataSeries to the secondary series. You can find the reference sample at the following link: https://ninjatrader.com/support/foru...ead.php?t=3572

    Please let me know if you have any questions.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Thanks but more help please

      Patrick,

      Thanks for the link. I read the content of it before I asked for help and after, but I am still clueless. The sample was imported into NT7, but after that, I could not find it anywhere, or in anyway. The linked document only seems to focus on code for adding a 2nd or 3rd DataSeries but doesn't provide instructions as to how to use the sample on using the keyword DataSeries. And it doesn't show how to find the sample, either.

      The key seems to be at the "myValue2.Set(....)" where I got stuck. I can't connect the "Input" keyword in that code to the 2nd DataSeries and that was why I raised the question last week.

      Anyways, any more information or instruction(s) would be greatly appreciated.
      Raymond

      Comment


        #4
        Hello raymondwins,

        Thank you for your response.

        Below is the code you provided in your first post and the information from the 'SampleDataSeries' strategy that you can find under Tools > Edit NinjaScript > Strategy in NinjaTrader after importing through File > Utilities > Import NinjaScript. You can download the reference sample 'SampleDataSeries' from the following link: https://ninjatrader.com/support/foru...ead.php?t=3572

        You first need to add the additional 500 Tick to your code:
        Code:
        	private DataSeries myValue2;
        	private double squeezeValue = 0;
        		
                protected override void Initialize()
                {
        			Overlay				= true;
        			CalculateOnBarClose = true;
        			
        			Add(PeriodType.Tick, 500);
                }
        Then in the OnBarUpdate() method we need to check for our DataSeries as null and if it is null then we sync it to the added 500 Tick series from the code above by passing an indicator based on the BarsArray[1]. BarsArray[1] is your added series where BarsArray[0] is the series of the chart (100 tick in this case).
        Code:
                protected override void OnBarUpdate()
                {
                    if (myValue2 == null)
        			{
        				/* Syncs another DataSeries object to the secondary bar object.
        				We use an arbitrary indicator overloaded with an IDataSeries input to achieve the sync.
        				The indicator can be any indicator. The DataSeries will be synced to whatever the
        				BarsArray[] is provided.*/
        				myValue2 = new DataSeries(SMA(BarsArray[1], 50));
        			}
        Then we pass the Closes[1][0], BarsArray[1], and CurrentBars[1].
        Code:
        			myValue2.Set(Closes[1][0] - (((DonchianChannel(BarsArray[1], 20).Mean.Get(CurrentBars[1])) + (EMA(BarsArray[1], 20)[0])) / 2));
        			squeezeValue = LinReg(myValue2, 20)[0];
                }
        Please visit the following links for more information:

        Please let me know if you have any questions.
        Patrick H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Duval, Today, 08:38 AM
        0 responses
        6 views
        0 likes
        Last Post Duval
        by Duval
         
        Started by i2w8am9ii2, 02-13-2019, 04:28 PM
        7 responses
        61 views
        0 likes
        Last Post sledge
        by sledge
         
        Started by woodyfox, Yesterday, 08:33 PM
        0 responses
        7 views
        0 likes
        Last Post woodyfox  
        Started by rblunsom, Yesterday, 11:19 AM
        2 responses
        29 views
        0 likes
        Last Post guidoisot  
        Started by drewski1980, Yesterday, 02:38 PM
        1 response
        22 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Working...
        X