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

Trouble with multiple timeframes

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

    Trouble with multiple timeframes

    Hi,

    I am sure I am missing something obvious, but it's stumped me, so if you could put me on the right track, I'd appreciate it...

    I'm trying to develop a milti time frame indicator. So, for example, say we want to see if price is over the MA on the 1 minute, 5 minute, 5 range timeframes.

    What I did is this

    New indicator with this added

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 1);
    AddDataSeries(Data.BarsPeriodType.Minute, 5);
    AddDataSeries(Data.BarsPeriodType.Range, 5);
    }else if (State == State.DataLoaded)
    {
    pjsKeltner1 = pjsKeltner(Closes[3],2,10,false,"");
    }

    The pjsKeltner is for this example the indicator I want to check on the 5 range series.

    I setup a new chart with a single data series on it and add the indicator.

    Now, as a test, all I've tried to do is change the plot colour when a threshold is reached. So I have this in onbarupdate

    if (BarsInProgress == 3 && Bars.Count>1 && CurrentBar > 1)
    {
    if (Closes[3][0] <= pjsKeltner1.Lower1[0])
    {
    PlotBrushes[0][0] = Brushes.Green;
    }
    else if (Closes[3][0] >= pjsKeltner1.Upper1[0]) {
    PlotBrushes[0][0] = Brushes.Red;
    }
    else {
    PlotBrushes[0][0] = Brushes.DimGray;
    }

    I am simply setting the plot[0] to a value of 10 in onbarupdate and if (barsinprogress == 0) so there is a plot set for every interval that is shown on the chart.

    If I set the chart period to something low, like 10 seconds, there are obviously periods where the above triggers and the plot should change colour, but it does not. If I change the data series on the chart to 5 range, it works. If I set the chart timeframe to anything else, even short periods which would obviously be inclusive of the time period the threshold was triggered, it does not.

    I have tried with tick replay on also, thinking perhaps the 5 range data series ONLY has bar final closes in it? With tick replay on, does this affect only the main data series, or any seperate data series too? My thought was that Closes[3] might be just that, the bar closes ONLY, rather than updated tick by tick? If that is correct, it is possible to add dataseries, yet have them play their data through indicators with tick replay on also?

    I hope this makes sense.

    Thanks.

    #2
    Hello pjsmith,

    Thanks for your post.

    Anything involved with changing the chart plot should be conducted when BarsInProgress = 0 because that matches the "slots" of when the plot is shown.

    It looks like all you need do is change your BarsInProgress check to 0 as your other code appears correctly referenced. IE:

    if (BarsInProgress == 0 && Bars.Count>1 && CurrentBar > 1)
    {
    if (Closes[3][0] <= pjsKeltner1.Lower1[0])
    {
    PlotBrushes[0][0] = Brushes.Green;
    }
    else if (Closes[3][0] >= pjsKeltner1.Upper1[0]) {
    PlotBrushes[0][0] = Brushes.Red;
    }
    else {
    PlotBrushes[0][0] = Brushes.DimGray;
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply. I tried this and it does indeed change the plot, mostly to green, but something is very amiss.

      For exmaple, if I add this to the code to check the upper and lower limits and price of lcose[3][0], with this

      Print(Closes[3][0].ToString() + "/" + pjsKeltner1.Lower1[0].ToString() + "/" + pjsKeltner1.Upper1[0].ToString());

      And check the results, I get these output

      2573.5/2568.4/2573.4
      2573.5/2568.4/2573.4
      2573.5/2568.4/2573.4
      2573.5/2568.4/2573.4
      2573.5/2568.4/2573.4

      That is with the primary data series set to 5 range. Now, if I change the primary data series to 10 seconds

      I get this output

      2573.25/2573.58333333333/2578.58333333333
      2573/2573.58333333333/2578.58333333333
      2573.25/2573.58333333333/2578.58333333333
      2573.25/2573.58333333333/2578.58333333333

      Yet, in the code, the indicator is forced to use the Closes[3].

      Because the indicator seems to be giving very different results based on the primary data series timeframe. This should not happen? btw - The pjsKeltner is just based on your own Keltner indicator, as supplied in NT. It just adds a couple extra bands.

      I'm expecting the upper and lower keltner in this example to remain constant, regardless of the time frame selected on the chart as I have told it to use the indicator added dataseries[3], the 5 range, above.

      What am I missing?

      Comment


        #4
        Hello pjsmith,

        Thanks for your reply.

        Please review the helpguide section here: https://ninjatrader.com/support/help...nstruments.htm In particular the section "How Bars Data is Referenced".

        Use your print statements to continue debugging and relate the print values to the bar values to clear up what data is used and when. It may also help you to create a (seperate) chart with all the bars of each series displayed to aid in visually understanding.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks. So if I'm reading that example correctly, added data series are NOT processed tick by tick, but the main data series added to the chart would be (assuming you had tick-replay on or were real-time and indicator set to calc on each tick) ?

          Comment


            #6
            Hello pjsmith,

            Thanks for your reply.

            In real time, the data would be processed tick by tick when using Calculate.OnEachTick. The two illustrations in the helpguide section "How bars data is referenced" are showing the difference between Calculate.OnBarClose (which is the same for historical) and Calculate.OnEachTick which would be live.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by f.saeidi, Today, 08:03 AM
            0 responses
            3 views
            0 likes
            Last Post f.saeidi  
            Started by cre8able, 04-17-2024, 04:16 PM
            7 responses
            64 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Aviram Y, 08-09-2023, 09:04 AM
            11 responses
            299 views
            0 likes
            Last Post arjandezeeuw  
            Started by Christopher Leggit, 02-15-2024, 09:00 AM
            3 responses
            47 views
            0 likes
            Last Post rdtdale
            by rdtdale
             
            Started by DavidHP, Today, 07:56 AM
            0 responses
            4 views
            0 likes
            Last Post DavidHP
            by DavidHP
             
            Working...
            X