• 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

Strategy Indicator on Different Calculate Method then Strategy does not work

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

    Strategy Indicator on Different Calculate Method then Strategy does not work

    When using a different Calculate method for an indicator in your strategy then what your strategy is running is not working. I uploaded a test that can duplicate my results. I made a copy of the EMA and set its
    PHP Code:
    (State ==State.HistoricalCalculate =Calculate.OnBarClose
    I set my strategy to Calculate =Calculate.OnEachTick.

    As you can see from the below print statements, the prints from the indicator are calculating correctly on the bar close but the strategy does not see these results unless the strategy is using the same Calculate method as the indicator. The results for the emas from the strategies perspective is ZERO.

    The strategy works perfectly well using historical data (for obvious reasons that it only calculates OnBarClose) but what I mean is that it enters orders in historical but doesn't enter orders in Real Time, meaning how I am calling the indicator to get its values is correct.

    <REALTIME>
    From Indicator- Calculate.OnBarClose1 Min Heiken-Ashi 10:29:00 PM Current Bar #: 6087 EMA: 1.13698849230083
    From Strategy - Calculate.OnBarClose 1 Min Heiken-Ashi 10:29:00 PM Current Bar #: 6087 ema_a: 1.13698849230083
    From Indicator- Calculate.OnBarClose1 Min Heiken-Ashi 10:29:00 PM Current Bar #: 6087 EMA: 1.13697405473776
    From Strategy - Calculate.OnBarClose1 Min Heiken-Ashi 10:29:00 PM Current Bar #: 6087 ema_b: 1.13697405473776
    From Indicator- Calculate.OnBarClose1 Min Heiken-Ashi 10:30:00 PM Current Bar #: 6088 EMA: 1.13698949743361
    From Strategy - Calculate.OnBarClose 1 Min Heiken-Ashi 10:30:00 PM Current Bar #: 6088 ema_a: 1.13698949743361
    From Indicator- Calculate.OnBarClose1 Min Heiken-Ashi 10:30:00 PM Current Bar #: 6088 EMA: 1.13697936982517
    From Strategy - Calculate.OnBarClose1 Min Heiken-Ashi 10:30:00 PM Current Bar #: 6088 ema_b: 1.13697936982517
    <REALTIME>
    From Strategy - Calculate.OnEachTick1 Min Heiken-Ashi 10:33:00 PM Current Bar #: 6091 ema_b: 0
    From Strategy - Calculate.OnEachTick 1 Min Heiken-Ashi 10:33:00 PM Current Bar #: 6091 ema_a: 0
    From Strategy - Calculate.OnEachTick1 Min Heiken-Ashi 10:33:00 PM Current Bar #: 6091 ema_b: 0
    From Strategy - Calculate.OnEachTick 1 Min Heiken-Ashi 10:33:00 PM Current Bar #: 6091 ema_a: 0
    From Strategy - Calculate.OnEachTick1 Min Heiken-Ashi 10:33:00 PM Current Bar #: 6091 ema_b: 0
    From Indicator- Calculate.OnBarClose1 Min Heiken-Ashi 10:33:00 PM Current Bar #: 6091 EMA: 1.13702627768273
    From Strategy - Calculate.OnEachTick 1 Min Heiken-Ashi 10:34:00 PM Current Bar #: 6092 ema_a: 0
    From Indicator- Calculate.OnBarClose1 Min Heiken-Ashi 10:33:00 PM Current Bar #: 6091 EMA: 1.13700722068894
    From Strategy - Calculate.OnEachTick1 Min Heiken-Ashi 10:34:00 PM Current Bar #: 6092 ema_b: 0
    From Strategy - Calculate.OnEachTick 1 Min Heiken-Ashi 10:34:00 PM Current Bar #: 6092 ema_a: 0
    From Strategy - Calculate.OnEachTick1 Min Heiken-Ashi 10:34:00 PM Current Bar #: 6092 ema_b: 0
    From Strategy - Calculate.OnEachTick 1 Min Heiken-Ashi 10:34:00 PM Current Bar #: 6092 ema_a: 0
    <REALTIME>
    From Indicator- Calculate.OnEachTick1 Min Heiken-Ashi 10:39:00 PM Current Bar #: 6097 EMA: 1.13694239544264
    From Strategy - Calculate.OnEachTick 1 Min Heiken-Ashi 10:39:00 PM Current Bar #: 6097 ema_a: 1.13694239544264
    From Indicator- Calculate.OnEachTick1 Min Heiken-Ashi 10:39:00 PM Current Bar #: 6097 EMA: 1.13697587396995
    From Strategy - Calculate.OnEachTick1 Min Heiken-Ashi 10:39:00 PM Current Bar #: 6097 ema_b: 1.13697587396995
    From Indicator- Calculate.OnEachTick1 Min Heiken-Ashi 10:39:00 PM Current Bar #: 6097 EMA: 1.1369490621093
    From Strategy - Calculate.OnEachTick 1 Min Heiken-Ashi 10:39:00 PM Current Bar #: 6097 ema_a: 1.1369490621093
    From Indicator- Calculate.OnEachTick1 Min Heiken-Ashi 10:39:00 PM Current Bar #: 6097 EMA: 1.13697920730328
    From Strategy - Calculate.OnEachTick1 Min Heiken-Ashi 10:39:00 PM Current Bar #: 6097 ema_b: 1.13697920730328




    Attached Files

    #2
    Hello cutzpr,

    Thanks for your post.

    I notice your are using BarsAgo 0 references in your script. This will show differences when calculating OnEachTick with your strategy and OnBarClose with the indicator.

    When using Calculate.OnEachTick, we constantly recalculate the developing bar (BarsAgo 0.) When Calculating.OnBarClose, we are not calculating the developing bar, but referencing that bar when the bar closes.

    If you would like to make OnBarClose referencing when using OnEachTick/OnPriceChange, you will have to check BarsAgo 1 of the opening tick of the next bar. This can be done by checking:

    if (IsFirstTickOfBar) Print(Indi[1]); // Print the value of the bar after it has closed.

    I've attached an example that can show using IsFirstTickOfBar with BarsAgo 1 references to mimic OnBarClose behavior with BarsAgo 0. This example also demonstrates accounting for calculating historical data with and without using Tick Replay where the NinjaScript may not be forced to calculate OnBarClose.

    Publicly available documentation on IsFirstTickOfBar can be found here - https://ninjatrader.com/support/help...ttickofbar.htm

    Please let me know if you have any additional questions.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Jim,

      Thank you for the clarification. I thought since the indicator is Set to OnBarClose, that its last value it calculated would still be at position[0] until a new bar was formed. This makes sense now.

      Comment


        #4
        Jim,

        Thank you very much, that seems to work. But I have one question, how could I take advantage of IsRising and IsFalling using this method since I cant specify which bar to look at (by default it will look at the current [0])

        Would I be forced to do something like - if(a[1] > a[2] && a[2] > a[3]) while using usePrevBarsAgo

        Comment


          #5
          Hello cutzpr,

          Yes, you would have to use logical statements or a loop to check the Series from a specified number of bars ago.

          for example:

          if (Close[i] > Close[i+1]) where "i" is the bars ago you wanted to check or to see if you are rising at that bar.

          Let me know if there is anything else I can do to help.
          JimNinjaTrader Customer Service

          Comment


            #6
            Thanks Jim

            I will place this here just incase anyone else finds it helpful

            PHP Code:
            public bool zIsFalling(ISeries<doubleseries ,int startBar,int barsBack)
                        {

                            for(
            int i startBarbarsBacki++)
                            {
                                if(
            series[i] > series[i+1]) return false;
                            }

                            return 
            true;

                        }

            public 
            bool zIsRising(ISeries<doubleseries ,int startBar,int barsBack)
                        {

                            for(
            int i startBarbarsBacki++)
                            {
                                if(
            series[i] < series[i+1]) return false;
                            }
                            return 
            true;
                        } 

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by xsgex, Yesterday, 09:46 PM
            0 responses
            2 views
            0 likes
            Last Post xsgex
            by xsgex
             
            Started by Steve L, Yesterday, 09:36 PM
            0 responses
            1 view
            0 likes
            Last Post Steve L
            by Steve L
             
            Started by krugman25, Yesterday, 09:34 PM
            0 responses
            4 views
            0 likes
            Last Post krugman25  
            Started by indy73, Yesterday, 04:42 PM
            0 responses
            15 views
            0 likes
            Last Post indy73
            by indy73
             
            Started by Italianforex, Yesterday, 06:20 AM
            2 responses
            13 views
            0 likes
            Last Post gplatis
            by gplatis
             
            Working...
            X