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

PercentComplete question

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

    PercentComplete question

    i'm trying to find the best way to run condition checking code within a CalcOnBarClose=False indicator

    i tried making a pause loop but failed to realize that it may change the positioning of my peaks and valleys (checking for divergence) before the bar is closed
    and it does - i get all kinds of erratic behavior because each time it runs through the condition check there is a chance that the peak or valley it's looking at will shift during the time the bar is built

    so now i think i need to check only once at some point towards the end of the bar being built for the divergent condition

    will PercentComplete serve to allow only one run through of the condition check once the bar has built to that point ?

    ie

    if (Bars.PercentComplete == .75)
    {
    run condition check;
    }

    just want to make sure the condition check is run only once as running it more than once on a bar messes things up

    thanks,
    wes

    #2
    Hello Wes,

    Thank you for your post.

    PercentComplete would not make it so only one run through occurs, due to the fact that the condition would return true every tick after the percentage was complete that you specify.

    In this case I would recommend using FirstTickOfBar if you only want one item to run once yet continue to have the script run CalculateOnBarClose = false. You can find an example of this at the following link: http://www.ninjatrader.com/support/f...ad.php?t=19387

    Please let me know if you have any questions.

    Comment


      #3
      Originally posted by stafe View Post
      i'm trying to find the best way to run condition checking code within a CalcOnBarClose=False indicator

      i tried making a pause loop but failed to realize that it may change the positioning of my peaks and valleys (checking for divergence) before the bar is closed
      and it does - i get all kinds of erratic behavior because each time it runs through the condition check there is a chance that the peak or valley it's looking at will shift during the time the bar is built

      so now i think i need to check only once at some point towards the end of the bar being built for the divergent condition

      will PercentComplete serve to allow only one run through of the condition check once the bar has built to that point ?

      ie

      if (Bars.PercentComplete == .75)
      {
      run condition check;
      }

      just want to make sure the condition check is run only once as running it more than once on a bar messes things up

      thanks,
      wes
      That would be only one piece of it. You will want to add a boolean check to know that it has run, and not run it again.

      Code:
      private bool lastBar = -1;
      Code:
      if (Bars.PercentComplete => .75 && lastBar != CurrentBar)
      {
      //run condition check;
      lastBar = CurrentBar;
      }

      Comment


        #4
        thank you koganam, i haven't had a chance yet to implement your solution but as soon as i do i'll let you know how it goes
        thanks again
        /w

        and thank you Patrick H, i had tried that already and posted for a solution other than FTOB since the condition i'm checking for doesn't always exist at first tick of bar
        that was answered by k in another post already (no fair to you having not seen the other post)
        /w

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Tim-c, Today, 03:54 AM
        0 responses
        2 views
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by FrancisMorro, Today, 03:24 AM
        0 responses
        2 views
        0 likes
        Last Post FrancisMorro  
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,770 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        31 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        945 views
        0 likes
        Last Post spwizard  
        Working...
        X