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

is EMA above the current pps bool

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

    is EMA above the current pps bool

    Hello, I'm having trouble figuring out how this whole indicator thing works.
    Can someone show me an example of what this would look like:

    I want an indicator that simply returns a 1 if the conditions are met, and a zero if they are not met. (Boolian) based on the script that comes up when i am trying to make it, it looks like I can only graph stuff.

    Can someone post the code for a custom indicator that goes something like this:


    // if the EMA based on 5 minute bars over 9 periods is less than the current price

    if ( EMA(9) < Current price )
    return(true);
    else
    return(false);


    If i did want to graph this, it would just graph a zero or a 1, right? I'm mainly planning to use this in the market analyzer.


    Could you post what the entire ninja script would look like for what i described above (EMA 9 period based on 5 minute bars)
    Last edited by chris8sirhc; 05-01-2012, 08:54 AM.

    #2
    chris8sirhc,

    I would suggest using integers here.

    Also, the return command doesn't plot in this case, you would need to set a dataseries plot to 0 or 1.

    For example :

    if ( EMA(9)[0] > Close[0])
    {
    Plot0.Set(1);
    }
    else
    {
    Plot0.Set(0);
    }

    When you create an indicator you can setup some plots to assign these values into.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      gotcha, but im not necessarily trying to plot anything. I just want an indicator that can compare the EMA to the current price per share since the market analyzer cannot compare two variables.

      Does the plot function work in that way if im going to use the indicator only in the market analyzer (ie, its not actually ever going to be graphed)

      Could you post what the entire ninja script would look like for what i described above (EMA 9 period based on 5 minute bars)
      Last edited by chris8sirhc; 05-01-2012, 08:54 AM.

      Comment


        #4
        chris,

        Plots are what are accessible in the Market Analyzer, so this would be required for its use.

        Code:
                protected override void Initialize()
                {
                    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                    Overlay				= false;
                }
        
                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
        			if(CurrentBar < BarsRequired)
        			{
        				return;
        			}
                    // Use this method for calculating your indicator values. Assign a value to each
                    // plot below by replacing 'Close[0]' with your own formula.
                    if ( EMA(9)[0] > Close[0])
        			{ 
        				Plot0.Set(1);
        			}
        			else
        			{
        				Plot0.Set(0);
        			}
                }
        You would just need to go to Tools > New NinjaScript > Indicator > ensure you setup 1 plot named Plot0.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          "You would just need to go to Tools > New NinjaScript > Indicator > ensure you setup 1 plot named Plot0."

          This doesn't make sense, can you rephrase? The grammar is so bad, im not exactly sure what you mean??

          Comment


            #6
            Chris,

            Please left click the Tools menu, then go to "New NinjaScript". After doing this, please go to "Indicator". From here, you will have a wizard available. A couple pages over, accessible by using the "next" button, you will be able to setup plots. In this menu, please ensure that you have a "Plot0" setup. Once you do this, please continue clicking next until you have the NinjaScript editor accessible. Then, you will be able to copy the code I provided to your editor window.
            Last edited by NinjaTrader_AdamP; 05-01-2012, 09:29 AM.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              How do I get this new indicator to show up as an option to use in the market analyzer?

              Comment


                #8
                chris,

                Once you create an indicator and compile it, you should be able to access it in the market analyzer. The only exception to this would be if you have some NinjaScript issues. When you compile, does it give you any error messages?
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  oh, didnt know i had to compile. I just saved it, and it didnt show up. guess that explains it!

                  Comment


                    #10
                    chris,

                    Please don't hesitate to contact us should you require additional assistance.
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      Actually, what would be the best way to incorporate the closest call strike price above the current pps into an indicator?

                      Comment


                        #12
                        chris,

                        You want to add options data to an indicator?

                        This would probably require a multi-series indicator.



                        You're data provider would also need to offer the call strike price.
                        Adam P.NinjaTrader Customer Service

                        Comment


                          #13
                          Yeah, I will have a data feed that provides option prices.

                          Comment


                            #14
                            chris,

                            You can setup options prices in the Tools > Instrument Manager. You would need to map any relevant symbols for the instruments you want which could be provided by your data provider.

                            To add these to your strategy, I would suggest taking a look at the Tools > Edit NinjaScript > SampleMultiInstrument strategy. It is a sample of how to add a second instrument into your indicator or strategy.
                            Adam P.NinjaTrader Customer Service

                            Comment


                              #15
                              so how would I change this so that im comparing the current high of the candle with the current ema, && the previous candle high with the previous EMA, && the candle before that's high with the candle before thats EMA.

                              Basically I want to plot(1) if the EMA is above the high of the candle for the current, and last two candles. I dont want to compare it to the current price, or the close of the candles.

                              Basically I want to change the code below to test for the high of the candle instead of the closing price of the candle:

                              if ( (EMA(9)[0] < Close[0]) && (EMA(9)[-1] < Close[-1]) && (EMA(9)[-2] < Close[-2]) )
                              {
                              Plot0.Set(1);
                              }
                              else
                              {
                              Plot0.Set(0);
                              }
                              Last edited by chris8sirhc; 01-18-2013, 02:42 PM. Reason: more info

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by BarzTrading, Today, 07:25 AM
                              2 responses
                              14 views
                              1 like
                              Last Post BarzTrading  
                              Started by devatechnologies, 04-14-2024, 02:58 PM
                              3 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by tkaboris, Today, 08:01 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post tkaboris  
                              Started by EB Worx, 04-04-2023, 02:34 AM
                              7 responses
                              162 views
                              0 likes
                              Last Post VFI26
                              by VFI26
                               
                              Started by Mizzouman1, Today, 07:35 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X