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

Loop with variable period, why it doesn't work ?

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

    Loop with variable period, why it doesn't work ?

    Hello !

    I can't make work this code :

    Code:
    if (X) {
    Depart = CurrentBar;
    }
    
    PPP = CurrentBar-Depart;
    		
    			
    total=0;
    for (int v=0; v<=PPP; v++) {
    	total = ROT[v] + total;
    }
    If I run this, the indicator doesn't work. If I replace in the loop "PPP" by a fixed number (for example 10) it works. Why ? How can I do ?

    Thanks a lot !

    #2
    Hello After,

    If you print the value of PPP after setting it, what is the value of PPP?

    Is X true when PPP is set? (That would be CurrentBar-CurrentBar which = 0)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea !

      Here you can find the value of PPP.
      Yeah X can be true while PPP is running of course.
      And even with this code it doesn't work

      Code:
      			if (X) {
      				Depart = CurrentBar;
      			}
      			PPP = CurrentBar-Depart;
      		    
      			if (PPP<1){
      				PPP=1;
      			}
      			
      			total=0;
      		    for (int v=0; v<=PPP; v++) {
      				total = ROT[v] + total;
      			}
      Attached Files

      Comment


        #4
        Hello After,

        I am suggesting you use prints to debug your code. Also, your code has changed since your previous post.

        With your previous post, if X is true, then PPP will equal 0. In the last post if X is true then PPP will equal 1.

        Code:
        if (X) {
        Depart = CurrentBar;
        }
        PPP = CurrentBar-Depart;
        Print(Time[0]+" - PPP: "+PPP.ToString()); 
        if (PPP<1){
        PPP=1;
        }
        
        total=0;
        for (int v=0; v<=PPP; v++) {
        Print(Time[0]+" - v: "+v+" - ROT[v]: "+RoT[v].ToString());
        total = ROT[v] + total;
        }
        Please post the output this prints from the Output window.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          "I am suggesting you use prints to debug your code. Also, your code has changed since your previous post."

          Yeah you're right sorry. I posted few new lines to show you the problem isn't "X is true while PPP is running"

          I got this :

          "20/02/2014 10:42:00 - PPP: 1001
          This is a message
          Error on calling 'OnBarUpdate' method for indicator 'HUSKYFINAL2' on bar 1001: barsAgo needed to be between 0 and 255 but was 256"
          Last edited by After; 01-02-2015, 03:40 PM.

          Comment


            #6
            Hi After,

            Looks like the issue is the Maximum Bars Lookback.

            Try adding:

            MaximumBarsLookBack = MaximumBarsLookBack.Infinite;

            To Initialize()

            http://www.ninjatrader.com/support/h...rslookback.htm
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              It works ! Thanks Chelsea you're the boss. I didn't know this issue, now yes

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by f.saeidi, Today, 11:02 AM
              1 response
              1 view
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by geotrades1, Today, 10:02 AM
              4 responses
              11 views
              0 likes
              Last Post geotrades1  
              Started by rajendrasubedi2023, Today, 09:50 AM
              3 responses
              15 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by lorem, Today, 09:18 AM
              2 responses
              11 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by geddyisodin, Today, 05:20 AM
              4 responses
              30 views
              0 likes
              Last Post geddyisodin  
              Working...
              X