• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IsFirstTickOfBar vs OnBarClose giving me different results

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

    IsFirstTickOfBar vs OnBarClose giving me different results

    Hi I have a strategy that runs with the setting option on bar close and works ok when set to this... this is not the problem .

    I rewrote the same version of the strategy utilizing isfirstickofbar for entrys so this way I could take entrances on bar close and exits using on each tick. ( functionally this works)

    when testing both strategy's in market replay they do not take the same entry's and I can not get them to match up.

    I believe the problem is that my stochastic and macd indicator are updating on each tick when strategy is set to on each tick.. if this is the case how can I make sure indicators are set to on bar close while strategy is set to on each tick .

    My goal is to have both strategys which are identical to take the same entry's even though the on each tick and on bar close settings are different

    do you know what else could be the issue if the indicators are not the problem im having?

    #2
    Hello gbux11,

    Thanks for your post.

    Indicators that are added by a hosting NinjaScript will inherit the Calculate mode of the parent NinjaScript. Indicators can be forced to use their own Calculate mode if that indicator has the Calculate mode set in State.Historical. I do not think this is the issue, however.

    As long as you are checking BarsAgo indexes of 1 instead of 0 and have your logic within a IsFirstTickOfBar check, I would expect the same data to be referenced as if you were using BarsAgo indexes of 0 and Calculate.OnBarClose. This should be the same case with indicators unless that indicator generates different plots if it is calculated on each tick or on bar close.

    My recommendation would be to skip historical data in the strategy as this would create a difference in behavior when the strategy processes historical data, and to take debugging steps to analyze the first real time entry and how that entry is getting calculated. If the entry signals are different there must be some part of the logic that is creating the different behavior.

    Although indicators are not used, I have created a demonstration showing how a strategy can use Calculate.OnEachTick and IsFirstTickOfBar to achieve the same results as a strategy with Calculate.OnBarClose.

    Demo - https://drive.google.com/file/d/1k18...w?usp=drivesdk

    Please let me know if I can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      HI Jim,
      The main problem im having I believe looking into this is referencing a stochastic cross using renko, when set to on each tick the stochastic is giving different signals than on bar close. the original look back period was 1 for on bar close , which I changed to 2 for on each tick version.

      How can I set indicators to calculate on bar close when strategy is set to calculate on each tick? can you provide example if possible of how to set it in historical ... or if I have a lookback period of 1 on a stochastic cross , what would the new lookback period be when utilizing isfirsttickofbar?

      thanks for the help.

      Comment


        #4
        Hello gbux11,

        The indicator itself will have to force its own calculate mode in OnStateChange under State.Historical. You could duplicate an indicator to add this modification. Below is an example copying the SMA indicator and adding code to force the calculate mode.

        Code:
        protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionSMA;
                        Name                        = "SMACalculate";
                        IsOverlay                    = true;
                        IsSuspendedWhileInactive    = true;
                        Period                        = 14;
        
                        AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameSMA);
                    }
                    else if (State == State.Configure)
                    {
                        priorSum    = 0;
                        sum            = 0;
                    }
                    else if (State == State.Historical)
                    {
                        Calculate = Calculate.OnBarClose; //Force Calculating on bar close for this indicator
                    }
                }
        I would not recommend changing the look back period when changing from Calculate.OnBarClose to Calculate.OnEachTick. All that should be necessary is to change the BarsAgo reference when you are calculating on the first tick of a new bar when using OnEachTick or OnPriceChange.

        Please let us know if we can be of further assistance.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NT-Roland, Today, 04:36 PM
        0 responses
        2 views
        0 likes
        Last Post NT-Roland  
        Started by Newtrader101, Today, 03:40 PM
        2 responses
        10 views
        0 likes
        Last Post Newtrader101  
        Started by Branpo, Today, 02:58 PM
        2 responses
        7 views
        0 likes
        Last Post Branpo
        by Branpo
         
        Started by sdauteuil, Today, 02:09 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by AMATX, Today, 02:19 PM
        2 responses
        11 views
        0 likes
        Last Post AMATX
        by AMATX
         
        Working...
        X