Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate Both on Bar close and Each Tick

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

    Calculate Both on Bar close and Each Tick

    I need to handshake my indicator with my strategy immediately after an order is placed/detected. My Indicator because of the load only calculates on Bar Close.
    Can I alter the structure in the following way to check for a Handshake on each tick
    and process the rest of the multi Time frame indicator on Bar close.

    Here is what I think I could be done. Is this going to work as I expect ?

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class CalculateOnBarClose : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Set a portion of Indicator to Update on Each Tick";
    Name = "CalculateOnBarClose";
    Calculate = Calculate.OnEachTick;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    if (IsFirstTickOfBar )
    {
    // HandShake with Strategy
    }
    else
    switch(BarsInProgress)
    {
    // MultiTime Frame Code normally processsed on Bar Close is processed here.

    }
    }
    }
    }

    #2
    Hello JerryWar,

    Thanks for opening the thread.

    The code outlined in OnBarUpdate() will iterate with each incoming tick with Calculate set to Calculate.OnEachTick. You will see IsFirstTickOfBar iterate once on each new bar, but you will see multiple iterations in the else statement for each tick that builds the bar.

    You can use IsFirstTickOfBar to take certain actions that occur for the close of a bar. I would suggest to limit the code in the else statement to only process for the BarsInProgress and what you need to update with each incoming tick.

    Keep in mind, if you want to reference the bar value that had just closed when using OnEachTick, you will want to reference the previous bar within IsFirstTickOfBar.

    Please let me know if I can be of further help.

    Comment


      #3
      JIm
      You made me realize I had the logic backwards. I want to process on the Handshake on the Else condition ( which is every tick ) and the BarsInProgress on the isFirstTick ( Close of bar condition )

      Thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      88 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      48 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      31 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      34 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      69 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X