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

Disable auto loop

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

    Disable auto loop

    Can I disable the auto loop so that I start from the oldest bar instead of the latest bar using a manual loop?

    Call it a learning disability, but I'm trying to adapt some of my VB.net code and I'm having a hard time thinking "backwards in time".

    Thanks,

    Paul

    #2
    Not sure I follow...What is an auto loop?
    RayNinjaTrader Customer Service

    Comment


      #3
      implied loop in ninja script

      In Ninja script you don't have to explicitly include a "for loop", you just enter what you want to calculate, indexed from the most recent bar. For example, if is want to calulate the different between todays close versus yesterdays close I would include the following line in the body of the code.

      Close(0) - Close(1)

      There is an implied loop already written into the script. What I want is to disable this part so I can do my calculation starting from the oldest bar. Like this

      Code:
       
      for (i=0; i < #ofbars; i++)
      {
      Close(i) - Close(i-1)
      }
      Thanks

      Comment


        #4
        Try something like this:

        Code:
        [FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] ([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] index = Count -[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; index >= [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; index--) [/SIZE][/FONT]
        [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
        [SIZE=2][FONT=Courier New]Print(Close[index]);[/FONT][/SIZE]
        [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
        RayNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Brevo, Today, 01:45 AM
        0 responses
        2 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        3 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        238 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Started by oviejo, Today, 12:28 AM
        0 responses
        4 views
        0 likes
        Last Post oviejo
        by oviejo
         
        Working...
        X