• 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

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.
    Chris L.NinjaTrader Customer Service

    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 leodrz, Today, 09:45 PM
          2 responses
          13 views
          0 likes
          Last Post leodrz
          by leodrz
           
          Started by habibalex, Today, 09:30 PM
          0 responses
          7 views
          0 likes
          Last Post habibalex  
          Started by Herrwolf1, Today, 09:07 PM
          0 responses
          5 views
          0 likes
          Last Post Herrwolf1  
          Started by nomadmilo, Today, 08:52 PM
          1 response
          8 views
          0 likes
          Last Post nomadmilo  
          Started by jvanelli, Today, 08:48 PM
          0 responses
          5 views
          0 likes
          Last Post jvanelli  
          Working...
          X