Announcement

Collapse
No announcement yet.

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 sjsj2732, Yesterday, 04:31 AM
              0 responses
              28 views
              0 likes
              Last Post sjsj2732  
              Started by NullPointStrategies, 03-13-2026, 05:17 AM
              0 responses
              284 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              281 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              132 views
              1 like
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              90 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Working...
              X