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

Problem with a piece of code: Indi no longer plotting

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

    Problem with a piece of code: Indi no longer plotting

    Hi there,

    I am developping an indicator that draws dots, diamonds and squares in an indicator panel when certain conditions are met.

    The indi runs very well with this condition:

    Code:
    if (MACD(12, 20, 9).Diff[0] < Nul
                    && MACD(10, 15, 1)[0] < Nul
                    && MACD(5, 8, 1)[0] < Nul
                    && MACD(12, 20, 9).Diff[0] < MACD(12, 20, 9).Diff[1]
                    && MACD(10, 15, 1)[0] < MACD(10, 15, 1)[1]
                    && MACD(5, 8, 1)[0] < MACD(5, 8, 1)[1])
                {
                    DrawDiamond("My diamond2" + CurrentBar, false, 0, 0.5, Color.Red);
    }
    But when I add this piece of code (that checks for other conditions),
    Code:
    if (MACD(12, 20, 9).Diff[0] < MACD(12, 20, 9).Diff[1]
                    && MACD(10, 15, 1)[0] < MACD(10, 15, 1)[1]
                    && MACD(5, 8, 1)[0] < MACD(5, 8, 1)[1]
                    && Stochastics(7, 14, 3).K[0] <= P50)
               {
                    DrawDiamond("My diamond3" + CurrentBar, false, 0, 0.7, Color.Red);
                }
    nothing gets plotted anymore Where did I go wrong ?

    #2
    Stochastics(7, 14, 3).K[0] <= P50

    What is P50? Is it a variable? Or do you mean K[0]<=50?

    Comment


      #3
      Hello Spinn,

      Thank you for your post.

      I agree with Tom299, we would need to know what the p50 value represents. Is it supposed to be a value you set elsewhere or really just the value of 50?

      Comment


        #4
        Hi guys, and thanks for trying to help !


        P50 is indeed a value I defined in 'Variables', like so
        Code:
        private int p50 = 50; // Default setting for P50
        It is also present in 'properties' like this:

        Code:
        public int P50
                {
                    get { return p50; }
                    set { p50 = Math.Max(50, value); }
                }
        Last edited by Spinn; 03-09-2016, 10:05 AM.

        Comment


          #5
          So this is the code that makes the whole indicator go silent (draws nothing anymore when I add the second part, the close long)

          Code:
          //OPEN LONG ???
                      if (MACD(12, 20, 9).Diff[0] > Nul
                          && MACD(10, 15, 1)[0] > Nul
                          && MACD(5, 8, 1)[0] > Nul
                          && MACD(12, 20, 9).Diff[0] > MACD(12, 20, 9).Diff[1]
                          && MACD(10, 15, 1)[0] > MACD(10, 15, 1)[1]
                          && MACD(5, 8, 1)[0] > MACD(5, 8, 1)[1])
                      {
                          DrawDiamond("My diamond" + CurrentBar, false, 0, 0.5, Color.Lime);
                      }
                      // CLOSE LONG ???
                      //if (Close[0] < EMA(200)[0])
                      //(MACD(12, 20, 9).Diff[0] < MACD(12, 20, 9).Diff[1])
                      else if (MACD(10, 15, 1)[0] < MACD(10, 15, 1)[1])
                      //    && MACD(5, 8, 1)[0] < MACD(5, 8, 1)[1]
                      //    && Stochastics(7, 14, 3).K[0] <= P50)
                      {
                          DrawDot("My dot3" + CurrentBar, false, 0, 0.7, Color.Red);
                      }
          The problem is situated in the //close long section: if I uncomment the line
          Code:
          //if (Close[0] < EMA(200)[0])
          and comment the else if, then everything works, vice versa it does not Same with the other lines (I used the opposite statements in the //OPEN LONG section, is that part of the problem perhaps ?)

          I tried 'if', 'else if' and 'else', but everything fails.

          Please help
          Last edited by Spinn; 03-10-2016, 09:55 AM.

          Comment


            #6
            Hello Spinn,

            Thank you for your response.

            What if you try the followign condition and check the Output window? Do you see an values?
            The Output window is found under Tools > Output.
            Code:
            if (MACD(10, 15, 1)[0] < MACD(10, 15, 1)[1])
            && MACD(5, 8, 1)[0] < MACD(5, 8, 1)[1]
            && Stochastics(7, 14, 3).K[0] <= P50)
            {
            Print(Time[0] + " Condition is valid.");
            }
            For information on printing please visit the following link: http://ninjatrader.com/support/forum...58&postcount=1

            Comment


              #7
              Thanks Patrick !

              I tried, but it wouldn't compile, so I commented out everything except for the line
              Code:
              if (MACD(10, 15, 1)[0] < MACD(10, 15, 1)[1])
              (and the print-statement obviously)
              The indi then compiles, but nothing gets plotted

              Comment


                #8
                Hello Spinn,

                Thank you for your response.

                So the condition you are trying to implement does not compile?

                Can you attach your .cs file to your response?
                You can attach your indicator to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your Indicator > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.

                Comment


                  #9
                  I actually had to copy/past the source code because I kept running into compiling issues while trying to export (error CS0118 on lines 63, 67, 72, 76 and 82)

                  So please find the .txt file in attachment

                  Note: the commented line
                  Code:
                  //DrawText("test2", false, "EMA 60",0,0.2, 0, Color.Black, StringAlignment.Far);
                  is the issue I tried to address in this post: http://ninjatrader.com/support/forum...ad.php?t=83667 (will test the solution offered there tomorrow!)
                  Attached Files

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by CortexZenUSA, Today, 12:53 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by CortexZenUSA, Today, 12:46 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by usazencortex, Today, 12:43 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post usazencortex  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  168 responses
                  2,266 views
                  0 likes
                  Last Post sidlercom80  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  3 responses
                  13 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X