Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dataseries issue

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

    Dataseries issue

    Hello,

    I have this little test"script" with COBC=true; in an ES-chart

    protected override void OnBarUpdate()
    {
    if(Historical) return;

    {
    if (SMA(20)[0] > SMA(40)[0]
    && Close[0]>Open[0])
    {
    EnterLong(DefaultQuantity, "");
    }
    }
    }

    When enabling the script all is OK and "waiting" untill condition is true.

    But when I do in Initialize Add("^VIX", PeriodType.Range,2);
    (there is no condition with VIX yet, its only to test when adding it)

    then there is an entry immediately when script is enabled (even when condition is not true). Sounds not logically? I agree, and cant find the reason for this behavior.

    Thank you
    Tony
    Last edited by tonynt; 10-07-2016, 02:08 PM. Reason: clearifying

    #2
    Hello tonynt,

    Thank you for your post.

    Are you looking for conditions on both the ES and the VIX? If not, you need to be specific in your code when using multiple instruments. For example:
    Code:
    protected override void OnBarUpdate() { if(Historical) return; if (BarsInProgress == 0 && SMA(BarsArray[0], 20)[0] > SMA(BarsArray[0], 40)[0] && Closes[0][0]>Opens[0][0]) { EnterLong(DefaultQuantity, ""); } }
    I recommend reviewing the details on multiple instruments in your code at the following link: http://ninjatrader.com/support/helpG...nstruments.htm

    Comment


      #3
      Hello Patrick,

      thank you for your reply. I use multiple instruments and dataseries in indicators and scripts. But I never had a problem like now with VIX. Sorry I there is a misunderstanding from me. But why is there immediately an entry in this little script when I do enabling and have Add(VIX...) in Initialize?

      Thanks
      Tony

      Comment


        #4
        Originally posted by tonynt View Post
        Hello,

        I have this little test"script" with COBC=true; in an ES-chart

        protected override void OnBarUpdate()
        {
        if(Historical) return;

        {
        if (SMA(20)[0] > SMA(40)[0]
        && Close[0]>Open[0])
        {
        EnterLong(DefaultQuantity, "");
        }
        }
        }

        When enabling the script all is OK and "waiting" untill condition is true.

        But when I do in Initialize Add("^VIX", PeriodType.Range,2);
        (there is no condition with VIX yet, its only to test when adding it)

        then there is an entry immediately when script is enabled (even when condition is not true). Sounds not logically? I agree, and cant find the reason for this behavior.

        Thank you
        Tony
        Entry on what instrument? The chart instrument or VIX?

        Comment


          #5
          Hi koganam,

          thank you for your reply. The chart instrument. I think you are referring to my Historical return. I should do if BIP!=0 return to have the chart instrument. (Correct?)

          The purpose of this thread here is that I have issues when adding Vix, because there is immediately an error message in logtab when I change eg from $USOIL to ^VIX. (also between 10:00 AM and 3:00 PM). So I tried to find the reason beginning from 0 and testing all behavior.

          By the way, as you are an experienced user I know from your replies in the forum, do you have an idea why a script strategy working OK with Add($USOIL..) or Add(CL...) does cause error messages when only(!) changing from Add($USOIL...) to Add(^VIX...)? In the script I only have Closes[dataseries VIX][0]>Opens[dataseries VIX][0].This is causing me the problems.

          Thanks
          Tony
          Last edited by tonynt; 10-08-2016, 02:55 AM. Reason: clearifiying

          Comment


            #6
            Originally posted by tonynt View Post
            Hi koganam,

            thank you for your reply. The chart instrument. I think you are referring to my Historical return. I should do if BIP!=0 return to have the chart instrument. (Correct?)

            The purpose of this thread here is that I have issues when adding Vix, because there is immediately an error message in logtab when I change eg from $USOIL to ^VIX. (also between 10:00 AM and 3:00 PM). So I tried to find the reason beginning from 0 and testing all behavior.

            By the way, as you are an experienced user I know from your replies in the forum, do you have an idea why a script strategy working OK with Add($USOIL..) or Add(CL...) does cause error messages when only(!) changing from Add($USOIL...) to Add(^VIX...)? In the script I only have Closes[dataseries VIX][0]>Opens[dataseries VIX][0].This is causing me the problems.

            Thanks
            Tony
            You need to check all your BarSeries for validity.

            ref: http://ninjatrader.com/support/forum...15&postcount=1

            Comment


              #7
              thank you for the link. when I do so exactly then the message persists. I think I have to refer to the dataseries in concern, but I dont know how to modify. THANK YOU!
              for (int index = 0; index < BarsArray.Length; index++) { if (CurrentBars[index] < this._intEscapeBars) return; }

              Comment


                #8
                Originally posted by tonynt View Post
                thank you for the link. when I do so exactly then the message persists. I think I have to refer to the dataseries in concern, but I dont know how to modify. THANK YOU!
                for (int index = 0; index < BarsArray.Length; index++) { if (CurrentBars[index] < this._intEscapeBars) return; }
                What value did you assign to _intEscapeBars?

                You may have to do some more extensive debugging to pin point your problem. Start by printing out the values that you suspect may be causing your problem, and see if they match what you expect.

                I have given you a solution that points to a rather specific error message, so if you are still getting an error, then you will have to determine on your own why you are getting the error, as I cannot see your entire code to determine what specifically is wrong in this particular case.

                Comment


                  #9
                  Thank you for your reply.

                  I did not assign a value, I copied and pasted from the thread. Where should I assign?

                  Thanks
                  Tony

                  Comment


                    #10
                    Originally posted by tonynt View Post
                    Thank you for your reply.

                    I did not assign a value, I copied and pasted from the thread. Where should I assign?

                    Thanks
                    Tony
                    How do you mean? In the thread to which I pointed you, there is a value assigned. You can always use a fixed stated value instead of an assigned integer.

                    I have been responding to you on the assumption that you know the rudiments of how to program. Your last post leads me to think otherwise. I would suggest that you get the rudiments down: it really is impossible to teach rudimentary programming in the context of a Q&A forum. I am not trying to put you down: I really do want to help anyone to whom I respond, but I am simply stating the difficulty that there is if a responder has to guide you at every single step, including the most elementary step of assigning a value to a variable, and where to do it.

                    The real first step is to simply open up the NT Help file and work through all the examples until you understand how the NT framework structures things at the most rudimentary level. Then it might pay to crack open some C# resources.

                    All the best.

                    Comment


                      #11
                      Hi koganam,

                      thanks for your reply. No problem with constructive critical reply. And from you point of view I understand. Of course I know how to assign a value to a variable eg I built me my own buttons to trade without charttrader;-)

                      I do not understand you specific solution, thats it.

                      All the best to you as well!
                      Tony

                      Comment


                        #12
                        Originally posted by tonynt View Post
                        I do not understand you specific solution, thats it.
                        What don't you understand about it?

                        Code:
                                    for (int index = 0; index < BarsArray.Length; index++) 
                                    {
                                        if (CurrentBars[index] < this._intEscapeBars) return;
                                    }
                        BarsArray is an array of Bars (literally), so looping from zero to BarsArray.Length is like looping through all BarsInProgress values.

                        You know that BarsInProgress value of 0 means the primary bar series, right?

                        And you know that BIP values 1 and higher represent secondary bar series added via Add() in Initialize(), right? (Which means that if you never add a secondary bar series then BarsArray.Length is set to 1, naturally. And if you add only one secondary bar series then BarsArray.Length is set to 2, naturally.)

                        So, what is that CurrentBars array thing doing in there?

                        Well, naturally, you looked that up, right?

                        After a wee bit of study and thought, you can easily surmise this code is trying to make sure that each bar series has a certain same minimum number of bars, right?

                        Koganam's code said the minimum number of bars for each bar series is 1, you see that right? That's the variable _intEscapeBars.

                        Variables can start with an underscore character, so this name is valid. Underscores used as beginning characters are common in the world of programming to indicate a truly "internal" variable who's scope should be limited -- it's an idiom, that's all.

                        Yes, pause here and look up idiom, it's important in programming.

                        So, we know _intEscapeBars is a global variable, but that underscore '_' prefix says it has limited scope. (How do we 'know' that? Because, generally, the usage of a '_' prefixed global variable means it is used relatively local to where it is defined; that's the idiom.)

                        So, why does he use 'escape' in that name? Because, if there are not enough bars in each bar series, the code immediately returns from OnBarUpdate() -- ergo, the code 'escapes' from further processing via return.

                        Piece of cake, right?

                        Btw, I agree with Koganam. I am surprised any of this code tripped you up. Your tone sounded like you were relatively well-informed about programming, up until your last post, that is.
                        Last edited by bltdavid; 10-13-2016, 09:44 AM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Behungr101, Today, 10:17 AM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_JustinD  
                        Started by ezrollin, Today, 10:11 AM
                        3 responses
                        11 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by xmess777, Yesterday, 07:16 PM
                        2 responses
                        25 views
                        0 likes
                        Last Post xmess777  
                        Started by 8033075, Yesterday, 08:13 PM
                        1 response
                        35 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by futurenow, Yesterday, 06:13 PM
                        1 response
                        25 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Working...
                        X