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

Help using MAX

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

    Help using MAX

    I am trying to create an indicator that will plot a down arrow above a bar if certain conditions are met.

    Right now I am trying to identify if the current bar has a high that is higher than the previous 4 bars.

    My logic looks like this

    var2 = MAX(High, 3)[1];

    if (High[0] > var2)
    var3=1;
    else var3=0;

    if (var3==1)
    DrawArrowDown("tag1" + CurrentBar, true, 0, High[0] + TickSize, Color.Red);

    when I compile the indicator I get no plots on the screen.
    if I change the MAX(High,3)[0] and the if(High[0} == var2) it works.

    I can't seem to figure out why MAX(High,3)[1] doesn't work. Should this not contain the highest bar price for the last three bars beginning one bar ago? Therefore I am checking if the current bar high is greater than the highest high of the previous 3 bars.

    #2
    Does this help?


    Comment


      #3
      Hello wcmaria,

      Thank you for writing in.

      When your indicator wasn't plotting, did you see any errors in the Log tab of the Control Center or the Tools -> Output Window?

      You'll want to ensure that you have enough bars before plotting. I see that your indicator is attempting to access the previous value of the MAX() indicator. If no data exists one bar ago, you will run into a run-time error and the indicator will not plot.

      I would suggest taking a look at this tip post on our support forum about more information on making sure that you have enough bars in the data series you are accessing: http://ninjatrader.com/support/forum...ead.php?t=3170

      Please, let us know if we may be of further assistance.
      Zachary G.NinjaTrader Customer Service

      Comment


        #4
        No arrows are plotted on a 5 minute chart with at least a days worth of bars.

        In the output window I get the following error:

        Error on calling 'OnBarUpdate' method for indicator 'aahilo' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

        Here is my code.

        protected override void OnBarUpdate()
        {
        min = MIN(Low,4);
        max = MAX(High,4);

        bool buyCond1 = Low[0]<min[1];
        bool buyCond2 = Close[0]>Open[0];
        bool buyCond3 = Close[0]>Close[1];

        bool sellCond1 = High[0]>max[1];
        bool sellCond2 = Close[0]<Open[0];
        bool sellCond3 = Close[0]<Close[1];

        if (buyCond1 && buyCond2 && buyCond3)
        {
        DrawArrowUp("tag1" + CurrentBar, true, 0, High[0] + TickSize, Color.Blue);
        }

        if (sellCond1 && sellCond2 && sellCond3)
        {
        DrawArrowDown("tag1" + CurrentBar, true, 0, High[0] + TickSize, Color.Red);
        }
        }

        Comment


          #5
          Hello wcmaria,

          Please note that your script will call OnBarUpdate() on every bar.

          On the first bar, there is no previous bar to look back to. You need to add a check to prevent accessing a non-existent previous bar, per my previous post:

          Originally posted by NinjaTrader_ZacharyG View Post
          I would suggest taking a look at this tip post on our support forum about more information on making sure that you have enough bars in the data series you are accessing: http://ninjatrader.com/support/forum...ead.php?t=3170

          Please, let us know if we may be of further assistance.
          Zachary G.NinjaTrader Customer Service

          Comment


            #6
            Thanks.

            Used the following code and it worked.

            if (CurrentBar < quality)
            return;

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Waxavi, Today, 02:10 AM
            0 responses
            3 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by TradeForge, Today, 02:09 AM
            0 responses
            8 views
            0 likes
            Last Post TradeForge  
            Started by Waxavi, Today, 02:00 AM
            0 responses
            2 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by elirion, Today, 01:36 AM
            0 responses
            4 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by gentlebenthebear, Today, 01:30 AM
            0 responses
            4 views
            0 likes
            Last Post gentlebenthebear  
            Working...
            X