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

Indexing issues

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

    Indexing issues

    what am I doing wrong in this expression?
    138 double high = existsHistDailyData ? dailyBar.High : High[0][0];
    139 double low = existsHistDailyData ? dailyBar.Low : Low[0][0];
    140 double close = existsHistDailyData ? dailyBar.Close : Close[0][0];

    Before this, I only had it with one [0] zero brackets and it had another error.
    If I take the "double" designation, it gives a third type of error.

    See the attached script errors snag for the one listed above.
    Thanks for the help.
    Attached Files

    #2
    Hello randl,

    Thank you for your post.

    High[0][0] will need to be Highs[0][0], Low[0][0] will need to be Lows[0][0], and Close[0][0] will need to be Closes[0][0].

    Please try making these adjustments and let me know if this corrects the error.

    Comment


      #3
      Thanks Patrick, that worked great!!
      The script compiled but I am not getting the lines I was expecting - nothing was painted.
      I have no idea what is happening.
      So I think I have bigger problems I need to study.
      I think this is one way to learn.

      Comment


        #4
        randl, thanks for letting us know - which condition were you using to trigger prints then?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Is this what you mean by condition?
          Add(new Plot(Color.White, "PP"));
          Add(new Plot(Color.Violet, "R1"));
          Add(new Plot(Color.Peru, "S1"));
          Add(new Plot(Color.Violet, "R2"));
          Add(new Plot(Color.Peru, "S2"));
          Add(new Plot(Color.Violet, "R3"));
          Add(new Plot(Color.Peru, "S3"));
          //in "Initialize" add VIX statement
          Add("VIX 12-13", PeriodType.Day, 1);// This does not need to be printed

          Otherwise, these are the "if" conditions:
          currentClose = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedClose : close;
          currentHigh = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedHigh : high;
          currentLow = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedLow : low;
          }
          else
          {
          currentClose = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedClose : close;
          currentHigh = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedHigh : Math.Max(currentHigh, high);
          currentLow = (priorDayHLC == HLCCalculationMode.UserDefinedValues) ? userDefinedLow : Math.Min(currentLow, low);
          }

          if (pivotRangeType == PivotRange.Daily)
          currentDate = lastBarTimeStamp;
          if (pivotRangeType == PivotRange.Weekly)
          currentWeek = lastBarTimeStamp;
          if (pivotRangeType == PivotRange.Monthly)
          currentMonth = lastBarTimeStamp;

          if ((pivotRangeType == PivotRange.Daily && currentDate != Cbi.Globals.MinDate)
          || (pivotRangeType == PivotRange.Weekly && currentWeek != Cbi.Globals.MinDate)
          || (pivotRangeType == PivotRange.Monthly && currentMonth != Cbi.Globals.MinDate))
          {
          PP.Set(pp);
          R1.Set(r1);
          S1.Set(s1);
          R2.Set(r2);
          S2.Set(s2);
          R3.Set(r3);
          S3.Set(s3);
          }
          Last edited by randl; 11-01-2013, 08:46 AM.

          Comment


            #6
            Thanks for getting back, no I meant under which OnBarUpdate() condition / trigger would you issue your print statement? Like for example if (Close[0] > Close[1]) Print(Time[0] + " Close up");
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Here are the Bar decisions:

              protected override void OnBarUpdate()
              {
              if (Bars == null)
              return;
              if (!Bars.BarsType.IsIntraday && Bars.Period.Id != PeriodType.Day)
              return;
              if (Bars.Period.Id == PeriodType.Day && pivotRangeType == PivotRange.Daily)
              return;
              if (Bars.Period.Id == PeriodType.Day && Bars.Period.Value > 1)
              return;

              // pivots only work for
              // - intraday
              // - 1 day chart with PivotRange Weekly or Monthly

              if (!isDailyDataLoaded)
              {
              if (priorDayHLC == HLCCalculationMode.DailyBars && Bars.BarsType.IsIntraday)
              {
              Enabled = false;
              System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetBarsNow));
              return;
              }

              existsHistDailyData = false;
              isDailyDataLoaded = true;
              }

              IBar dailyBar;
              if (existsHistDailyData)
              {
              sessionDateDaily = GetLastBarSessionDate(Time[0], Bars, PivotRange.Daily);
              dailyBar = dailyBars.Get(dailyBars.GetBar(sessionDateDaily));

              if (dailyBar.Time.Date > sessionDateDaily.Date)
              {
              for (DateTime i = sessionDateDaily; i >= dailyBars.GetTime(0); i = i.AddDays(-1))
              {
              dailyBar = dailyBars.Get(dailyBars.GetBar(i));
              if (dailyBar.Time.Date == i.Date)
              break;
              }
              }
              }

              Comment


                #8
                Thanks, so you're trying to assign and calculate the values then in Initialize() as it seems by your edited post?

                PP.Set(pp);
                R1.Set(r1);
                S1.Set(s1);
                R2.Set(r2);
                S2.Set(s2);
                R3.Set(r3);
                S3.Set(s3);

                That should be definitely happening in OnBarUpdate() as well.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  I am not sure I understand your meaning. I was using the Ninja Pivots C# code as a go-by and did not change any of the areas we have been discussing.

                  Comment


                    #10
                    From your prior code posts it looked as if you were setting values for the plots in your Initialize(), this would not work. Does the Pivot indicator then work normally for you still using the same inputs? Then I would suggest to run a compare of each section to find out what you changed, or start by commenting out parts and printing your variable states to understand what's evaluating and how to see why your expectation from the code base might be off.

                    Here's more info about the basic debug process using Print() statements -

                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks, let me try that; I will write back when I finish.

                      Comment


                        #12
                        Indexing Issues

                        Okay I ran through the code line by line - no problem found.
                        I went back and used a code from another Pivot (FibPivots) which is currently working, The only items I changed were:
                        1. added the VIX line Patrick noted below,
                        2. changed to Pivot equations to use yesterday's VIX close multiplied by yesterday's Market close, normalized over 252 trading days as a factor for yesterday's close and multiplied that quantity by a Fib number to plot.

                        Nothing plots. the FibVIXPivots is there (see the attached snag), but without any attributes.
                        Attached Files

                        Comment


                          #13
                          Do you see any log error when running your changed script then?

                          Please try to redo / comment out changes you did in step 2 and only add the additional series in - any change in outcome? Would you have a check for enough CurrentBars then added at your OnBarUpdate top for both series, the primary and added one?

                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            The problem was I was trying to use VIX futures as in "VIX 12-13" but I only have the index. the Index is ^VIX. so I changed that and I am going to see if this works. the ^VIX is 20 min delayed since I now need to add the CBOE to my IQ account.

                            Thanks for the help, I will get back to you when I get this other issue worked out.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by nandhumca, Today, 03:41 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post nandhumca  
                            Started by The_Sec, Today, 03:37 PM
                            0 responses
                            3 views
                            0 likes
                            Last Post The_Sec
                            by The_Sec
                             
                            Started by GwFutures1988, Today, 02:48 PM
                            1 response
                            5 views
                            0 likes
                            Last Post NinjaTrader_Clayton  
                            Started by ScottWalsh, 04-16-2024, 04:29 PM
                            6 responses
                            33 views
                            0 likes
                            Last Post ScottWalsh  
                            Started by frankthearm, Today, 09:08 AM
                            10 responses
                            36 views
                            0 likes
                            Last Post frankthearm  
                            Working...
                            X