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

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);
    Paul H.NinjaTrader Customer Service

    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);
        Paul H.NinjaTrader Customer Service

        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.
            Paul H.NinjaTrader Customer Service

            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?
                Paul H.NinjaTrader Customer Service

                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.
                    Paul H.NinjaTrader Customer Service

                    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 Barry Milan, Yesterday, 10:35 PM
                        5 responses
                        16 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by DanielSanMartin, Yesterday, 02:37 PM
                        2 responses
                        13 views
                        0 likes
                        Last Post DanielSanMartin  
                        Started by DJ888, 04-16-2024, 06:09 PM
                        4 responses
                        13 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by terofs, Today, 04:18 PM
                        0 responses
                        12 views
                        0 likes
                        Last Post terofs
                        by terofs
                         
                        Started by nandhumca, Today, 03:41 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post nandhumca  
                        Working...
                        X