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

  • NinjaTrader_PaulH
    replied
    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

    Leave a comment:


  • simpletrades
    replied
    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.

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    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

    Leave a comment:


  • simpletrades
    started a topic arrow issues

    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]

Latest Posts

Collapse

Topics Statistics Last Post
Started by cre8able, Today, 01:16 PM
1 response
8 views
0 likes
Last Post NinjaTrader_Gaby  
Started by chbruno, 04-24-2024, 04:10 PM
3 responses
48 views
0 likes
Last Post NinjaTrader_Gaby  
Started by samish18, Today, 01:01 PM
1 response
6 views
0 likes
Last Post NinjaTrader_LuisH  
Started by WHICKED, Today, 12:56 PM
1 response
8 views
0 likes
Last Post NinjaTrader_Gaby  
Started by WHICKED, Today, 12:45 PM
1 response
11 views
0 likes
Last Post NinjaTrader_Gaby  
Working...
X