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.
    JimNinjaTrader Customer Service

    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 Max238, Today, 01:28 AM
      5 responses
      40 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by giulyko00, Yesterday, 12:03 PM
      3 responses
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by habeebft, Today, 07:27 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChristopherS  
      Started by AveryFlynn, Today, 04:57 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by r68cervera, Today, 05:29 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X