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 with arrows

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

    Indicator with arrows

    Hello,

    I have created an indicator that combines 2 different indicators and Stochastic to plot up and down arrows when certain conditions are met. For the most part, it works very well, with a couple minor exceptions. So the indicator will occasionally post an arrow when the condition(s) for the Bollinger Bands are true, but the Stochastic is false. I would like it to only plot an arrow when ALL conditions are true. Second, I have noticed that it does not plot an arrow on ALL bars when ALL conditions being true, and only a select few instead. I would like an arrow to be plotted on each bar when all conditions are true, even if there are multiple bars in a row.

    Any help or suggestions would help,

    Thank you,
    Chris

    #2
    Hello Chris,

    To understand why a script is behaving as it is, it is necessary to debug the script by adding prints that print all values for all variables used in the condition along with the time.

    Below is a link to a forum post with a helpful video that demonstrates.


    Please print all values and the time of the bar, include the output and the print code, and I will be happy to assist you in analyzing the output.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you Chelsea.

      How would I print the value of the Stochastic K line in the Print output? So far, all I can get it to do is print the price value of the current bar instead of the Stochastic value. I am trying to see if Stochastic is below 20 on current bar.

      Thank you,
      Chris

      Comment


        #4
        Hello Chris,

        An example of printing a Stochastic K plot value:

        Code:
        Print(Stochastics(4, 13, 7).K[0]);
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea,

          So I used your example, and it is still printing out the bar value instead of the value of the K Stochastic line. Here is how I have the current Print set up.

          Print(string.Format("{0} ; BollingerLow: {1} > PriceLow {1} ; StochasticK: {1} < Value(20)",
          Time[0], Bollinger2.Lower[0], Low[0], Stochastics(3,14,7).K[0]));

          Thank you again,
          Chris
          Last edited by chrisca; 12-27-2017, 04:45 PM.

          Comment


            #6
            Hello Chris,

            You have modified the print I have suggested. Does the original print I suggested print the correct value?

            You are not printing the Stochastics value in your print.

            You are printing the time, the Bollinger2.Lower[0], the Bollinger2.Lower[0] again, the Bollinger2.Lower[0] again, and then the text 'Value(20)'.

            Are you meaning to increment your indexes in your print?

            "{0} ; BollingerLow: {1} > PriceLow {2} ; StochasticK: {3} < Value(20)"

            Below is a publicly available link to the Microsoft documentation on String.Format().
            Converts the value of objects to strings based on the formats specified and inserts them into another string. If you are new to the String.Format method, see Get started with the String.Format method for a quick overview.


            As well as a link to a video that demonstrates using string.Format().
            Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.3:11 Creating a New NinjaScript Strategy13:52 Analyz...
            Last edited by NinjaTrader_ChelseaB; 12-27-2017, 05:01 PM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Chelsea,

              Thank you for the input. I managed to get it to work. According to the Print, on a specific bar I am looking at, the conditions were true, yet an arrow was not generated. Any ideas on that? I can send you the print if it would help.

              Thank you,
              Chris

              Comment


                #8
                Hello Chris,

                I'm happy to take a look with you.

                Please include the entire condition set and action block with your post along with the output from the output window.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Chelsea,

                  So here is my condition and action set:

                  if ((Stochastics1.K[0] < 20) && (CrossBelow(Low, Bollinger1.Lower, 1)))
                  {
                  Draw.ArrowUp(this, @"RedGreenLight Arrow up_1"+CurrentBar,
                  false, 0, (Low[0] + (-2 * TickSize)) , Brushes.Lime);
                  }

                  Here is the output that I am looking at:

                  12/21/2017 12:55:00 PM PriceLow[0] 2687.25 < BollingerLower3[0] 2687.64473446016
                  & StochasticK 12.8571428571427 < 20

                  12/21/2017 1:00:00 PM PriceLow[0] 2686.75 < BollingerLower3[0] 2686.89587637759
                  & StochasticK 11.6666666666665 < 20

                  12/28/2017 6:55:00 AM PriceLow[0] 2684.25 < BollingerLower3[0] 2684.77658497881
                  & StochasticK 12.6518218623478 < 20

                  Thanks again,
                  Chris
                  Last edited by chrisca; 12-28-2017, 09:12 AM.

                  Comment


                    #10
                    Hello Chris,

                    The print does not contain all of the values used in the condition set.

                    What is the code of the print?

                    Is the print one line above the condition set?

                    The condition also has a condition to require a crossover, however, this information is not in the print.

                    Please include all values for all variables for all conditions used in the condition set.

                    (you could just print if the crossbelow is evaluating as true)

                    Then include the code of the print and the output from the output window.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Chelsea,

                      I have the code of the Print just above // Set 1 so it will print on every bar. Here is the coding for the Print:

                      Print(Times[0][0].ToString() + @" PriceLow[0] " + Low[0].ToString() + @" CrossBelow
                      BollingerLower3[0] " + Bollinger2.Lower[0].ToString() + " " + CrossBelow(Low,
                      Bollinger2.Lower, 0).ToString() + @" & StochasticK " + Stochastics1.K[0].ToString() +
                      @" < " + 20.ToString());

                      I know I am missing something in the Print logic though because it lists the Price crossbelow as False for every bar. Here is the new output:

                      This had a crossover and should be listed as True:

                      12/28/2017 5:05:00 AM PriceLow[0] 2686.75 CrossBelow BollingerLower3[0]
                      2686.99392046864 False & StochasticK 13.0952380952377 < 20

                      This one should be True as well and an Arrow should have been plotted, but nothing was:

                      12/28/2017 6:55:00 AM PriceLow[0] 2684.25 CrossBelow BollingerLower3[0]
                      2684.77658497881 False & StochasticK 12.6518218623478 < 20

                      Comment


                        #12
                        Hello Chris,

                        This lets you know that the condition is not evaluating as true and this is why no drawing object appears.

                        So the next thing to find is why the crossbelow is evalutating as false.

                        Print the value of the Low on the previous bar and ensure this is greater than the Bollinger2.Lower on the previous bar and print the value of the Low on the current bar and ensure this is less than the value of the Bollinger2.Lower on the current bar.

                        Below is a link to a video that demonstrates.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Ok Chelsea I will do that.

                          The Print is listing every cross below as false however, even if the indicator plots an arrow. Thats why I feel like False on the Print is not reading properly.

                          What if the previous bar and current bar both cross below the Bollinger Band? I would like them both to print an arrow if the conditions are True.

                          Thank you,
                          Chris

                          Comment


                            #14
                            Hello Chris,

                            I'm not understanding how you are describing a cross on the most recent bar.

                            If both the current bar of series 1 and the previous bar of series 1 are both less than series 2, then this is not a cross.. Its just less than..

                            However, it would be highly unlikely for C# to not evaluate the values properly..

                            if 'CrossBelow(Low, Bollinger2.Lower, 0).ToString()' prints false, I would expect any condition that uses that code to also evaluate as false and not trigger.

                            Are you certain its that condition thats triggering and not another?

                            Last, I would expect that this cross condition would always be false.
                            You have set the lookback period to 0. You are looking for a cross to happen within 0 bars. There can't be a cross without at least 1 previous bar. So this would always be false.

                            It would be highly unlikely this condition is triggering any action.

                            Below is a publicly available link to the help guide on CrossBelow().
                            Last edited by NinjaTrader_ChelseaB; 12-28-2017, 11:00 AM.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Chelsea,

                              I am wanting an up arrow to be placed if the current bar crosses below the Bollinger Band, and when the Stochastic K line is less than 20. The indicator is plotting correctly for 90% of the bars that meet those conditions. However, there is a few rogue bars that the indicator does not trigger. Would I have better results if I set the current bar Low to be Less instead of CrossBelow? As for the look back period, I used 0 with the thought of that means it will look at the current bar and not the previous bar, which may be wrong given what you are saying.

                              Chris
                              Last edited by chrisca; 12-28-2017, 11:12 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by LawrenHom, Today, 10:45 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post LawrenHom  
                              Started by love2code2trade, Yesterday, 01:45 PM
                              4 responses
                              28 views
                              0 likes
                              Last Post love2code2trade  
                              Started by funk10101, Today, 09:43 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post funk10101  
                              Started by pkefal, 04-11-2024, 07:39 AM
                              11 responses
                              37 views
                              0 likes
                              Last Post jeronymite  
                              Started by bill2023, Yesterday, 08:51 AM
                              8 responses
                              44 views
                              0 likes
                              Last Post bill2023  
                              Working...
                              X