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

arrow issues

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

    arrow issues

    I haven't been here for about 5 yrs but used to be able to write simple codes but not anymore.
    I tried to just write something that draws a red arrow if the current bar is red and closed below the immediately prior red bar low if that was red.
    I also wanted a green arrow if the current green bar closed higher than the immediately prior green bar's high if that bar was green.
    The red work and if I only have it look for all green bars that works too but the green won't give any arrows once I include the prior bar requirement. The red stay working.
    I tried breaking it into two indicators but same thing, the green only works if I code to look at all green. I thought there used to be a way to do condition 1 and then run for condition 2 etc... but I don't remember how.
    I cannibalized this from another indicator with arrows.

    Any ideas why it won't work on green?

    [/QUOTE]
    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {

    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1 LONG type #2

    if (
    Close[0]> Open[0]//green
    && Close[0]>High[1] // closed higher than prior high
    && Close[1] > Open[1]//green
    )
    {
    DrawArrowUp(" up" + CurrentBar, false, 0, Low[0]- (TickSize*dist), Color.Lime);
    }


    //***********************************
    //Condition set 2 SHORT type 2

    if (
    Close[0]< Open[0]//red
    && Close[0]<Low[1] // closed lower than prior low
    && Close[1] < Open[1]//red
    //&& Close[-2] > Open[-2]//green
    )
    {
    DrawArrowDown(" down" + CurrentBar, false, 0, High[0]+(TickSize*dist) , Color.White);
    }
    }[QUOTE]

    #2
    Hello simpletrades,

    Thanks for your post.

    The indicator will error out on the first bar loaded because you are accessing a previous bar [1] before [1] exists. To prevent the error you would prevent processing your code until the indicator has loaded enough bars to evaluate your conditions. You can do this by adding a check of the CurrentBar variable which holds the bar number being processed. On the first bar loaded, CurrentBar = 0, on the next bar CurrentBar = 1, then CurrentBar = 2, etc, etc,

    Add the below statement as the first statement in the OnBarUpdate() method:

    if (CurrentBar < 1) return; // do not process until first 2 bars loaded.


    Note: The DrawArrowDown() statement uses the color white for the arrow, just checking to make sure you are not applying to a white background chart.

    Reference: http://ninjatrader.com/support/helpG...currentbar.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      on a 5 min chart is the bar that closed just before bar [0] bar [1] or bar [-1]?
      when I had it with minuses I was getting very haphazard arrows often = to the prior high if it showed at all.
      using 1,2 ertc.. it looks right when it does post.

      Comment


        #4
        Hello simpletrades,

        Thanks for your reply.

        The bar numbering will depend on your setting of CalculateOnBarClose = true or false:

        If true, the most current bar, index of [0] will be the last completed bar on the right edge of the chart. The bar that is currently forming to the right of that would not be known until it is completed and then it will be [0] and the bar before will be [1].

        If false, the most current bar, index of [0], will be the currently forming bar on the right edge. The last completed bar to the left will be [1].

        I've attached a picture to illustrate the bars ago indexing in both true and false conditions.

        Regarding negative indexes such as [-2], this will not work on real time data as a -2 would be two bars in the future which are not known in realtime. They would be known historically. We advise not to use negative indexes to refer to bars. I think the attached picture will help you to understand the bars ago indexing.
        Attached Files
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          thanks i'll check that later but whats weird is on just an ES chart up and down versions show arrows.
          On charts with CL on top and ES below,, CL shows up and down versions but ES only shows down arrows.?

          Comment


            #6
            its set to on bar close=true because until the bar is done theres no way to predict where it closes in relation to the prior bar.

            Comment


              #7
              Hello simpletrades,

              Thanks for your replies.

              Regarding, "On charts with CL on top and ES below,, CL shows up and down versions but ES only shows down arrows.?" Is it possible that the chart scaling is not showing the arrows below price? Can you change the vertical scale to see if arrows are just off the chart view?
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                no that wasn't it.
                I use the sets of indicators on both symbols.
                could something be interfering?

                Comment


                  #9
                  Hello simpletrades,

                  Thanks for your reply.

                  There is not enough information provided to formulate an answer.

                  Please attach a screenshot of the issue and post the various indicator source code for review.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    I decided not to worry about multi-series charts because it was working as up and down arrows on individual ES and CL charts but this morning the down arrows show on both but up arrows are only on ES.
                    I wrote an easier test for up and down dots requiring current and prior bar checks only and the down dots are on both CL and ES but the up dots are on neither and except for the bar test part the codes and alerts are identical in all 4.
                    Is there a way to send the .cs files because pasting a couple of indicators in entirety will be lengthy.
                    I'd also like to combine them so that condition 1 is down arrows and condition2 is up arrows and if condition 1 isn't true it checks condition 2 and if that is also not true no arrows print.

                    Comment


                      #11
                      I am enclosing a screenshot of the same indicators on 6 futures.
                      I only use ES and CL but it responds weird depending on symbol.
                      Attached Files

                      Comment


                        #12
                        I wondered if Saturday and closed markets mattered but this morning the FDAX still has no uparrows, NQ and YM has both as do CL and ES but none still show any updots only downdots?
                        I have 12 gig so it cant be a memory issue.

                        Comment


                          #13
                          Hello simpletrades,

                          Thanks for your posts.

                          Do not paste your code in a reply but instead attach your code as a file, same as you did with the screenshots.

                          Alternatively, you may write into PlatformSupport[at]NinjaTrader[dot]Com, mark the e-mail atten:Paul and a link to this thread. Attach your source code file(s) to your reply (again do not paste your code)
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            I attached all 4. Its the type1 Long where no dots ever print.
                            The 2's are the arrows.
                            Attached Files

                            Comment


                              #15
                              Forget the dots. I had it coded without the first bar being[0] but please try to figure out why the arrows aren't printing on all symbols all the time.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Barry Milan, Yesterday, 10:35 PM
                              5 responses
                              16 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by DanielSanMartin, Yesterday, 02:37 PM
                              2 responses
                              13 views
                              0 likes
                              Last Post DanielSanMartin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              4 responses
                              12 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by terofs, Today, 04:18 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post nandhumca  
                              Working...
                              X