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

Check a date

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

    Check a date

    Hi,

    I need to check, for any bar in a chart, if the bar date matches with a list of dates. If yes I will draw a vertical line on that bar.

    I'm trying building an array to store dates to be matched as variable, but I have some problems.
    Code:
    #region Variables
    private int[]  myArray = new int [1];
     #endregion
    I added items in the Initialize space
    Code:
    protected override void Initialize()
    {
    myArray[0] = 20130319;
    myArray[1] = 20130424;
    }
    in the OnBarUpdate I added
    Code:
    protected override void OnBarUpdate()
    {
         for (int i = 0; i < 2; i++)
         {
              if(ToDay(Time[0]) == myArray[i])
              {
               DrawVerticalLine("test1",0, Color.DarkRed, DashStyle.Dot, 3)
               }
          }
     }
    Unfortunately doesn't work and I cannot find where the error is (I made some tests but in some cases Ninja crashes).

    I know the use of array for EasyLanguage but I have some problem with c#.

    Could someone put me on the right way?

    Thanks.

    #2
    Hello MAX,

    Thank you for your post.

    This is more of a general C# concept which can't really support, however you can look into the Arraylist for example on MSDN for this, or search the forum, there have been some discussions on how to use those in scripts for NinjaTrader.

    You can find such a discussion at the following link: http://www.ninjatrader.com/support/f...ad.php?t=24801

    Comment


      #3
      Originally posted by MAX View Post
      Hi,

      I need to check, for any bar in a chart, if the bar date matches with a list of dates. If yes I will draw a vertical line on that bar.

      I'm trying building an array to store dates to be matched as variable, but I have some problems.
      Code:
      #region Variables
      private int[]  myArray = new int [1];
       #endregion
      I added items in the Initialize space
      Code:
      protected override void Initialize()
      {
      myArray[0] = 20130319;
      myArray[1] = 20130424;
      }
      in the OnBarUpdate I added
      Code:
      protected override void OnBarUpdate()
      {
           for (int i = 0; i < 2; i++)
           {
                if(ToDay(Time[0]) == myArray[i])
                {
                 DrawVerticalLine("test1",0, Color.DarkRed, DashStyle.Dot, 3)
                 }
            }
       }
      Unfortunately doesn't work and I cannot find where the error is (I made some tests but in some cases Ninja crashes).

      I know the use of array for EasyLanguage but I have some problem with c#.

      Could someone put me on the right way?

      Thanks.
      You declared your Array to have a size of 1 element. You cannot put 2 elements into an Array that is sized for one element. Declare your Array to be the correct size.
      Code:
      private int[]  myArray = new int [2];

      Comment


        #4
        Thanks koganam you are right, I missed the lenght.
        Although now I don't have any errors but the indicator does not draw any vertical lines.

        Comment


          #5
          No, I correct previous post. I see only the last vertical line on chart.....

          Comment


            #6
            Originally posted by MAX View Post
            No, I correct previous post. I see only the last vertical line on chart.....
            If you want to see multiple lines, they must have unique tags. You are using a single tag, so the line will be updated each time. Try
            DrawVerticalLine("test1"+CurrentBar.ToString(),0, Color.DarkRed, DashStyle.Dot, 3);

            Comment


              #7
              Perfect koganam. It works. Thanks very much.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by judysamnt7, 03-13-2023, 09:11 AM
              4 responses
              59 views
              0 likes
              Last Post DynamicTest  
              Started by ScottWalsh, Today, 06:52 PM
              4 responses
              36 views
              0 likes
              Last Post ScottWalsh  
              Started by olisav57, Today, 07:39 PM
              0 responses
              7 views
              0 likes
              Last Post olisav57  
              Started by trilliantrader, Today, 03:01 PM
              2 responses
              21 views
              0 likes
              Last Post helpwanted  
              Started by cre8able, Today, 07:24 PM
              0 responses
              10 views
              0 likes
              Last Post cre8able  
              Working...
              X