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

Daily candles return the same values...?

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

    Daily candles return the same values...?

    Hello,

    I have the following code:

    Code:
      else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Minute, 60);
                    AddDataSeries(Data.BarsPeriodType.Minute, 60 * 4);
                    AddDataSeries(Data.BarsPeriodType.Day, 1);​
    And then:

    Code:
    protected override void OnBarUpdate()
    {
    if(CurrentBar < 5)
    return;​
    
    // ... Other stuff
     else if (BarsInProgress == 3 && IsFirstTickOfBar)
                    {
                        for(int i = 1; i <= 3; ++i)
                {
                    Print(string.format{{0}, {1}, {2} {3} , Barnumber, High[i], Low[i], Close[i]);​
    The other timeframes are working fine, but for D1 I get the same values for high/low/close. Barnumber incremenets as expected.

    What am I doing wrong...? I've also tried hard coding Highs[3][1], etc. instead of using High/Low/Close.

    Thanks!

    Koby

    #2
    Is Barnumber CurrentBar?

    If you have 5 or fewer days of data on the chart, there wouldn't be anything on the daily time frame because you're doing if (CurrentBar < 5) return;...

    Try changing the chart to have let's say 10 days of data on it, and change Barnumber there to CurrentBar.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hey Bruce,

      Thx for the reply! I should have mentioned that I'm also printing Time[0] in there as well and I do see the date printed properly. The datetime shows as 5pm and the dates are incrememnting. I thought it might be a historical vs real-time thing but have tried doing High[3] as well just to see if the values change...but they didn't.

      Oh...and the chart is pulling back 60 days of data...just the default setting. I'm not sure if that's what you meant?

      thx!

      Comment


        #4
        Start with this and work your way slowly back to what you have so you can find your mistake:

        Code:
        #region Using declarations
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.ComponentModel.DataAnnotations;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using System.Windows;
        using System.Windows.Input;
        using System.Windows.Media;
        using System.Xml.Serialization;
        using NinjaTrader.Cbi;
        using NinjaTrader.Gui;
        using NinjaTrader.Gui.Chart;
        using NinjaTrader.Gui.SuperDom;
        using NinjaTrader.Gui.Tools;
        using NinjaTrader.Data;
        using NinjaTrader.NinjaScript;
        using NinjaTrader.Core.FloatingPoint;
        using NinjaTrader.NinjaScript.DrawingTools;
        #endregion
        
        //This namespace holds Indicators in this folder and is required. Do not change it.
        namespace NinjaTrader.NinjaScript.Indicators
        {
            public class TestDailyInfo : Indicator
            {
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        Description                                    = @"Enter the description for your new custom Indicator here.";
                        Name                                        = "TestDailyInfo";
                        Calculate                                    = Calculate.OnBarClose;
                        IsOverlay                                    = false;
                        DisplayInDataBox                            = true;
                        DrawOnPricePanel                            = true;
                        DrawHorizontalGridLines                        = true;
                        DrawVerticalGridLines                        = true;
                        PaintPriceMarkers                            = true;
                        ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                        //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                        //See Help Guide for additional information.
                        IsSuspendedWhileInactive                    = true;
                    }
                    else if (State == State.Configure)
                    {
                        AddDataSeries(Data.BarsPeriodType.Minute, 60);
                        AddDataSeries(Data.BarsPeriodType.Minute, 60 * 4);
                        AddDataSeries(Data.BarsPeriodType.Day, 1);​
                    }
                }
        
                protected override void OnBarUpdate()
                {
                    if (CurrentBar < 5) return;​
        
                    // ... Other stuff
                    if (BarsInProgress == 3 && IsFirstTickOfBar)
                    {
                        for (int i = 1; i <= 3; i++)
                        {
                            Print(string.Format("{0}, {1}, {2} {3}", CurrentBar - i, High[i], Low[i], Close[i]));​
                        }
                    }
                }
            }
        }​
        Output:
        4, 4099, 4017 4024.25
        3, 4117, 4076.25 4087
        2, 4087.5, 4008.5 4084.25
        5, 4037.75, 4006 4029.5
        4, 4099, 4017 4024.25
        3, 4117, 4076.25 4087
        6, 4054.25, 3944 3954.5
        5, 4037.75, 4006 4029.5
        4, 4099, 4017 4024.25
        7, 3976.25, 3880.75 3897.25
        6, 4054.25, 3944 3954.5
        5, 4037.75, 4006 4029.5
        8, 3971.5, 3839.25 3888.75
        7, 3976.25, 3880.75 3897.25
        6, 4054.25, 3944 3954.5
        9, 3972.5, 3885 3954.25
        8, 3971.5, 3839.25 3888.75
        7, 3976.25, 3880.75 3897.25
        10, 3964, 3865 3925
        9, 3972.5, 3885 3954.25
        8, 3971.5, 3839.25 3888.75
        11, 4000, 3895 3994.5
        10, 3964, 3865 3925
        9, 3972.5, 3885 3954.25
        12, 4009.25, 3932.5 3947
        11, 4000, 3895 3994.5
        10, 3964, 3865 3925
        13, 3989.5, 3897.25 3983
        12, 4009.25, 3932.5 3947
        11, 4000, 3895 3994.5
        14, 4043.25, 3981.75 4035.75
        13, 3989.5, 3897.25 3983
        12, 4009.25, 3932.5 3947
        15, 4073.75, 3966.25 3970.5
        14, 4043.25, 3981.75 4035.75
        13, 3989.5, 3897.25 3983
        16, 4039.5, 3948.5 3978
        15, 4073.75, 3966.25 3970.5
        14, 4043.25, 3981.75 4035.75
        17, 4010.75, 3937 4001.25
        16, 4039.5, 3948.5 3978
        15, 4073.75, 3966.25 3970.5
        18, 4034.25, 3997.5 4007.25
        17, 4010.75, 3937 4001.25
        16, 4039.5, 3948.5 3978
        19, 4023.75, 3980.75 4001.5
        18, 4034.25, 3997.5 4007.25
        17, 4010.75, 3937 4001.25
        20, 4061.25, 4006 4057.5
        19, 4023.75, 3980.75 4001.5
        18, 4034.25, 3997.5 4007.25
        21, 4087.75, 4052.5 4080
        20, 4061.25, 4006 4057.5
        19, 4023.75, 3980.75 4001.5
        22, 4142.5, 4078 4137.75
        21, 4087.75, 4052.5 4080
        20, 4061.25, 4006 4057.5
        23, 4157.75, 4122.75 4153.75
        22, 4142.5, 4078 4137.75
        21, 4087.75, 4052.5 4080
        24, 4171.75, 4115.25 4129
        23, 4157.75, 4122.75 4153.75
        22, 4142.5, 4078 4137.75
        25, 4135.5, 4099 4117.25
        24, 4171.75, 4115.25 4129
        23, 4157.75, 4122.75 4153.75
        26, 4135.25, 4096.5 4132
        25, 4135.5, 4099 4117.25
        24, 4171.75, 4115.25 4129
        27, 4146.75, 4121 4132
        26, 4135.25, 4096.5 4132
        25, 4135.5, 4099 4117.25
        28, 4143, 4098.75 4136.25
        27, 4146.75, 4121 4132
        26, 4135.25, 4096.5 4132
        29, 4151.75, 4128.75 4136.5
        28, 4143, 4098.75 4136.25
        27, 4146.75, 4121 4132
        30, 4177.75, 4113.5 4119
        29, 4151.75, 4128.75 4136.5
        28, 4143, 4098.75 4136.25
        31, 4177, 4110.25 4172.75
        30, 4177.75, 4113.5 4119
        29, 4151.75, 4128.75 4136.5
        32, 4189, 4138 4163.75
        31, 4177, 4110.25 4172.75
        30, 4177.75, 4113.5 4119
        33, 4180.5, 4148 4176.75
        32, 4189, 4138 4163.75
        31, 4177, 4110.25 4172.75
        34, 4198.25, 4164.5 4180
        33, 4180.5, 4148 4176.75
        32, 4189, 4138 4163.75
        35, 4187.5, 4150.5 4178.5
        34, 4198.25, 4164.5 4180
        33, 4180.5, 4148 4176.75
        36, 4173.5, 4137 4152.5
        35, 4187.5, 4150.5 4178.5
        34, 4198.25, 4164.5 4180
        37, 4161, 4135.25 4156.75
        36, 4173.5, 4137 4152.5
        35, 4187.5, 4150.5 4178.5
        38, 4164.25, 4133.5 4159.5
        37, 4161, 4135.25 4156.75
        36, 4173.5, 4137 4152.5
        39, 4158.5, 4091.5 4093.25
        38, 4164.25, 4133.5 4159.5
        37, 4161, 4135.25 4156.75
        40, 4116.25, 4068.75 4076
        39, 4158.5, 4091.5 4093.25
        38, 4164.25, 4133.5 4159.5
        Note that the bar numbers aren't strictly in order, because for each new bar on the daily series you're printing the most recent three.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Hmm odd...thanks ill try!

          Comment


            #6
            Hello Koby,

            Thanks for your post.

            The sample that QuantKey_Bruce shared demonstrates how you could print out the most recent three daily high, low, and close values.

            You could compare your code with the code they shared to see where differences might be.

            Note to also make sure there are enough bars processing in all the added series by adding a CurrentBars check for each added series.

            Make sure you have enough bars: https://ninjatrader.com/support/help...nough_bars.htm
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Balage0922, Today, 07:38 AM
            0 responses
            5 views
            0 likes
            Last Post Balage0922  
            Started by JoMoon2024, Today, 06:56 AM
            0 responses
            6 views
            0 likes
            Last Post JoMoon2024  
            Started by Haiasi, 04-25-2024, 06:53 PM
            2 responses
            19 views
            0 likes
            Last Post Massinisa  
            Started by Creamers, Today, 05:32 AM
            0 responses
            6 views
            0 likes
            Last Post Creamers  
            Started by Segwin, 05-07-2018, 02:15 PM
            12 responses
            1,786 views
            0 likes
            Last Post Leafcutter  
            Working...
            X