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

question on multiple time domain indicator

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

    question on multiple time domain indicator

    Hello,
    I am trying to write a multiple time domain indicator. I have the following issue:
    My main time is "1 min". I then added a daily time via:
    AddDataSeries(Data.BarsPeriodType.Day, 1);
    What I see is that I only get 2 daily bars, and I would like to do a 30 day average.
    I saw that there is a "barsToLoad," , but I don't see how it can be added to the AddDataSeries.

    2, When I apply the same indicator on a daily chart, NT takes a very long time to update (it shows "Loading" for sometimes 30min !!) , and eventually shows nothing
    All that I have is:
    Values[0][0] = CurrentBars[0] ;
    This works well in 1min, 5min, even weekly or monthly context - it shows the graphical bar count. However it shows nothing on daily context . this happens on certain instruments Any idea why ? any idea how to avoid this ?
    Thanks

    #2
    Hello Leope,

    Thank you for you note.

    I would suggest including a current bar check at the beginning of the script under OnBarUpdate, for example if you had 1 extra series you would want,

    If(CurrentBars[0]<30 || CurrentBars[1] <30) return;

    You could read more about current bar checks,


    To get a 30 day average of the secondary series and plot it on the primary series, you could use,

    Values[0][0]=SMA(Closes[1], 30)[0];

    When you apply the indicator to a chart, right click on the chart>data series> and set Days to Load > 2, for example 35 since you want a 30 day average. This should give you more than 2 days of data.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi,
      Thanks for your answer.
      I have a list of about 100 instruments that I want to apply to the indicator. The list varies on a daily basis. Having to do a right click on each one is not an option.
      Is there an automated way to increase the number of days to look back, and apply it only to the daily dataseries ? Somehow use the "barsToLoad," ? I saw the following:

      AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)

      Can I utilize this somehow ? the instrumentName in the above should be the current one [and not a constant known string]. Is this possible ? if yes, how do I do this and what should be the value of the other fields?
      Thanks

      Comment


        #4
        Hello Leope,

        Thank you for your response.

        The Bars To Load will inherit from the primary bar series for the instrument. You would need to set your chart to 30 days to load or more to get the 30 day average.

        On the long load times, are you utilizing Tick Replay on your chart?

        I look forward to your response.

        Comment


          #5
          Hi,
          The chart is not the main issue.
          I want to use this indicator in a market analyzer. In this case I will need to somehow set the number of bars to the required number. I cant open every instrument in a chart and set it. its not practical. Is there an automated way to do so ?
          Bottom line, I have a very simple code, that either does not work or gets stuck.
          Here is what I do: In State.Configure
          AddDataSeries(Data.BarsPeriodType.Minute, 5);
          AddDataSeries(Data.BarsPeriodType.Day, 1);
          In OnBarUpdate
          Values[0][0] = CurrentBars[0] ;
          Values[1][0] = CurrentBars[0] ;
          Values[2][0] = CurrentBars[0] ;
          When the chart is in "1 min" time frame it works ok, though , I need to change the days to load to a big number , so that I can see some progress in Values2 .
          But when I change the chart timeframe to days, the indicator shows nothing on all Values, which I don't understand why. and when I switch back to minutes it gets stuck with the "Loading".
          So what is going on here ?

          Comment


            #6
            The actual code is of course:
            Values[0][0] = CurrentBars[0] ;
            Values[1][0] = CurrentBars[1] ;
            Values[2][0] = CurrentBars[2] ;

            Comment


              #7
              Hello Leope,

              Thank you for your response.

              May we test the indicator on our end? If not, do you have a simplified version of the script that produces the same results in the Market Analyzer?

              You can export your indicator by going to Tools > Export > NinjaScript Add On > Add > select your indicator > OK > Export > name the file 'NTsupport' > Save.

              The file will be located under Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript. Please attach the file to your response.

              I look forward to your response.

              Comment


                #8
                Hi Patrick,
                Thanks for your help !
                Attached is the file. I have added some comments in the file on what I see.
                I believe I am missing something basic ...
                Thanks again!
                Attached Files

                Comment


                  #9
                  Hello Leope,

                  In the script you uploaded I do not see a current bar check at the top of the script under OnBarUpdate as I suggested my first post. A clue this is the problem can be found on the log tab of the control center.

                  If you add the following under OnBarUpdate do you still experience the behavior?
                  Code:
                  if ( CurrentBars[2] < 20 || CurrentBars[0] < 20 ||  CurrentBars[1] < 20) return;
                  I look forward to your reply.
                  Attached Files
                  Alan P.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello,
                    If you look at my script, you can see that these lines existed and were commented out.
                    As I mentioned in my comments , if they are not commented the script always exists,as it fails to meet the min bars required, since CurrentBars[2] is always 2 or 3 when timeframe is 1min/5min.
                    This was the issue that started this thread
                    Do you see this ? I couldn't find an automated way to get the CurrentBars[2] to be larger than 3. As I said, having to manually change the dataseries on each chart is not a viable option for me, as I plan to use this in a market analyzer.
                    So is there an automated way to use 30 daily bars on a 1 or 5 min chart ?
                    Thanks

                    Comment


                      #11
                      Hello Leope,

                      When you apply the indicator to the market analyzer, you can define Data Series Type and Value, as well as the time frame. Set Days back to 30 and the type to minute, and the value for type 1 or 5.

                      Does this approach not work for you?

                      I look forward to your reply.
                      Attached Files
                      Alan P.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello,
                        Thanks for your answer. Yes, this can work.
                        Though, basically I need 20 days of daily data and not 20 days of 1min data . Can this slow down the update rate? alternatively, I can calculate what I need offline and load it into the script.
                        Both approaches are not straightforward. I would expect that I would be able to create a dataseries and define the barsToLoad. Don't understand why you have this for a different instrument and not for the current instrument.
                        Additional questions:
                        1. Where can I see possible runtime errors due to my indicator ? I noticed you had that marked in one of the previous images you sent.
                        2. Any idea why the indicator fails to show anything on a daily context ? I added the following code:
                        if (BarsInProgress ==0) { req0 = BarsRequiredToPlot ; }
                        if (BarsInProgress ==1) { req1 = BarsRequiredToPlot ; }
                        if (BarsInProgress ==2) { req2 = BarsRequiredToPlot ; }
                        Values[0][0] = req0 ;
                        Values[1][0] = req1;
                        Values[2][0] = req2;

                        behavior is really weird. My understanding is that all these dataseries always exist. But when my chart time is above 5 min , the indicator shows nothing. Why is this ?

                        Comment


                          #13
                          Hello Leope,

                          If you want to pull 20 days of daily data you could set Load Data based on Days, Days back to 20, Data Series Type to Day, Value to 1.

                          You can see errors on the log tab of the control center.

                          Without the full script I would be unable to diagnose why your code is not working, it could be an error, not enough bars, etc.

                          I would suggest adding print statements to the script, for example printing CurrentBars[0] CurrentBars[1], etc. I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:

                          Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


                          I’ve provided a link covering debugging which you may find helpful.

                          Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

                          Please let us know if you need further assistance.
                          Attached Files
                          Alan P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by judysamnt7, 03-13-2023, 09:11 AM
                          4 responses
                          59 views
                          0 likes
                          Last Post DynamicTest  
                          Started by ScottWalsh, Today, 06:52 PM
                          4 responses
                          36 views
                          0 likes
                          Last Post ScottWalsh  
                          Started by olisav57, Today, 07:39 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post olisav57  
                          Started by trilliantrader, Today, 03:01 PM
                          2 responses
                          21 views
                          0 likes
                          Last Post helpwanted  
                          Started by cre8able, Today, 07:24 PM
                          0 responses
                          10 views
                          0 likes
                          Last Post cre8able  
                          Working...
                          X