Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate not fire

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

    OnBarUpdate not fire

    OnBarUpdate does not fire when applying strategy to a Chart using Market Replay for ES 06-18. I have simplified the code to just display messages in the output window.

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

    protected override void OnStateChange()
    {

    if (State == State.SetDefaults)
    {
    // NinjsAcript Output window
    NinjaTrader.Code.Output.Reset(PrintTo.OutputTab1);
    NinjaTrader.Code.Output.Process("SimpleMACrossOver ", PrintTo.OutputTab1);
    NinjaTrader.Code.Output.Process("State.SetDefaults ", PrintTo.OutputTab1);

    Description = @"SimpleMACrossOver.";
    Name = "SimpleMACrossOver";
    Calculate = Calculate.OnBarClose; //Calculate.OnEachTick
    BarsRequiredToTrade = 20;
    IsInstantiatedOnEachOptimizationIteration = false;

    }
    else if (State == State.DataLoaded)
    {
    NinjaTrader.Code.Output.Process("State.DataLoaded" , PrintTo.OutputTab1);
    }


    else if (State == State.Configure)
    {
    NinjaTrader.Code.Output.Process("State.Configure", PrintTo.OutputTab1);
    }
    }

    protected override void OnBarUpdate()
    {
    NinjaTrader.Code.Output.Process("Here", PrintTo.OutputTab1);
    }

    }
    }
    Attached Files

    #2
    Hello TradingDreamer,

    Thanks for your post.

    I do not see the same results testing with Market Replay Data: https://www.screencast.com/t/lhopHIls

    I did notice in your screenshot that the strategy is not enabled. The strategy will go through the SetDefaults and Configure states when settings are applied before the strategy gets enabled. Upon enablement, DataLoaded, Historical, and then Realtime states will iterate.

    Publicly available documentation for further reading can be found below.

    NinjaScript LifeCycle - https://ninjatrader.com/support/help...fecycle_of.htm

    OnStateChange() - https://ninjatrader.com/support/help...tatechange.htm

    Please let us know if we can be of further assistance.

    Comment


      #3
      Thank you. It's been a while since I have been coding. Enabling my Strategy worked.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      89 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      135 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X