Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Current Candle Of Higher Data Series Info

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

    Current Candle Of Higher Data Series Info

    Most of my calculation are run on secondary data series, i.e. 1 tick. I tried running if (IsFirstTickOfBar) calculation, but, as expected, when I run it on 1 tick data series (BarsInProgress == 1), it always evaluates true.

    What I want. My primary data series is 1 minute. So I want to extract current Open/High/Low/Close of 1 minute, i.e. current live bar. If I just put Opens[0][0], when BarsInProgress == 1 (i.e. secondary, 1 tick data series), it would return Open of last closed bar.

    What workaround having 1 tick data series could you suggest to get Open/High/Low/Close of 1 minute (primary data series) = current live bar, when running calculation in secondary BarsInProgress?

    #2
    Hello UltraNIX,

    Thank you for your reply.

    Are you running the strategy OnPriceChange/OnEachTick, or are you running it OnBarClose? You'd need to run it OnPriceChange or OnEachTick to be able to access the currently forming bar's OHLC.

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      I am running OnBarClose. If I switch it to OnEachTick, then I would have to adjust my primary data series calculations, correct? For now I just use
      Code:
      if (BarsInProgress == 0)
      , but if it is calculated OnEachTick, it would mess up my calculations, I suppose.

      Comment


        #4
        Hello UltraNIX,

        Thank you for your reply.

        You could consider adjusting your logic for the primary series to calculate on IsFirstTickOfBar == true, that would only fire off that logic once per bar, right on the first tick, essentially emulating OnBarClose for that series.

        Please let us know if we may be of further assistance to you.

        Comment


          #5
          How would I then get values of Open / High / Low / Close of 1 minute? And, more importantly, how would I reference bars ago properties, like Close[2] (2 bars ago of 1 minute), not Close of 2 ticks before.

          Can you post some code examples or create example code to reference all we talked about:
          1) Reference Open of the currently live bar 1 minute bar.
          2) Reference Close[2] of 1 minute, i.e. 2 bars ago.

          Comment


            #6
            Hello UltraNIX,

            Thank you for your reply.

            Please see the simple code example below:

            Code:
             public class GetOHLCOfPrimaryExample : Strategy
            {
            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = @"Enter the description for your new custom Strategy here.";
            Name = "GetOHLCOfPrimaryExample";
            Calculate = Calculate.OnEachTick;
            EntriesPerDirection = 1;
            EntryHandling = EntryHandling.AllEntries;
            IsExitOnSessionCloseStrategy = true;
            ExitOnSessionCloseSeconds = 30;
            IsFillLimitOnTouch = false;
            MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
            OrderFillResolution = OrderFillResolution.Standard;
            Slippage = 0;
            StartBehavior = StartBehavior.WaitUntilFlat;
            TimeInForce = TimeInForce.Gtc;
            TraceOrders = false;
            RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
            StopTargetHandling = StopTargetHandling.PerEntryExecution;
            BarsRequiredToTrade = 20;
            // Disable this property for performance gains in Strategy Analyzer optimizations
            // See the Help Guide for additional information
            IsInstantiatedOnEachOptimizationIteration = true;
            }
            else if (State == State.Configure)
            {
            AddDataSeries(Data.BarsPeriodType.Tick, 1);
            }
            }
            
            protected override void OnBarUpdate()
            {
            if (CurrentBars[0] < 2)
            return;
            
            if(BarsInProgress == 0)
            {
            if (IsFirstTickOfBar)
            {
            // Do things on primary series here, refer to prior bar data if you want to emulate OnBarClose for this
            }
            }
            
            if (BarsInProgress == 1)
            {
            Draw.TextFixed(this, "MyText", "1 min: Open: " + Opens[0][0] + " High: " + Highs[0][0] + " Low: " + Lows[0][0] + "\nClose:" + Closes[0][0] + " Close of 2 bars ago: " + Closes[0][2], TextPosition.BottomRight);
            
            }
            }
            }
            Please let us know if we may be of further assistance to you.

            Comment


              #7
              I copied your code and ran backtest, but it's not working as expected. Opens[0][0], Highs[0][0], Lows[0][0] refer to most recently closed bar on 1 minute timeframe, not currently live one.

              I adjusted your code and instead of Draw.TextFixed used Print.

              As you can see, I hovered over the last closed bar, and it's values match with those that are printed. However, I want the values of currently open bar, meaning, Close[0][0] should be the current trading price and change on each price change, and Open[0][0] should be current live bar's open, and so on.
              Attached Files

              Comment


                #8
                Hello UltraNIX,

                Thank you for your reply.

                That would be expected when backtesting on historical data. Fills are determined based on 4 data points, OHLC of a bar since that is the only information that is known during a backtest and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.

                Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick'.

                Also, here is a link to the differences on real-time vs backtest (historical).
                http://ninjatrader.com/support/helpG...ime_vs_bac.htm

                To see this working as it would in real time, you can apply it on a regular chart using the Sim101 account, or use it in Playback with Market Replay data.

                Please let us know if we may be of further assistance to you.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                61 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                134 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                75 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                50 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X