Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 DJ888, 04-16-2024, 06:09 PM
          4 responses
          12 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by terofs, Today, 04:18 PM
          0 responses
          7 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by nandhumca, Today, 03:41 PM
          0 responses
          6 views
          0 likes
          Last Post nandhumca  
          Started by The_Sec, Today, 03:37 PM
          0 responses
          3 views
          0 likes
          Last Post The_Sec
          by The_Sec
           
          Started by GwFutures1988, Today, 02:48 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Working...
          X