Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding indicator values to secondary series

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

    Adding indicator values to secondary series

    Hi
    I have a strategy that uses indicator as order entry and i am adding a secondary series and want to have a match entries. Secondary series indicator is _patsIndicatorA for anchored. I am getting an error cannot apply [] in the expressioni of type double. Is this the right way of calling indicator on secondary series?


    Code:
    private TDUPriceAction _patsIndicator;
    private TDUPriceAction _patsIndicatorA;​
    in configured state
    Code:
     else if (State == State.Configure)
                {
                    AddDataSeries(BarsPeriodType.Tick, 2000);
                }​
    Code:
    else if (State == State.DataLoaded)
                {
                    ClearOutputWindow(); //Clears Output window every time strategy is enabled
                    _patsIndicator = TDUPriceAction(Close, TDUPatsRules.Mack, false);
    
    
                    _patsIndicatorA = TDUPriceAction(Close, TDUPatsRules.Mack, false);
                       ​
    and in my entry logic i have
    Code:
    else if (All2Entries
                    && (Position.MarketPosition == MarketPosition.Flat)
                    && (_patsIndicator.SignalLong[0].ApproxCompare(2) == 0)                
                    && !(_patsIndicator.SignalLong[0].ApproxCompare(1) == 0)
    
                    && (_patsIndicatorA.SignalLong[1][0].ApproxCompare(2) == 0)                
                    && !(_patsIndicatorA.SignalLong[1][0].ApproxCompare(1) == 0)    ​

    #2
    Hello, thanks for writing in. We have an example here showing how to set up an indicator on a secondary series:


    Your code is passing in the primary series in State.DataLoaded. The error you are getting means that _patsIndicator.SignalLong is not a series, but a double variable that is part of the _patsIndicator indicator class, so you will not be able to use it like a Series<double> object.

    Comment


      #3
      The link is broken, can you please double check the link? Also the indicator supports series.. So i wont be able to run strategy on both series entry when there is signal on both of the series?
      Click image for larger version

Name:	image.png
Views:	294
Size:	79.8 KB
ID:	1254113

      Comment


        #4
        Hi, the link is working for me. Here is the full link:

        HTML Code:
        https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?using_a_secondary_series_as_an.htm
        We have an example strategy built into the platform called "SampleMultiInstrument". This will show you how to submit orders to both series that the strategy is reading.

        Comment


          #5
          i wasnt able to find SampleMultiInstrument strategy only on github
          Sandbox for ninjatrader strategies & experiments. Contribute to beckerben/NinjaTrader development by creating an account on GitHub.


          I understand that I can call indicator with bars array when dealing with ninjatrader indicators. So with this custom indicator its not possible?
          adx = ADX(14);
          adx1 = ADX(BarsArray[1], 14);
          if (adx[0] > 30 && adx1[0] > 30)

          Comment


            #6
            I added additional series to my strategy
            I am printing Print("closes 1 1 "+Closes[1][1] + CurrentBars[1]); and in data window its bars 612, but it prints bar index 912. its not correct. How do i fix it? If i print Print("bars in progress" + BarsInProgress); i get barsinprogress0 always.. I just wanted to perform condition that secondary previous close is higher then open.

            Also I am printing inside bar that i want to display on secondary series, how can i make sure it prints on secondary series and not on primary?
            Code:
            if(BarsInProgress == 1)
                        {
                        //here
            
                        if ((Closes[1][1] > Opens[1][1]) && (Closes[1][0] < Closes[1][1]) && (Closes[1][0] > Opens[1][1]) && (Opens[1][0] < Closes[1][1]) && (Opens[1][0] > Opens[1][1])
                         || (Closes[1][1] < Opens[1][1]) && (Closes[1][0] > Closes[1][1]) && (Closes[1][0] < Opens[1][1]) && (Opens[1][0] > Closes[1][1])  && (Opens[1][0] < Opens[1][1]))
                            {
                                insidebar=true;
                                Draw.VerticalLine(this, @"Wide_Body1" + CurrentBars[0].ToString(), 0, Brushes.ForestGreen, DashStyleHelper.Dot, 1);
            //                    Draw.ArrowDown(this, @"CongestionBox Arrow down_1 " + Convert.ToString(CurrentBars[0]), false, 0, (High[0] + 2) , Brushes.White);
                            }
                            else {
                                insidebar=false;
                            }
                            }​


            Click image for larger version  Name:	image.png Views:	0 Size:	1.11 MB ID:	1254184
            Last edited by tkaboris; 06-02-2023, 05:55 AM.

            Comment


              #7
              Hi, your script is not doing something right. I can not tell what it is. You will need to reference the existing examples that I have already given you and debug your script by comparing what you are doing differently.

              Comment


                #8
                I am trying to print correct values but i cant with this logic. Something is wrong with referencing CurrentBars

                if(BarsInProgress == 1)
                {
                Print("closes[1][1]" + Closes[1][1] + CurrentBars);
                Last edited by tkaboris; 06-02-2023, 08:26 AM.

                Comment


                  #9
                  Hi, this code would not compile, it should be:

                  Print("Closes[1] [1] " + " - " + CurrentBars[0]);​

                  Here is the documentation that can be accessed at any time if needed:
                  https://ninjatrader.com/support/help...tml?closes.htm //Closes

                  Comment


                    #10
                    I have included two print statements in both BarsInProgress==1 and in outside of it and only outside ofBarsInProgress prints out
                    bars in progress0
                    closes[1][1]135862594
                    ​so it prints from primary series.
                    I dont understand why BarsinProgress==1 is not executing. Do i need to initialize values for Closes[1][1]?


                    Print("bars in progress insied barsinprogess==1" + BarsInProgress); and Print("closes[1][1]" + Closes[1][1] + CurrentBars[0]);​

                    Code:
                    if(BarsInProgress == 1)
                                {
                    [B]Print("bars in progress insied barsinprogess==1" + BarsInProgress);
                                Print("closes[1][1]" + Closes[1][1] + CurrentBars[0]);[/B]
                    
                                if ((Closes[1][1] > Opens[1][1]) && (Closes[1][0] < Closes[1][1]) && (Closes[1][0] > Opens[1][1]) && (Opens[1][0] < Closes[1][1]) && (Opens[1][0] > Opens[1][1])
                                 || (Closes[1][1] < Opens[1][1]) && (Closes[1][0] > Closes[1][1]) && (Closes[1][0] < Opens[1][1]) && (Opens[1][0] > Closes[1][1])  && (Opens[1][0] < Opens[1][1]))
                                    {
                                        insidebar=true;
                                        Draw.VerticalLine(this, @"Wide_Body1" + CurrentBars[0].ToString(), 0, Brushes.ForestGreen, DashStyleHelper.Dot, 1);
                    //                    Draw.ArrowDown(this, @"CongestionBox Arrow down_1 " + Convert.ToString(CurrentBars[0]), false, 0, (High[0] + 2) , Brushes.White);
                                    }
                                    else {
                                        insidebar=false;
                                    }
                                }
                                #endregion
                                        if (SystemPrint)
                    
                    [B]Print("percent wick low [1] " + percentWick + " - " + CurrentBars);
                                            Print("closes[1][1]" + Closes[1][1] + CurrentBars[0]);[/B]
                    
                                        }​

                    Comment


                      #11
                      so stupid i had this line in my barupdate
                      if (BarsInProgress!=0) return;

                      Comment


                        #12
                        Can you please help me to modify this line so it displays in secondary series and not in primaries??
                        Draw.VerticalLine(this, @"Wide_Body1" + CurrentBars[0].ToString(), 0, Brushes.ForestGreen, DashStyleHelper.Dot, 1);

                        P.S I wish you guys can hire someone to rewrite and or add a lot more to support files so they are actually make sense..

                        Comment


                          #13
                          Hi, the secondary series that you add using "AddDataSeries" does not display on the chart, so drawing tools can only target the primary series. The indicator has a property "DrawOnPricePanel" If the indicator runs in its own panel and DrawOnPricePanel = false, the drawing tools will show up in the indicator panel. If DrawOnPricePanel is true, drawing tools will show up on the price panel.

                          Comment


                            #14
                            hi, I am trying to call trendline values from secondary series. i was following an example but its not working. it shows error cant convert to double. Can you please help?
                            private TrendLines acnhoredTL;

                            if(BarsInProgress == 1)
                            anchoredTL = TrendLines(2,1, 0, false);​

                            Comment


                              #15
                              Hi, Please see the example in the TrendLines documentation first, it shows that it needs to be indexed:



                              double value = TrendLines(5, 4, 25, true)[0];

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              66 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              141 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              76 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              47 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              51 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X