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

Multi Time Frame Daily ATR filter

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

    Multi Time Frame Daily ATR filter

    So, apparently what I thought was working in backtest is not working in forward test the way I had planned. I am trying to make it such that if today's range is greater than yesterday's ATR at close, then set boolean to true. If today's range is less than or equal to yesterday's ATR at close, then set boolean to false. I am placing orders on a lower time frame than the daily.

    Here's the relevant code, the indicators are the stock ninjatrader ones.

    Code:
    			 // Set 43
    			if (Range1[0] > ATR1[0])
    			{
    				DailyRangeBlock = true;
    				Print("DailyRangeBlock = True");
    			}
    			
    			 // Set 44
    			if (Range1[0] <= ATR1[0])
    			{
    				DailyRangeBlock = false;
    				Print("DailyRangeBlock = False");
    			}
    While debugging I have discovered the range indicator put in this way returns yesterday's range at close at when I use [0]. The same with ATR, it is still yesterday's number at [0].

    Is there some way to access today's range as it is being painted? I already tried to Print the string from the Range indicator Ninjatrader.Custom.Resource.RangeValue and it just returns "Range value." I dug down deeper and found I was just referencing yesterday's value.

    Also tried calculating on each tick. That didn't work.

    Edit: just realized I should probably reference the bar directly. Going to work on that now.
    Last edited by liquid150; 01-23-2018, 07:15 PM.

    #2
    I am currently running some fixes with Calculate set to OnEachTick and OnPriceChange. I am hoping this will fix the issue.
    Last edited by liquid150; 01-23-2018, 08:39 PM.

    Comment


      #3
      I want to at least get confirmation that I'm working in the right direction. I turned the strategy over to Calculate.OnEachTick, and the following is the code I am using to get the range of today's bar:

      Highs[1][0] - Lows[1][0]

      And comparing it like so
      Code:
      			 // Set 43
      			if ((Highs[1][0] - Lows[1][0]) > ATR1[0])
      			{
      				DailyRangeBlock = true;
      				Print("DailyRangeBlock = True");
      			}
      			
      			 // Set 44
      			if ((Highs[1][0] - Lows[1][0]) <= ATR1[0])
      			{
      				DailyRangeBlock = false;
      				Print("DailyRangeBlock = False");
      			}
      Should this at least in theory pick up today's range properly, since I am calculating on each tick? I referenced the Multi Instrument page in the Help Guide, and saw the graphics and realized what my problem likely was.

      Comment


        #4
        Hello,

        Thank you for the posts.

        I wanted to gather some more details as the sample provided is not really enough to understand what may be happening in your logic. Based on your sample it looks like you have a multi-series script but I cannot tell what BarsInProgress this is being executed from. Can you provide some detail on the setup of your script? What are the primary and secondary series timeframes that are being used here? In your overall logic, is this surrounded by a BarsInProgress check? if so which one?



        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Good afternoon Jesse,

          The main time frame on which the script is written is an external to NT8 formula I use to calculate a custom tick bar size from average daily volume. I have the daily bar time frame as a secondary data set.

          The only BarsInProgress and CurrentBars script in use in the strategy was generated by NT8 and is in the beginning of OnBarUpdate. It reads:

          Code:
          if (BarsInProgress != 0) 
          				return;
          
          			if (CurrentBars[0] < 3
          			|| CurrentBars[1] < 1)
          			return;
          The script I am using below is many lines beneath this, and is not inside of an if(BarsInProgress..... as far as I am aware.

          PS: I am pretty confident, due to some testing I did today, that switching to calculate on each tick will solve the problem.

          I would like to put in a feature request though. I would like to be able to have the strategy calculate on main time frame bar close. I'm not sure how hard it would be to split up the logic for different time frames on that, though. Your people will have to determine if it's a valuable idea.

          It would basically only save me CPU cycles, but it could be a whole lot of them.
          Last edited by liquid150; 01-24-2018, 04:33 PM.

          Comment


            #6
            As usual, doing more research found me what I needed. This page appears to offer a solution to my problem.

            If I understand this correctly, If I add IsFirstTickofBar to the condition sets where needed, they will only calculate on close. This should be sufficient to save CPU cycles...and also will fix another problem I noticed came up when changing to Calculate.OnEachTick.

            Comment


              #7
              Hello,

              Thank you for posting the solution you found.

              You are correct, IsFirstTickofBar would be what is suggested if you wanted to simulate Calculate OnBarClose while using OnEachTick. Based on your reply it looks like you have corrected the problem at this point, if I am incorrect please let me know and I would be happy to assist further.
              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,227 views
              0 likes
              Last Post xiinteractive  
              Started by andrewtrades, Today, 04:57 PM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by chbruno, Today, 04:10 PM
              0 responses
              7 views
              0 likes
              Last Post chbruno
              by chbruno
               
              Started by josh18955, 03-25-2023, 11:16 AM
              6 responses
              440 views
              0 likes
              Last Post Delerium  
              Started by FAQtrader, Today, 03:35 PM
              0 responses
              11 views
              0 likes
              Last Post FAQtrader  
              Working...
              X