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

confused about data series

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

    confused about data series

    i want to calculate on bar close a value that is = value one bar ago minus some other valuse


    Value2 = (Value2[1] - Value1);

    i can't seem to get this to work, is the DataSeries the right way to set this up?

    #2
    Hello JimPunkrockford,

    Thank you for your post.

    Yes, a DataSeries would be correct. Please try the following:
    Code:
    Value2.Set(Value2[1] - Value1);

    Comment


      #3
      okay. so first i need to set up a variable that is Value2 in the variables region.

      i did this

      DataSeries Value2;

      then nothing in void Initalize()

      then your suggestion in on bar update.

      that compiles but causes me to not be able to plot Value1 anymore

      Comment


        #4
        Hello JimPunkrockford,

        Thank you for your response.

        Please provide the full code so I may investigate this matter further. You will find the .cs file for the indicator in the following directory on your PC: (My) Documents\NinjaTrader 7\bin\Custom\Indicator.

        Comment


          #5
          #endregion

          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          /// <summary>
          /// third try at trin osc
          /// </summary>
          [Description("third try at trin osc")]
          public class myindicator3utillstep4 : Indicator
          {
          #region Variables
          // Wizard generated variables
          private string data2 = @"^TRIN"; // Default setting for Data2
          private string data3 = @"^DJIA"; // Default setting for Data3

          // User defined variables (add any user defined variables below)
          int Length = 5;
          DataSeries Value4;
          DataSeries Value6;
          DataSeries Value9;
          DataSeries Value10;
          #endregion

          /// <summary>
          /// This method is used to configure the indicator and is called once before any bar data is loaded.
          /// </summary>
          protected override void Initialize()
          {
          Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot1"));

          Overlay = false;
          Add(Data2,PeriodType.Day,1);
          Add(Data3,PeriodType.Day,1);


          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {
          try
          {

          double Value3 = (-(Closes[1][0])+(Closes[2][0]));
          Value4.Set(Value4[1]-Value3);

          Plot1.Set(Closes[1][0]);


          }
          catch (Exception ex)
          {
          Print (ex.ToString());
          }
          }

          Comment


            #6
            as soon as i add the line about Value4.set, my plot no longer works

            Comment


              #7
              Hello JimPunkrockford,

              Thank you for your response.

              You will need to sync the DataSeries in the Initialize() method as well:
              Code:
              protected override void Initialize()
              {
              Value4 = new DataSeries(this);

              Comment


                #8
                i thought i might have to do that.

                thanks that worked.

                i still don't get what the holder "this" is supposed to be.

                Comment


                  #9
                  Originally posted by JimPunkrockford View Post
                  i thought i might have to do that.

                  thanks that worked.

                  i still don't get what the holder "this" is supposed to be.
                  "this" specifies the current class file that is being used. It is a keyword that allows you to specify the class without having to write its actual name.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bmartz, 03-12-2024, 06:12 AM
                  5 responses
                  32 views
                  0 likes
                  Last Post NinjaTrader_Zachary  
                  Started by Aviram Y, Today, 05:29 AM
                  4 responses
                  13 views
                  0 likes
                  Last Post Aviram Y  
                  Started by algospoke, 04-17-2024, 06:40 PM
                  3 responses
                  28 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by gentlebenthebear, Today, 01:30 AM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by cls71, Today, 04:45 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X