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

Positive or negative opening price of the previous day

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

    Positive or negative opening price of the previous day

    How can I plot whether the previous day's opening price is positive or negative in the Market Analyzer?

    #2
    Hello ラリー,

    Thank you for your note.

    Please clarify, what are you comparing the previous day's opening price to in order to determine if it is positive or negative?

    I look forward to assisting you.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.

      It will be the first bar of the 1 min.

      In the attached image here, the first bar is a shadow, but I want to display them in the market analyzer.
      The same goes for the positive bars.​
      Attached Files

      Comment


        #4
        Hello ラリー,

        Thank you for clarifying.

        I am not aware of an existing Market Analyzer column or indicator that would accomplish this. That being said, this should be possible using a custom NinjaScript add-on. If you have a programming background, our team may provide you links to samples that would help you write the add-on yourself, or we can provide you with resources to find a programmer to create the add-on for you.

        Please let me know if one of these options interests you and I would be glad to follow up accordingly.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your reply.

          Please provide links and resources.​

          Comment


            #6
            Hello ラリー,

            Thank you for your reply.

            For any user getting started with NinjaScript, I recommend reviewing the following link which has many useful NinjaScript and C# resources:


            There are many ways you could show in the Market Analyzer if the previous day's open price was a positive bar or a negative bar. One way to do this is to code a custom indicator which may then be added via an Indicator column in the Market Analyzer. I have created a snippet that checks if IsFirstBarOfSession is true and whether the Close of that bar is greater than or less than the Open of that bar. It then sets a bool, positiveOpen, to true or false depending on whether the bar was positive or negative. I created a Series<double> called openBar that equals 1 when the positiveOpen bool is true and -1 when the bool is false. Then, the plot value is set based on the value of openBar, and the plot colors are LimeGreen or Red based on if it is greater than 0 or less than 0. You could add this indicator to a Market Analyzer column and set the "Type" dropdown to bar graph in order to view the green or red from the plot. Here is the snippet:

            Code:
            private Series<double> openBar;
            private bool positiveOpen;​
            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            AddPlot(new Stroke(Brushes.Black, 2), PlotStyle.Bar, "OpenBarPlot");
            }
            else if (State == State.DataLoaded)
            {
            openBar = new Series<double>(this);
            }
            }
            
            protected override void OnBarUpdate()
            {
            if (CurrentBar < 1)
            return;
            if (Bars.IsFirstBarOfSession && Close[0] > Open[0])
            positiveOpen = true;
            if (Bars.IsFirstBarOfSession && Close[0] < Open[0])
            positiveOpen = false;
            
            if (positiveOpen == true)
            openBar[0] = 1;
            if (positiveOpen == false)
            openBar[0] = -1;
            
            OpenBarPlot[0] = openBar[0];
            
            if (openBar[0] > 0)
            PlotBrushes[0][0] = Brushes.LimeGreen;
            else if (openBar[0] < 0)
            PlotBrushes[0][0] = Brushes.Red;
            else
            PlotBrushes[0][0] = Brushes.Black;
            }
            Here is what it looks like if I apply it to the Market Analyzer as a bar graph:


            Please try these ideas out on your own and let us know if we may be of further assistance.​​
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Thank you for your reply and for providing the link.

              I tried the code you provided after creating a new indicator file, but it outputs an error.
              What did I do wrong?
              Attached Files

              Comment


                #8
                Hello ラリー,

                Thank you for your reply.​

                Did you add the plot via the New Indicator wizard? Any plots added require additional logic in the Properties region of the script, and the wizard adds this logic for you. For example:

                Code:
                [Browsable(false)]
                [XmlIgnore]
                public Series<double> OpenBarPlot
                {
                get { return Values[0]; }
                }

                It is mentioned in the Tips for AddPlot() that we suggest using the NinjaScript wizard to generate plots:


                Please try creating the indicator again and add the plot in the wizard and this should resolve the errors.

                THank you for your time and patience.
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you for your reply.

                  I did not add the plot in the wizard.
                  However, I created a new indicator and added a plot in the wizard, which resolved some errors, but on line 75 I get "The name OpenBarPlot does not exist in the current context".​
                  Attached Files

                  Comment


                    #10
                    Hello Larry,

                    Thank you for your reply.

                    I see you added a plot called "My" but I suspect that "OpenBarPlot" was still copied/pasted and not created via the wizard. If you look near the bottom of your script, the "My" plot should have some information in the Properties region of your script. "OpenBarPlot" will need the same information added in order to resolve the error message.

                    Please let us know if we may be of further assistance.
                    Emily C.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you for your reply.

                      I have created the indicator file from here (attached) and copied and pasted the code you provided within Ninja Script, but are you saying that the attached screenshot here is not the wizard?

                      Also, I understand that the same information needs to be added to the "OpenBarPlot", is this done within Ninja Script?​
                      Attached Files

                      Comment


                        #12
                        Hello ラリー,

                        Thank you for your reply.​​

                        Yes, the image in your screenshot is from the Indicator wizard. The code snippet I provided was not intended to just copy/paste and then work right away; it was provided as a starting point and an example of the logic you could use while creating your own indicator. It is meant to be used as an educational resource so that you may develop the indicator yourself. If you would prefer, we could gladly provide you with more information to contact a NinjaScript consultant for hands-on educational services or a developer who could code this for you.

                        The same information for "OpenBarPlot" could be done within NinjaScript (per my response in post number 8), although it would be more simple to start a new indicator and add a plot with that name from the Wizard as shown in your screenshot, then you could use the snippet I provided as an idea when coding within the indicator that you create.

                        Thank you for your patience.
                        Emily C.NinjaTrader Customer Service

                        Comment


                          #13
                          Thank you for your reply.

                          The error seems to be resolved, but nothing is displayed when set to bar graph.

                          The other setting, when using the cell condition, displayed colors based on the condition, but not as shown in the screenshot you provided.

                          Attached Files

                          Comment


                            #14
                            Code:
                            名前空間 NinjaTrader.NinjaScript.Indicators
                            { 
                            public class MyCustomIndicator : Indicator 
                            { 
                            
                            [Browsable(false)] 
                            [XmlIgnore] 
                            public Series<double> OpenBarPlot 
                            { 
                            get { return Values[0]; } 
                            }
                            
                            
                            プライベート Series<double> openBar; 
                            private bool positiveOpen; 
                            
                            protected override void OnStateChange() 
                            { 
                            if (State == State.SetDefaults) 
                            { 
                            Description = @"新しいカスタム インジケーターの説明をここに入力してください。"; 
                            名前 = "MyCustomIndicator"; 
                            計算 = Calculate.OnBarClose; 
                            IsOverlay = false; 
                            DisplayInDataBox = true; 
                            DrawOnPricePanel = true; 
                            DrawHorizo​​ntalGridLines = true;
                            DrawVerticalGridLines = true; 
                            PaintPriceMarkers = true; 
                            ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; 
                            //新しい市場データ イベントごとに累積するカスタム値が指標に必要な場合は、このプロパティを無効にします。
                            //詳細については、ヘルプ ガイドを参照してください。
                            IsSuspendedWhileInactive = true; 
                            //AddPlot(Brushes.Orange, "My"); 
                            
                            
                            AddPlot(new Stroke(Brushes.Black, 2), PlotStyle.Bar, "OpenBarPlot"); 
                            } 
                            else if (State == State.DataLoaded) 
                            { 
                            openBar = new Series<double>(this); 
                            } 
                            }
                            
                            保護されたオーバーライド void OnBarUpdate() 
                            { 
                            
                            
                            
                            if (CurrentBar < 1) 
                            
                            return; 
                            if (Bars.IsFirstBarOfSession && Close[0] > Open[0])
                            ポジティブオープン = 真; 
                            if (Bars.IsFirstBarOfSession && Close[0] < Open[0]) 
                            positiveOpen = false; 
                            
                            if (positiveOpen == true) 
                            openBar[0] = 1; 
                            if (positiveOpen == false) 
                            openBar[0] = -1; 
                            
                            OpenBarPlot[0] = openBar[0]; 
                            
                            
                            if (openBar[0] > 0) 
                            PlotBrushes[0][0] = Brushes.LimeGreen; 
                            そうでなければ (openBar[0] < 0) 
                            PlotBrushes[0][0] = Brushes.Red; 
                            そうでなければ
                            PlotBrushes[0][0] = Brushes.Black; 
                            
                            // カスタム インジケーター ロジックをここに追加します。
                            }
                            
                            #領域プロパティ
                            
                            [Browsable(false)] 
                            [XmlIgnore] 
                            public Series<double> My 
                            { 
                            get { return Values[0]; } 
                            } 
                            #エンドリージョン
                            
                            } 
                            }
                            Last edited by ラリー; 11-29-2022, 05:09 AM.

                            Comment


                              #15
                              Hello ラリー,,

                              Thank you for that information.

                              This may have to do with your bar graph settings; there is a "Max bar graph display value" and I believe it defaults to 1000. Since this is only plotting -1 or 1, that would barely show up on a scale of 1000. Please try setting this to a smaller number, like 5, then apply the changes and see if this resolves your question about the bar graph.

                              Please let me know if I may be of further assistance.
                              Emily C.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GLFX005, Today, 03:23 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post GLFX005
                              by GLFX005
                               
                              Started by XXtrader, Yesterday, 11:30 PM
                              2 responses
                              11 views
                              0 likes
                              Last Post XXtrader  
                              Started by Waxavi, Today, 02:10 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by TradeForge, Today, 02:09 AM
                              0 responses
                              14 views
                              0 likes
                              Last Post TradeForge  
                              Started by Waxavi, Today, 02:00 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Working...
                              X