• 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

inside day

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

    inside day

    Hi,
    I'm new to programming.... I'm trying to develop a filter to check if yesterday was an inside day starting from minute chart, and I write this
    Code:
    if (Bars.GetDayBar(2) != null
    				&& PriorDayOHLC().PriorHigh[0] < Bars.GetDayBar(2).High
    				&& PriorDayOHLC().PriorLow[0] > Bars.GetDayBar(2).Low)
    obviously don't work....
    what's wrong??

    Thanks

    #2
    Hello kantkant2,

    Thank you for your post.

    I have tested this on my end and found this to work correctly on my end.

    Can you detail you what are looking for further and what you are seeing that is incorrect?
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Ok, I have tested it again, on the output window it checks me correctly the inside days, but when I try to make some action it seems to work uncorrectly......
      for example attached here a simple rules for system on dax:
      Code:
      protected override void OnBarUpdate()
              {
      			if (Bars.GetDayBar(2) != null
      				&& PriorDayOHLC().PriorHigh[0] < Bars.GetDayBar(2).High
      				&& PriorDayOHLC().PriorLow[0] > Bars.GetDayBar(2).Low
      				&& Math.Abs(PriorDayOHLC().PriorClose[0] - PriorDayOHLC().PriorOpen[0]) / (PriorDayOHLC().PriorHigh[0] - PriorDayOHLC().PriorLow[0]) < .5
      				&& ToTime(Time[0]) > ToTime(10, 10, 0)
      				&& ToTime(Time[0]) < ToTime(17, 0, 0)
      				&& Time[0].DayOfWeek != DayOfWeek.Monday)
      				
      			{
      				EnterLongStop(DefaultQuantity, CurrentDayOHL().CurrentHigh[0], "");
      				
      			}
      			
      			if (Bars.GetDayBar(2) != null
      				&& PriorDayOHLC().PriorHigh[0] < Bars.GetDayBar(2).High
      				&& PriorDayOHLC().PriorLow[0] > Bars.GetDayBar(2).Low
      				&& Math.Abs(PriorDayOHLC().PriorClose[0] - PriorDayOHLC().PriorOpen[0]) / (PriorDayOHLC().PriorHigh[0] - PriorDayOHLC().PriorLow[0]) < .5
      				&& ToTime(Time[0]) > ToTime(10, 10, 0)
      				&& ToTime(Time[0]) < ToTime(17, 0, 0)
      				&& Time[0].DayOfWeek != DayOfWeek.Tuesday)
      				
      			{
      				EnterShortStop(DefaultQuantity, CurrentDayOHL().CurrentLow[0], "");
      				
      			}
      if you try to backtest a few days you see they go well some days and bad other...

      and also, I have try to make a strategy only for mark with a dot the inside days, but they shows me only the last inside like this:
      Attached Files

      Comment


        #4
        What is your code being used for DrawDot() ?

        You'll also want to add Print statements to ensure values are what you would expect.
        I personally find this one to be most helpful
        Print("this portion of my code was hit at time: " + Time[0]);
        You can also add other variables into the print statement

        http://www.ninjatrader.com/support/f...ead.php?t=3418

        If you'd like us to look further into it could you please attach the complete script you're working with. We aren't able to offer debugging assistance here but if it's a simple script I would be happy to glance over it.

        Located in (MY)Documents\NinjaTrader 7\bin\Custom\Strategy
        Lance B.NinjaTrader Customer Service

        Comment


          #5
          thanks so much Lance!!
          to draw dot I wrote:
          Code:
          protected override void OnBarUpdate()
                  {
          			if (Bars.GetDayBar(1) != null
          				&& Bars.GetDayBar(2) != null
          				&& Bars.GetDayBar(1).High < Bars.GetDayBar(2).High
          				&& Bars.GetDayBar(1).Low > Bars.GetDayBar(2).Low)
          				
          			{
          				DrawDot("tag1", true, 1, Low[1] - TickSize, Color.Red);
          				Print(Time[0].ToString("dd/MM/yyyy") + ", Inside Day" );
          			}
                  }
          I attach my strategy like you said me.
          Attached Files

          Comment


            #6
            Hello kantkant2,

            Thank you for your response.

            For the DrawDot() the tag is always the same so the drawing object is only drawn on the most recent condition. To have it drawn on each condition you need to add in something that will change such as Time[0] or Current Bar:
            Code:
            DrawDot("tag1" + CurrentBar, true, 1, Low[1] - TickSize, Color.Red);
            For your conditions, I recommend breaking them down to check if they return true such as the following:
            Code:
            if (Bars.GetDayBar(2) != null)
            {
            Print("There is data for two days ago. " + Time[0]);
            }
            if(PriorDayOHLC().PriorHigh[0] < Bars.GetDayBar(2).High)
            {
            Print("Yesterday's high is less than two days ago. " + Time[0]);
            }
            etc...
            Then you can check if they work together:
            Code:
            if (Bars.GetDayBar(2) != null
            && PriorDayOHLC().PriorHigh[0] < Bars.GetDayBar(2).High)
            {
            Print("There is data for two days ago and yesterday's high is less than two days ago. " + Time[0]);
            }
            Your NinjaScript / C# Code will always be logically processed and evaluate according to your set logic – this can of course lead to unexpected results at times, thus we would suggest to simplify and debug your code to better understand the event sequence it would go through - unfortunately we cannot offer such debug or code modification services here, but please see the provided resources below to help you proceed productively :

            First of all you would want to use Print() statements to verify values are what you expect - Debugging your NinjaScript code.

            For strategies add TraceOrders = true to your Initialize() method and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders

            It may also help to add drawing objects to your chart for signal and condition confirmation - Drawing Objects.

            If you would prefer the debug assist of a professional NinjaScript consultant, please check into the following listings - Click here for a list of certified NinjaScript Consultants

            Please let me know if you have any questions.
            Patrick H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by StevenNelson, Today, 12:29 PM
            0 responses
            5 views
            0 likes
            Last Post StevenNelson  
            Started by anupsoni, Today, 12:23 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Kate  
            Started by aligator, Yesterday, 12:15 PM
            6 responses
            60 views
            0 likes
            Last Post eDanny
            by eDanny
             
            Started by frankduc, Today, 11:22 AM
            3 responses
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by aslane, Today, 10:53 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X