• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing dots based on a condition

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

    Drawing dots based on a condition

    I am new to coding in NinjaTrader. I am trying to draw a dot beneath bars based on a condition being true. I found the topic partially covered in an older thread at this link:

    http://ninjatrader.com/support/forum...ad.php?t=65414

    From that thread, I gather that I should use DrawDot rather than Plot when the dots are not to be drawn on every bar.

    I have this working for a condition based on the current bar, but it fails when I try to make the condition refer to previous bars.

    So, using this condition, I can get the dots to display correctly.

    if (Close[0] < Open[0])

    But, if I try to refer to previous bars, like this:

    if (Close[0] < Open[1])

    -- the code does not work. So, I assume it is the condition itself which I am getting wrong.

    Can anybody explain why this change would stop the code working, and how I would correctly refer to previous bars?

    Any help appreciated.

    Here's the rest of the code.

    Code:
    protected override void OnBarUpdate()
        {
    
            {   
    
                //if (Close[0] < Open[0]) 
                if (Close[1] > Open[1])
                //if(Close[1] < Close[0] && Close[1] < Close[2])
    
                    { 
                        myBarCloses=1;
                    } else {
                        myBarCloses=0;
                    }
    
                    if (myBarCloses==1) 
                    {
                        DrawDot(CurrentBar.ToString() +"BarCloseDot",true, 0, Low[0]*0.997, Color.Magenta);
                    }
    
            }      
    
        }

    #2
    Originally posted by rdhtci View Post
    Can anybody explain why this change would stop the code working, and how I would correctly refer to previous bars?
    If you look in the log tab you should see an error message I believe.
    Open an output window and you will definitely see the error (where I always look).

    This link should explain and solve your problems:

    http://ninjatrader.com/support/forum...ead.php?t=3170

    Comment


      #3
      Thanks very much for the assistance, I have it working with the suggestions in the link you provided.

      Interested in your other suggestions too. I can't find anything relevant in the log tab, and I see nothing at all in the output widow, I would be interested to know how I actually get a visible output.

      Comment


        #4
        Originally posted by rdhtci View Post
        Interested in your other suggestions too. I can't find anything relevant in the log tab, and I see nothing at all in the output widow, I would be interested to know how I actually get a visible output.
        The output window should be open when the error happens:

        It would say something like this:

        "5/3/2016 11:22:54 AM Strategy Error on calling 'OnBarUpdate' method for strategy 'a1xWnew/271b9005ace94801b857c51c1ba907d5': 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."

        You can simply call "Print" command to print to the output window.

        Code:
        Print ( "Close[0]=" + Close[0] );

        Comment


          #5
          Thanks again. Much appreciated.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by levikNT, Today, 07:36 AM
          0 responses
          2 views
          0 likes
          Last Post levikNT
          by levikNT
           
          Started by TazoTodua, Today, 07:27 AM
          0 responses
          4 views
          0 likes
          Last Post TazoTodua  
          Started by KennyK, Yesterday, 09:47 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Dogmatichacker, Yesterday, 03:52 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Trino, 03-23-2019, 09:26 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X