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

Crossabove makes this sense?

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

    Crossabove makes this sense?

    Just want it to draw an arrow up if the last close is higher than the last 20 closes. Should work, or?

    protected
    overridevoid Initialize()
    {
    PaintPriceMarkers =
    true; // Indicator plot values are displayed in the y axis
    CalculateOnBarClose = true;
    Overlay =
    true;
    PriceTypeSupported =
    true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    if (CrossAbove(Close, MAX(Close, period), 1))
    DrawArrowUp(
    "up arrow" + CurrentBar, true, 0, MAX(Close, period)[0], Color.Green);
     
    }

    #2
    Hi Precisely,

    In the CrossAbove(), instead of MAX(Close, period),

    try

    MAX(Close, period)[1]

    With MAX(Close, period), the current bar is being included when looking for the maximum value. So if the current close is the highest, the condition is trying to check if the current close is crossing above the current close, which will never occur.

    With MAX(Close, period)[1], the MAX() looks at values starting with the previous bar, then looks back.
    Last edited by NinjaTrader_Tim; 03-14-2010, 09:07 PM.
    TimNinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply Tim.

      Don't get it to work I'm afraid. Do you mean

      if
      (CrossAbove(Close, MAX(Close, period)[1])) ?


      Last edited by Precisely; 03-14-2010, 11:52 PM.

      Comment


        #4
        Hi Precisely,

        Yes, the MAX inside of the CrossAbove.

        So, something like...

        (CrossAbove(Close, MAX(Close,period)[1], 1))
        TimNinjaTrader Customer Service

        Comment


          #5
          It compiles with no errors, but no arrows I'm afraid (tried different periods).

          protectedoverridevoid OnBarUpdate()
          {
          if (CrossAbove(Close, MAX(Close, period)[1],1))
          DrawArrowUp(
          "up arrow" + CurrentBar, true, 0, MAX(Close, period)[1], Color.Green);
          }

          Comment


            #6
            Hi Precisely,

            The MAX can stay the same in the DrawArrowUp, if you want it to draw at the current bar height...

            if (CrossAbove(Close, MAX(Close, 5)[1],1))
            DrawArrowUp("up arrow" + CurrentBar, true, 0, MAX(Close, 5)[0], Color.Green);

            With that change, do you receive any errors in the Log tab in the Control Center?
            TimNinjaTrader Customer Service

            Comment


              #7
              Yepp, I get this one:

              2010-03-15 17:48:29 Default Error on calling the 'OnBarUpdate' method for indicator 'Turtle' on bar 0: Index was out of range. Must be non-negative and less than the size of the collection.
              Parameter name: index

              Comment


                #8
                Hi Precisely,

                You can add the following at the top of the OnBarUpdate()
                if (CurrentBar < 1)
                return;

                To avoid this in the future, please see the following...
                TimNinjaTrader Customer Service

                Comment


                  #9
                  Great, now it works fine. Thank you Tim.

                  Comment


                    #10
                    Tim having trouble painting arrows on chart with RSI. Want up arrows under bars when RSI is at or above 70 and down arrows above bars when RSI is at or below 30...is this difficut? I added this code to a generic RSI code but nothing was on chart. I spent a lot of time on what seems to be easy :-( any help appreciated

                    Thanks!

                    PaintPriceMarkers = true;
                    DrawOnPricePanel =
                    true;
                    if (CrossAbove(RSI(14, 1), 70, 1))
                    DrawArrowUp(
                    "rsi up" + CurrentBar, false, 0, Low[0], Color.Green);
                    elseif (CrossBelow(RSI(14, 1), 30, 1))
                    DrawArrowDown(
                    "rsi down" + CurrentBar, false, 0, High[0], Color.Red);

                    Comment


                      #11
                      This is the code I finally used. Maybe you can twiggle it a bit and get it to work.


                      protectedoverridevoid OnBarUpdate()
                      {
                      if (CurrentBar < 1)
                      return;
                      if (Close[0] > Close[1])


                      if (CrossAbove(Close, MAX(Close, periodup)[1],1))
                      DrawArrowUp(
                      "up arrow" + CurrentBar, true, 0, MAX(Close, periodup)[0], Color.Green);

                      if (CrossBelow(Close, MIN(Close, perioddown)[1], 1))
                      DrawArrowDown(
                      "down arrow" + CurrentBar, true, 0, MIN(Close, perioddown)[0]+TickSize, Color.Red);
                      }
                      Last edited by Precisely; 03-20-2010, 09:29 AM.

                      Comment


                        #12
                        Hello,

                        I saw that you are missing a bracket shown in red below:

                        if (Close[0] > Close[1])
                        {
                        DenNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by sightcareclickhere, Today, 01:55 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post sightcareclickhere  
                        Started by Mindset, 05-06-2023, 09:03 PM
                        9 responses
                        258 views
                        0 likes
                        Last Post ender_wiggum  
                        Started by Mizzouman1, Today, 07:35 AM
                        4 responses
                        18 views
                        0 likes
                        Last Post Mizzouman1  
                        Started by philmg, Today, 01:17 PM
                        1 response
                        7 views
                        0 likes
                        Last Post NinjaTrader_ChristopherJ  
                        Started by cre8able, Today, 01:01 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Working...
                        X