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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Working...
      X