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

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:



    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.

    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;
        			
        			[B]Add(PeriodType.Tick, 500);[/B]
                }
        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([B]Closes[1][0][/B] - (((DonchianChannel([B]BarsArray[1][/B], 20).Mean.Get([B]CurrentBars[1][/B])) + (EMA([B]BarsArray[1][/B], 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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cre8able, Today, 01:01 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by manitshah915, Today, 12:59 PM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by ursavent, Today, 12:54 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Mizzouman1, Today, 07:35 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by RubenCazorla, Today, 09:07 AM
        2 responses
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X