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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      56 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      133 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X