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

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?

    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



        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
        LanceNinjaTrader 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.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            43 views
            0 likes
            Last Post jeronymite  
            Started by frankthearm, Today, 09:08 AM
            4 responses
            10 views
            0 likes
            Last Post frankthearm  
            Started by yertle, Today, 08:38 AM
            5 responses
            15 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by adeelshahzad, Today, 03:54 AM
            3 responses
            18 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by bill2023, Yesterday, 08:51 AM
            6 responses
            27 views
            0 likes
            Last Post NinjaTrader_Erick  
            Working...
            X