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 to return 1 or 0 in the market analyzer

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

    indicator to return 1 or 0 in the market analyzer

    Dear NinjaTrader support team,

    I am building the custom indicator and will use it in the market analyzer for stock screening. I'll want this indicator to come up with 1 or 0 based on the predefined conditions.
    • What would be a rough syntax/method for that? (how to say "if x>y, then return 1 in the market analyzer, if not then return 0 ")


    Are there any changes to be made to these lines or settings below them:
    • protected override void OnBarUpdate()
    • protected override void Initialize()


    Thank you

    ionaz

    #2
    ionaz,

    I am happy to assist you.

    If you create an indicator with a single Plot in it, you can simply create two conditions. Suppose we called our plot Plot0.

    In OnBarUpdate()

    Code:
    if( condition1 )
    {
      Plot0.Set(1);
    }
    else if ( condition2 )
    {
      Plot0.Set(0);
    }
    Then when you add it to the Market Analyzer you can select which "Plot" you want it to display in the Market Analyzer. If there is only one plot it will default to this.

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Dear AdamP,

      once I enter
      if( condition1 ) { Plot0.Set(1); } else if ( condition2 ) { Plot0.Set(0); }

      I get an error message saying:
      "The name Plot0 does not exist in the current context"

      I guess it's because I need to announce Plot0 as a variable.
      Could you please tell me how that should look like and where to do it (below onbarupdate or below initialize)

      Thanks!

      ionaz

      Comment


        #4
        ionaz, for the Plot you would want to have this line in your Initialize() method :

        Code:
        Add(new Plot(Color.Green, PlotStyle.Line, "Plot0"));
        And then this part in your Properties section :

        Code:
        [Browsable(false)]
        [XmlIgnore()]
                public DataSeries Plot0
                {
                    get { return Values[0]; }
                }
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hello Ninjatrader,

          First of all, thank you very much. It works. Market Analyzer returns 1 or 0.

          I have a few questions, because I want to understand this.
          • after I added that plot method under the initialize my charts became squashed. This line is plotted at the y value of 1. So my question is, how can I get rid of this line on the chart so that chart looks normal again? How is it related to my need for Market Analyzer to return 1/0 values?
          • could you please also explain why do I need this part in the properties?
            [Browsable(false)] [XmlIgnore()] public DataSeries Plot0 { get { return Values[0]; } }



          I am relly curious and want to understand and learn this, that's why I am asking.


          Thank you

          Comment


            #6
            Glad to hear ionaz, that would be expected for the plot, you set a value to use and this would be visualized here as well on your charts, hence the squashed effect. To avoid this use the indicator then on another panel or choose the overlay scale for example.

            The properties part links the public series property to the main indicator Value series, it would be the series actually holding your stored values, while the Add() Plot in your Initialize only determines how this would be visualized.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              ionaz, for the Plot you would want to have this line in your Initialize() method :

              Code:
              Add(new Plot(Color.Green, PlotStyle.Line, "Plot0"));
              And then this part in your Properties section :

              Code:
              [Browsable(false)]
              [XmlIgnore()]
              public DataSeries Plot0
              {
              get { return Values[0]; }
              }
              I'm trying to create a similar indicator; if (position.MarketPosition == MarketPosition.Flat) return 0, else if (PositionAccount.MarketPosition != MarketPosition.Flat) return 1.

              I don't see Initialize() when creating an indicator in Ninjascript Editor. Where would I plug these lines in NT8? Here is what I have so far:

              protected override void OnBarUpdate()
              {
              if (position.MarketPosition == MarketPosition.Flat)
              {
              Plot0.Set(0);
              }
              else
              {
              Plot0.Set(1);
              }
              }

              }
              }

              Comment


                #8
                Hello andr3i,

                Thanks for your post.

                You are posting in the NinjaTrader7 forums and the code between NinjaTrader7 and NinjaTrader8 is not compatible.

                In NinjaTrader8 you would add your plot in the OnStateChange() section under State.SetDefaults.

                You would not use Plot0.Set(). Instead you would assign like this: Plot0[0] = 0;

                If you have further questions, please create a new topic in the appropriate NinjaTrader8 forums to help users keep these forums organized, thanks for your understanding.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  did you manage to make this indicator ?

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by gentlebenthebear, Today, 01:30 AM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by Aviram Y, Today, 05:29 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by cls71, Today, 04:45 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by TradeForge, Today, 02:09 AM
                  1 response
                  22 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by elirion, Today, 01:36 AM
                  2 responses
                  14 views
                  0 likes
                  Last Post elirion
                  by elirion
                   
                  Working...
                  X