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

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:



    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:

    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 geotrades1, Today, 10:02 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by ender_wiggum, Today, 09:50 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by rajendrasubedi2023, Today, 09:50 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by bmartz, Today, 09:30 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by geddyisodin, Today, 05:20 AM
          3 responses
          26 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X