Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

2nd timeframe, Calculate.OnEachTick: but 2nd timeframe [0] is last historical candle

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

    2nd timeframe, Calculate.OnEachTick: but 2nd timeframe [0] is last historical candle

    [have moved my inquiry to another thread which illustrates the issue for another user who had a similar but different problem. Thanks!]
    Last edited by catinabag; 03-31-2020, 08:33 AM.

    #2
    Hi catinabag, thanks for your note.

    Try turning on Tick Replay. (be sure to read "How to Enable Tick Replay") You will get historical ticks on the secondary series up until the point of the first real-time tick. Things like "IsFirstTickOfBar" work as expected on the historical to real time transition with tick replay on.

    Please let me know if this does not resolve your inquiry.

    Comment


      #3
      Hi, appreciate the email.

      Actually, the "simple approach" as I interpreted your message did not work.

      A simple approach based on your message:
      1. I went to Control Center -> Tools -> Options -> Market Data -> <check Show Tick Replay>
      2. I added the code: "if(IsFirstTickOfBar){ " with a "}" at the end, so that this statement encapsulates the entirety of OnBarUpdate().

      **This didn't do anything at all.**

      B. A more complicated approach
      1. It seems I would have to reference the historical secondary timeframe data in OnBarUpdate() but then get the current data from OnMarketData().
      2. Then, I would somehow combine these data into a single formula, and then *that* would be useful.
      3. I have no idea where the entry and exit logic would reside since, presumably, OnMarketData() comes after OnBarUpdate() in the code, and all my entry/exit stuff is in OnBarUpdate().

      So, I have the following questions:
      (i) Did I get it right when I described what needs to be done via my "B" entry above?
      (ii) Do you have any sample code that shows the approach in "B"?
      (iii) I'm troubled to read that "Tick Replay" and OnMarketData() are very data intensive. Does this mean it will lead to a system crash?

      Thank you!

      Comment


        #4
        In addition to my questions in the prior post, I thought it would be helpful to post a sample code and picture to illustrate the issue.

        This simple code is plotting the High[0] of the five-minute datafeed.

        namespace NinjaTrader.NinjaScript.Strategies
        {
        public class TEST2 : Strategy
        {

        private Series<double> test;


        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Strategy here.";
        Name = "TEST2";
        Calculate = Calculate.OnEachTick;
        EntriesPerDirection = 1;
        EntryHandling = EntryHandling.AllEntries;
        IsExitOnSessionCloseStrategy = true;
        ExitOnSessionCloseSeconds = 30;
        IsFillLimitOnTouch = false;
        MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
        OrderFillResolution = OrderFillResolution.Standard;
        Slippage = 0;
        StartBehavior = StartBehavior.AdoptAccountPosition;
        TimeInForce = TimeInForce.Gtc;
        TraceOrders = false;
        RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
        StopTargetHandling = StopTargetHandling.PerEntryExecution;
        BarsRequiredToTrade = 20;
        AddPlot(Brushes.Blue, "StrategyPlot");
        // 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.Minute, 5);
        }
        else if (State == State.DataLoaded)
        {
        test = new Series<double>(this, MaximumBarsLookBack.Infinite);

        }


        }
        protected override void OnBarUpdate()
        {
        if (BarsInProgress != 0)
        return;

        if (CurrentBars[0] < 1
        || CurrentBars[1] < 1)
        return;

        test[0] = Highs[1][0];

        StrategyPlot[0] = test[0];

        // Set 1
        if (test[0] == 0)
        {
        EnterLongLimit(Convert.ToInt32(DefaultQuantity), (Close[0] + (-2 * TickSize)) , "");
        }

        // Set 2
        if (test[0] == 100000)
        {
        ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
        }

        // Set 3

        }

        #region Properties

        public Series<double> StrategyPlot
        {
        get { return Values[0]; }
        }
        #endregion

        Now, let's look at the picture. You'll see the orange plot is *5 minutes late* on the 1st through 4th minutes and 6th through 9th minutes of the chart.

        Please take a look at the picture. I would like the orange line to be shifted five minutes to the left!

        I would be very grateful if someone could please explain to me the simple solution to this problem. Thank you!

        Comment


          #5
          [have moved my inquiry to another thread which illustrates the issue for another user who had a similar but different problem. Thanks!]
          Last edited by catinabag; 03-31-2020, 08:33 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, 03-13-2026, 05:17 AM
          0 responses
          87 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          151 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          79 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          53 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          62 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X