Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  581 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  338 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  103 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  554 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  552 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X