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

Need Help with plotting line at the open price on the hour

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

    Need Help with plotting line at the open price on the hour

    Below is my attempt at coding what I am asking for but has compilation errors. Can you help?



    {
    if (CurrentBar < 24) return;
    int H1 = 0;
    for (int barsAgo = 0; barsAgo < 24; barsAgo++)
    {
    H1 = H1 + Input[barsAgo];
    }
    if (ToTime(Time[0]) >= ToTime(H1, 00, 00))
    {
    int bartime = CurrentBar - Bars.GetBar(new DateTime(2007,1,16,H1,0,0));
    }
    DrawHorizontalLine("Hour Open",Open[bartime],Color.Blue);
    }

    #2
    H1 = H1 + Input[barsAgo];
    That will cause some problems since Input[barsAgo] is a double while H1 is an int. If you changed H1 to a double you will still have problems over here:
    ToTime(H1, 00, 00)
    The inputs for ToTime() should be ints not doubles. I am also not sure if you can use an int > 24 for the input of your DateTime variables. Your H1 variable can surely take on a value greater than 24 and cause problems in that aspect too.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh. Got the following to compile but still not updating my line on the hour. Any thoughts.

      --------------------------------------------------
      -------------------------------------------------

      protected override void OnBarUpdate()
      {
      //if (CurrentBar < 24) return;
      int H1 = 0;
      for (int barsAgo = 0; barsAgo < 24; barsAgo++)
      {
      H1 = H1 + barsAgo;
      }
      if (ToTime(Time[0]) - H1*10000 < 0)
      {
      int bartime = CurrentBar - Bars.GetBar(new DateTime(2008,1,17,0,0,0));

      DrawHorizontalLine("Hour Open",Open[bartime],Color.Blue);
      DrawVerticalLine("Hour Line",bartime,Color.Blue);

      }
      else
      if (ToTime(Time[0]) - H1*10000 >= 0)
      {
      int bartime = CurrentBar - Bars.GetBar(new DateTime(2008,1,17,H1,0,0));

      DrawHorizontalLine("Hour Open",Open[bartime],Color.Blue);
      DrawVerticalLine("Hour Line2",bartime,Color.Blue);


      }

      -----------------------------------------------------------
      --------------------------------------------------------

      Comment


        #4
        You will need to debug your code. Please check out this tip: http://www.ninjatrader-support.com/v...ead.php?t=3418

        If you look in the Log tab in the Control Center you will see an error to this effect:
        Code:
        Error on calling the 'OnBarUpdate' method for indicator 'drawtest' on bar 0: drawtest.DrawVerticalLine: bar must be greater/equal 0 but was -251
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks for pointing this out. Still working on it will. See what you get if you delete the "DrawHorizontaLine" line of code.

          Comment


            #6
            Due to bandwidth issues I cannot help you debug your code. Thanks for understanding. I suggest you us Print functions on your H1 values and your bartime values in the manner recommended in the tip I provided you.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by funk10101, Today, 09:43 PM
            0 responses
            6 views
            0 likes
            Last Post funk10101  
            Started by pkefal, 04-11-2024, 07:39 AM
            11 responses
            37 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Yesterday, 08:51 AM
            8 responses
            44 views
            0 likes
            Last Post bill2023  
            Started by yertle, Today, 08:38 AM
            6 responses
            26 views
            0 likes
            Last Post ryjoga
            by ryjoga
             
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            24 views
            0 likes
            Last Post algospoke  
            Working...
            X