Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

OnBarUpdate order execution

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

  • asterio
    replied
    Thats works perfect!

    I also notice that indicators are called for OnStateChange: Historical before calling OnBarUpdate().
    That's nice.

    Here is a output working with 1 strategy and 2 indicators using your suggestion.

    >> Strategy is running a regular backtest
    [vT2] : OnStateChange: SetDefaults
    [vT2] : OnStateChange: Configure
    [vOB] : OnStateChange: SetDefaults
    [vOB] : OnStateChange: Configure
    13/03/2018 23:01:00: [vStrategy] : OnStateChange: DataLoaded | Backtest
    13/03/2018 23:01:00: [vT2] : OnStateChange: DataLoaded
    13/03/2018 23:01:00: [vOB] : OnStateChange: DataLoaded
    13/03/2018 21:57:00: [vStrategy] : OnStateChange: Historical | Backtest
    14/03/2018 15:30:00: [vStrategy] : OnBarUpdate from vStrategy
    13/03/2018 21:57:00: [vT2] : OnStateChange: Historical
    14/03/2018 15:30:00: [vT2] : OnBarUpdate from vT2
    13/03/2018 21:57:00: [vOB] : OnStateChange: Historical
    14/03/2018 15:30:00: [vOB] : OnBarUpdate from vOB
    14/03/2018 15:31:00: [vStrategy] : OnBarUpdate from vStrategy
    14/03/2018 15:31:00: [vT2] : OnBarUpdate from vT2
    14/03/2018 15:31:00: [vOB] : OnBarUpdate from vOB
    14/03/2018 15:32:00: [vStrategy] : OnBarUpdate from vStrategy
    14/03/2018 15:32:00: [vT2] : OnBarUpdate from vT2
    14/03/2018 15:32:00: [vOB] : OnBarUpdate from vOB
    14/03/2018 15:33:00: [vStrategy] : OnBarUpdate from vStrategy
    14/03/2018 15:33:00: [vT2] : OnBarUpdate from vT2
    14/03/2018 15:33:00: [vOB] : OnBarUpdate from vOB
    14/03/2018 15:34:00: [vStrategy] : OnBarUpdate from vStrategy
    14/03/2018 15:34:00: [vT2] : OnBarUpdate from vT2
    14/03/2018 15:34:00: [vOB] : OnBarUpdate from vOB
    [vStrategy] : OnStateChange: SetDefaults | NinjaScript
    [vStrategy] : OnStateChange: Terminated | Backtest
    13/03/2018 23:01:00: [vStrategy] : OnStateChange: Terminated | NinjaScript
    13/03/2018 23:01:00: [vT2] : OnStateChange: Terminated
    13/03/2018 23:01:00: [vOB] : OnStateChange: Terminated


    where you can notice how both indicators are update in the same bar as strategy.

    Thanks JoshG!!

    Leave a comment:


  • NinjaTrader_JoshG
    replied
    Hello asterio,
    Thanks for your post.

    You are correct, the strategies OnBarUpdate() would be called first and then the indicators OnBarUpdate() would be called after that. If you require the indicators value to be updated before processing any logic that references that indicators value you can use Update(). Something similar to the following snippet would instantiate an SMA indicator and then force it to update before processing further logic in the strategies OnBarUpdate().

    Code:
    private SMA mySMA;
    protected override void OnStateChange()
    {
         if (State == State.DataLoaded)
         {
               mySMA = SMA(100);
         }
    }
    
    protected override void OnBarUpdate()
    {
    	[B]mySMA.Update();[/B]
    	if (mySMA[0] < Close[0])
    	{
    		[COLOR="SeaGreen"]//do something[/COLOR]
    	}
    }
    I am including a link to the help guide documentation for Update(), for your convenience.

    Update()
    https://ninjatrader.com/support/help...us/?update.htm

    Please let me know if you have any questions.

    Leave a comment:


  • asterio
    started a topic OnBarUpdate order execution

    OnBarUpdate order execution

    Dear team,

    I just notice that when I use an Indicator declared inside a strategy, every time I try to make a simulation with Strategy Analyzer, I see this behavior:

    1. first all the calls to OnBarUpdate() for Strategy class for the period considered
    2. then calls to the OnBarUpdate() for the indicator.

    But for my has no sense as Strategy would make decisions based on Indicator status, I mean, both OnBarUpdate() calls should be called for both within the same bar (actually I'd prefer to call to all indicator before call Strategy to have fresh data.

    What I missing?

    I 'd tried to instantiate indicator on Configure, DataLoaded, Historical, with the same results.

    Thanks in advance
    --
    Asterio

Latest Posts

Collapse

Topics Statistics Last Post
Started by maybeimnotrader, Yesterday, 05:46 PM
2 responses
22 views
0 likes
Last Post maybeimnotrader  
Started by adeelshahzad, Today, 03:54 AM
5 responses
32 views
0 likes
Last Post NinjaTrader_BrandonH  
Started by stafe, 04-15-2024, 08:34 PM
7 responses
32 views
0 likes
Last Post NinjaTrader_ChelseaB  
Started by merzo, 06-25-2023, 02:19 AM
10 responses
823 views
1 like
Last Post NinjaTrader_ChristopherJ  
Started by frankthearm, Today, 09:08 AM
5 responses
22 views
0 likes
Last Post NinjaTrader_Clayton  
Working...
X