Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Bars.PercentComplete

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

    Using Bars.PercentComplete

    I am developing a strategy that I want to do order management on a per tick basis (for mimicing a trailing stop by adjusting the StopLoss) but only generate buy signals on a closed bar basis.

    Would the following sample code accomplish this or am I missing something?

    Note: The Indicators I use for the BuySignal do have CalculateOnBarClose = true; but I understood from a previous post that if I set strategy to CalculateOnBarClose = false; then that would have the indicators called on every tick, I am hoping the below code works around this.

    Code:
     
    protected override void Initialize()
    {
         CalculateOnBarClose = false;
    }
     
    protected override void OnBarUpdate()
    {
         if (Bars.PercentComplete == 1)
         {
              // Buy Signal processing code
         }
         // Order Management processing code
    }

    #2
    Please check out FirstTickOfBar. Might work better for your purposes...

    Comment


      #3
      Checked into it, but would have me need to recode all my Indicators since they are currently expecting Bar[0] to be current closed bar and Bar[1] to be previous closed bar. Also not sure how this would affect back testing of my indicators/strategy whereas the above does work with backtesting even though it is not tick by tick adjusting the trailing stop.

      Does your reply mean the above would not work as I have indicated or does it mean Bars.PrecentComplete == 1 may not always occur or is there some other issue? I plan on testing it more anyway, so I will let you know the results of those tests anyhow.
      Last edited by bigtrade5; 05-12-2008, 07:08 AM.

      Comment


        #4
        Your approach should also work but as you stated, check it out.
        RayNinjaTrader Customer Service

        Comment


          #5
          Disregard my last post, it likely will not work since PercentComplete likely will never be 100% running tick by tick since we don't know when the bar really is closed until we get the 1st tick of the new bar which is why Dierk suggested checking "FirstTickOfBar" property.
          RayNinjaTrader Customer Service

          Comment


            #6
            I can confirm PercentComplete == 1 does not work, and agree with your assesment of why in last post. I will have to rework my indicators to support using FirstTickOfBar, as this does work as expected, but I need to offset my Indicators by and extra bar (ie. looking at High[1] now instead of High[0], etc).

            Thanks for your help on this, your guys are beyond top notch support for both speed of response and quality of information... I really appreciate it.

            Comment


              #7
              Percent Complete does not work on Price Based Chart Types... How to detect?

              What is a good way to check programatically whether the bar type of the chart hosting an indicator supports the Bars.PercentComplete property? I want to prevent runtime errors on chart types based on price only such as Range and Renko.

              Yes, I know I could test for all the chart types that are either allowed or prohibited. But is there a way to directly test for whether the chart, whatever it is, supports the property? Should I just look for the PropertyNotSupported error and work from that?

              Comment


                #8
                Hi Ricam,

                Testing for the bar type can be used here. I'm not aware of a different way. Generally it's available for time, tick, and volume based charts.

                if (Bars.Period.Id == PeriodType.Minute || Bars.Period.Id == PeriodType.Tick)
                Print(Bars.PercentComplete);
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                648 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                369 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                109 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                573 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                575 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X