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

Basic coding script questions

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

    #46
    Hello sandman,

    Thank you for your update on this matter.

    Is CalculateOnBarClose set to True or False? If set to True, please set to False and test again.

    For information on CalculateOnBarClose please visit the following link: http://www.ninjatrader.com/support/h...onbarclose.htm

    Please let me know if you have any questions or if CalculateOnBarClose is already set to False.

    Comment


      #47
      Thanks for checking Patrick.

      I do have this in the code already:

      protected override void Initialize()
      {
      CalculateOnBarClose = false;
      }

      Anything else I could check?

      sandman

      Comment


        #48
        Hello sandman,

        Thank you for your response.

        Try using Print() statements for each condition that would change the color. Then open up your Output Window (Tools > Output Window) and check to see if you get prints when the conditions should return true.

        For information on Print() please visit the following link: http://www.ninjatrader.com/support/h.../nt7/print.htm
        For information on debugging your NinjaScript code please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3418

        Please let me know if you have any questions.

        Comment


          #49
          Hi Patrick, thank you. I don't know yet how to use that print command. But

          I worked out a colored LinReg with the color changing depending on whether it is rising or falling. In the code for that is something "if rising" then color it green "else falling" then color it red. In other words "if" and "else".

          For the colored candles which I am trying to code now I only have an "if", i.e. if all my conditions for rising are met then color the candle green. But I have no "else" statement.

          // Condition set 1
          if (Close[0] > Opens[0][0]
          && LinReg(BarsArray[0],4)[0] > LinReg(BarsArray[0],4)[1]
          && LinReg(BarsArray[0],9)[0] > LinReg(BarsArray[0],9)[1]
          && LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],4)[1]
          && LinReg(BarsArray[1],9)[0] > LinReg(BarsArray[1],9)[1] )
          {
          BarColor = upCandle_Color;
          }

          Could adding this do the trick like this:

          else
          {
          BarColor = Color.Empty;
          }

          And then do the same for the falling condition:

          // Condition set 2
          if (Close[0] < Opens[0][0]
          && LinReg(BarsArray[0],4)[0] < LinReg(BarsArray[0],4)[1]
          && LinReg(BarsArray[0],9)[0] < LinReg(BarsArray[0],9)[1]
          && LinReg(BarsArray[1],4)[0] < LinReg(BarsArray[1],4)[1]
          && LinReg(BarsArray[1],9)[0] < LinReg(BarsArray[1],9)[1])
          {
          BarColor = downCandle_Color;
          }
          else
          {
          BarColor = Color.Empty;
          }

          or am I overlooking something?

          sandman

          Comment


            #50
            Hello sandman,

            Thank you for your update on this matter.

            I would test each possibility to understand how the if and else conditions work with one another. For information on if and else please visit the following link: http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx

            From what you have detailed the else statement appears to be the missing element here. Please try this on your end and advise if this corrects the matter.

            Comment


              #51
              Thanks Patrick.

              I tried out using an "else" statement but that did not work, so I added an
              "else if" statement and included in that just one of the conditions. Like this:

              if (Close[0] > Opens[0][0]

              && LinReg(BarsArray[0],4)[0] > LinReg(BarsArray[0],4)[1]
              && LinReg(BarsArray[0],9)[0] > LinReg(BarsArray[0],9)[1]
              && LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],4)[1]
              && LinReg(BarsArray[1],9)[0] > LinReg(BarsArray[1],9)[1] )
              {
              BarColor = upCandle_Color;
              }

              else if (Close[0] > Opens[0][0])
              {
              BarColor = Color.Empty;
              }

              That seems to work out fine because when the conditions are met the bar is colored and it correctly "loses" the coloration when the conditions change while the bar is in progress. That is what I had wanted.

              Sofar so good. See the attached image. The bars which I encircled were actually colored dark red when they were being created. But when I re-applied the same indicator they disappeared. What makes them disappear in historic mode?

              sandman
              Attached Files

              Comment


                #52
                Originally posted by sandman View Post
                Sofar so good. See the attached image. The bars which I encircled were actually colored dark red when they were being created. But when I re-applied the same indicator they disappeared. What makes them disappear in historic mode?
                sandman
                Additional image 2 attached. Here I applied the same indicator but not with colored bars but a colored background stripe. While the indicator draws the background color and it stays, the colored bars "disappeared". Is there an explanation for that?

                sandman
                Attached Files

                Comment


                  #53
                  Hello sandman,

                  Thank you for your response.

                  May I take a look at this code on my end? You can send a 'toy' version if you wish as long as it has the code used for the bars.

                  If you prefer you can send your NinjaScript file to support[at]ninjatrader[dot]com with 'ATTN: Patrick' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=51627

                  I look forward to your response.

                  Comment


                    #54
                    When I use this line of code for a secondary bars object it works okay but is not perfect yet for my taste.

                    LinReg(BarsArray[1],4)[0] > LinReg(BarsArray[1],4)[1]

                    Now I want to see if when I use "Rising" I could get different and better results. I tried this but it is not being accepted ("cannot convert from double to NT.Data.IDataSeries-whatever that means"):

                    Rising(LinReg(BarsArray[1],4)[0]))

                    Any tip of what I have to correct here?

                    sandman

                    Comment


                      #55
                      sandman, you would need to pass a series to Rising(), not a double value so please try -

                      Rising(LinReg(BarsArray[1],4)))
                      BertrandNinjaTrader Customer Service

                      Comment


                        #56
                        Bertrand. That worked fine and now it does exactly what it is supposed to when it is supposed to do it. Thanks, also for your patience

                        sandman

                        Comment


                          #57
                          I have this in my code to color a 1Minute candle when that candle starts below or on the SMA and closes above it.

                          Close[0] > Opens[0][0]
                          && Close[0] > SMA(BarsArray[0],20)[0]
                          && Low[0] <= SMA(BarsArray[0],20)[0]

                          However, I would like to be more generous with where the low is in relation to that SMA and tell it that I am also okay even if the low is within 3 ticks above that SMA (of course maintaining that the Close has to be larger than the Open).

                          To do that I believe I can use the offset function.

                          Questions:
                          1. Do I have to express the offset on the Low side or on the SMA side, or does it even matter e.g.:
                          (Low[0]) 3 * TickSize
                          or is it:
                          (SMA(BarsArray[0],20)[0]) 3 * TickSize

                          2. If I would use not ticks as offset but percentage
                          (SMA(20)[0]) * (1 + 23))

                          - what is the 23 a percentage of?

                          sandman

                          Comment


                            #58
                            Sandman,

                            1) it doesnt matters ; (Low[0]) +/- 3 * TickSize will work fine
                            ....or (SMA(BarsArray[0],20)[0]) -/+ 3 * TickSize
                            2) using percentage would be ;
                            (SMA(20)[0]) * (1 + 23/100)) and it would be a 23% of the SMA(20) Price Value

                            Regards,
                            Pablo Maglio
                            The Indicator Store
                            pmaglio
                            NinjaTrader Ecosystem Vendor - The Indicator Store

                            Comment


                              #59
                              Got it Pablo. Thanks for your input. (As always, your instructions are easy to understand.)

                              sandman

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Gerik, Today, 09:40 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by RookieTrader, Today, 09:37 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by alifarahani, Today, 09:40 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post alifarahani  
                              Started by KennyK, 05-29-2017, 02:02 AM
                              3 responses
                              1,285 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              11 responses
                              186 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X