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

Referencing another indicator

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

    Referencing another indicator

    Hello

    (coding newbie - but studying a lot!!)

    I am working to change the color of the bar when the price
    • Closes Bullish
    • Closes Above SMA
    • Closes Above Parabolic SAR
      [*}Other items, but not necessary to list them


    I am running into an issue when I am trying to reference the ParabolicSAR in this indicator.

    in the OnBarUpdate() section, I have this written:

    Code:
    if(CurrentBar < smaPeriod) return;
    
    double smaValue = SMA (smaPeriod)[0];
    bool sarValue = true;
    
    sarValue = (Close > ParabolicSAR(.02 , .2 , .02)) ; 
    
    if ( Close[0] > Open[0]
    && Close[0] > smaValue
    && sarValue)
    
    {
    BarColor = Color.Blue;
    }
    The compile error that I receive with this is, "Operator '>' cannot be applied operands of type 'NinjaTrader.Data.IDataSeries' and 'NinjaTrader.Indicator.ParabolicSAR'

    I hope my explanation of what I am trying to do, what I have done, and what my problem is has been clear enough. Could you please let me know what I have done wrong, how to fix it, and any explanation to help fill in the gaps in my learning would be greatly appreciated.

    Thank you

    #2
    You might try Close[0] instead of Close. See if that works.

    Dan
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      Thank you for the suggestion. I have entered that in the code and am receiving the same error message.

      Here is an update to the code:

      Code:
              
      			if(CurrentBar < smaPeriod) return; 
      			
      			double smaValue = SMA(smaPeriod)[0];
      			bool sarValue = true;
      			
      			sarValue = (Close[0] > ParabolicSAR(.02,.2,.02));
                  
      			
      			if(Close[0] > Open[0]
      				&& Close[0] > smaValue
      				&& sarValue)
      			{
      				BarColor = Color.Blue;
      			}

      Comment


        #4
        Hello jg123,

        Welcome to the NinjaTrader Support Forums!

        This is due to trying to compare two Series to see if they are greater than one another. You would want to access the value of each Data Series using the greater than ">" like eDanny stated.

        So change:

        sarValue = (Close > ParabolicSAR(.02 , .2 , .02));


        To:

        sarValue = (Close[0] > ParabolicSAR(.02 , .2 , .02)[0]);

        Here is a thread that you may view that goes over using brackets "[]" for more information.
        JCNinjaTrader Customer Service

        Comment


          #5
          There is also an error in this statement:

          Code:
          if ( Close[0] > Open[0]
          && Close[0] > smaValue
          && sarValue)
          The last && sarValue will not work as sarValue is not a bool. I assume it would need to be:

          && Close[0] > sarValue)

          Comment


            #6
            Thank you

            I had not placed a [0] behind my parabolic sar information. That fixed it.

            There are some other issues that I am running into and will post that in another reply in this same thread.

            Comment


              #7
              This has all helped quite a bit. Thank you.

              Here is the next issue that I am running into.

              I am attempting to make it also close outside of the MAEnvelopes (MAE).

              I added a bit of information such as:

              bool maEnvValue = true;
              double maEnvPerc = 1.0;
              double maEnvPeriod = 25;

              In the OnBarUpdate() I now have:

              Code:
              {
              			if(CurrentBar < smaPeriod) return; 
              			if(CurrentBar < maEnvPeriod) return;
              			
              
              			
              			sarValue = (Close[0] > ParabolicSAR(.02,.2,.02)[0]);
              			maEnvValue = (Close[0] > MAEnvelopes(maEnvPerc,3,maEnvPeriod).High[0]);
              			
              			smaValue = SMA(smaPeriod)[0];
                          
              			
              			if(Close[0] > Open[0]
              				&& Close[0] > smaValue
              				&& sarValue
              				&& maEnvValue)
              			{
              				BarColor = Color.Blue;
              			}
                      }
              the expectation is that it will change the color of the candle when the price also closes above the upper band of the MAE. The Plot output is "Upper" (default MAE indicator within NT).

              There are two more elements that I will need with this indicator that I can not yet figure out how to create, but will let you know if I am not able to come up with a solution.

              Comment


                #8
                Also, please feel free to direct me to specific spots in other resources to learn these types of information. I do not want to bombard the forum with information that I am able to learn on my own. I just have not seen the answers to these types of specific questions in any other manuals yet.

                Comment


                  #9
                  Hello jg123,

                  For the "Upper" Data Series of the MAEnvelopes() method you may want to use the "MAEnvelopes(maEnvPerc,3,maEnvPeriod).Upper[0]" instead of High to get the Upper Data Series.

                  Another resource that you may view to help learn NinjaScript is going to be our Help Guide where you may view informational items and tutorials at the following link.
                  Last edited by NinjaTrader_JC; 03-04-2014, 02:11 PM.
                  JCNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by maybeimnotrader, Today, 05:46 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post maybeimnotrader  
                  Started by quantismo, Today, 05:13 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post quantismo  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  8 responses
                  166 views
                  0 likes
                  Last Post jeronymite  
                  Started by cre8able, Today, 04:22 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post cre8able  
                  Started by RichStudent, Today, 04:21 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post RichStudent  
                  Working...
                  X