Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

indicator as input series

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

    indicator as input series

    Hello,

    I have this code wich does a great job for what i need but sometimes i use an indicator like a sma in the input series. My question is how can i hard link so that i dont need to set the SMA as input series?

    Code:
    int num = Math.Max(1000, CurrentBar);
    			
                        IDataSeries highs = Highs[0];
    					int num1 = Swing(BarsArray[0],period).SwingHighBar(0, 1, num);
                        int num2 = num1;
    			        double item = highs[num1];
                        
    					IDataSeries highs1 = Highs[0];
    				    int num3 = Swing(BarsArray[0],period).SwingHighBar(0, 2, num);
                        int num4 = num3;
                        double item1 = highs1[num3];
    					
    					IDataSeries lows = Lows[0];
    					int num5 = Swing(BarsArray[0],period).SwingLowBar(0, 1, num);
                        int num6 = num5;
                        double item2 = lows[num5];
    					
                        IDataSeries lows1 = Lows[0];
                        int num7 = Swing(BarsArray[0],period).SwingLowBar(0, 2, num);
                        int num8 = num7;
                        double item3 = lows1[num7];
    Thank You

    #2
    Hello hliboi,

    Thanks for your post.

    int num1 = Swing(SMA,period).SwingHighBar(0, 1, num);

    Comment


      #3
      Hello Paul,

      Thanks for your assistance. I tried that but if fails to reproduce the same results using sma as input and hard coding using
      Code:
      int num1 = Swing(SMA(smaperiod),period).SwingHighBar(0, 1, num);
      . Will try to post a picture.

      Comment


        #4
        Hello hliboi,

        Thanks for your reply.

        Not sure if you are using this in a multi-series or time frame situation but if you are then try:

        int num1 = Swing(SMA(BarsArray[0], smaperiod),period).SwingHighBar(0, 1, num);

        Comment


          #5
          Thank You for the sugestion Paul.

          Will later work on MultiTimeframe but for now just want it hardlinked.

          It still doesnt replicate the same results.

          Code:
          //					int num1 = Swing(BarsArray[0],period).SwingHighBar(0, 1, num); //Works perfect but need to add the input series manually
          //					int num1 = Swing(SMA(BarsArray[0], smaperiod),period).SwingHighBar(0, 1, num); //Works the same the code below givin diferent values 
          //					int num1 = Swing(SMA(smaperiod),period).SwingHighBar(0, 1, num);
          Will post the entire OnBarUpdate maybe its clearer.

          Code:
          protected override void OnBarUpdate()
                  {
                      if (CurrentBar < period || CurrentBars[0] < period || BarsInProgress != 0)
                      {
                          return;
                      }
                      di = 0;
          			
          			
                              int num = Math.Max(1000, CurrentBar);
          			
          			
                              IDataSeries highs = Highs[0];
          					int num1 = Swing(SMA(BarsArray[0], 1),period).SwingHighBar(0, 1, num);
                              int num2 = num1;
          			        double item = highs[num1];
          			
          //					int num1 = Swing(BarsArray[0],period).SwingHighBar(0, 1, num);
          //					int num1 = Swing(SMA(BarsArray[0], smaperiod),period).SwingHighBar(0, 1, num);
          //					int num1 = Swing(SMA(smaperiod),period).SwingHighBar(0, 1, num);
          			
                              
          					IDataSeries highs1 = Highs[0];
          				    int num3 = Swing(SMA(BarsArray[0], 1),period).SwingHighBar(0, 2, num);
                              int num4 = num3;
                              double item1 = highs1[num3];
          					
          					IDataSeries lows = Lows[0];
          					int num5 = Swing(SMA(BarsArray[0], 1),period).SwingLowBar(0, 1, num);
                              int num6 = num5;
                              double item2 = lows[num5];
          					
                              IDataSeries lows1 = Lows[0];
                              int num7 = Swing(SMA(BarsArray[0], 1),period).SwingLowBar(0, 2, num);
                              int num8 = num7;
                              double item3 = lows1[num7];
                             
          					if (Inputs[0][0]> Math.Max(item, item1))
                              {
                                  di = 1;
                              }
                              else if (Inputs[0][0]< Math.Min(item2, item3))
                              {
                                  di = -1;
                              }
                              else if (item > item1 && item2 > item3 && MIN(num6 - 1)[0] > item2)
                              {
                                  di = 1;
                              }
                              else if (item < item1 && item2 < item3 && MAX(num2 - 1)[0] < item)
                              {
                                  di = -1;
                              }
                              if (num2 < 0 || num4 < 0 || num6 < 0 || num8 < 0)
                              {
                                  di = 0;
                              }
                                                 
                              if (di == -1)
                              {
                                  Dir.Set(-1);
                                  PlotColors[0][0] = Color.Red;
                                  return;
                              }
                              if (di == 1)
                              {
                                  Dir.Set(1);
                                  PlotColors[0][0] = Color.Green;
                                  return;
                              }
                              Dir.Set(0);
                              PlotColors[0][0] = Color.Yellow;
                              return;
                      
                  }
          Thank You once again

          Picture:
          Attached Files
          Last edited by hliboi; 12-16-2015, 01:48 PM. Reason: Adding picture

          Comment


            #6
            Hello hliboi,

            When you get a chance, please post a screenshot with the two ways you've tried (using SMA as input and hard coding) as that might help us understand where you are heading.
            Thanks in advance.

            Comment


              #7
              Just did Paul. Sorry I edit the previous post.
              Thank You

              Comment


                #8
                Hello hliboi,

                Thanks for your post and picture.

                Trying to recreate on my end.

                Are you using an SMA(1) and is the swing period(strength) also 1?

                Comment


                  #9
                  Thanks Paul,

                  Yes. just to try im using both 1 period.

                  I can send you the full source if needed.

                  Thank You

                  Comment


                    #10
                    Hello hliboi,

                    Thanks for your reply.

                    That would be fine if you wish to do that.

                    Alternatively in looking again at what you posted, you are using input[0][0] in what sets the value of the plot. It would be interesting to print those values in the two cases of using SMA as input verses using SMA hardcoded. I suspect that is where the difference may be.

                    Comment


                      #11
                      Hello Paul,

                      I tried many combinations switching the Inputs [0][0] to SMA(1)[0] with no sucess at replicating the plot and result that is achieved using Input Series.

                      I find it awkard now.

                      Thank You

                      Comment


                        #12
                        Hello hliboi,

                        Thank you for your response.

                        May we test your full code on our end?
                        You can attach your indicator to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your Indicator > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.

                        If you prefer you can send the file to platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick - 1432001' in the subject line.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        577 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        334 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        101 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        553 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        551 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X