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

Multi-Timeframe SMA Condition Evaluation in Strategy Builder

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

    Multi-Timeframe SMA Condition Evaluation in Strategy Builder

    Hello NinjaTrader Community,

    I am working on a trading strategy using the Strategy Builder in NinjaTrader 8, and I've encountered a challenge that I hope you can help me with.

    My strategy is set up to enter trades on a 5-minute chart, but I want to include a condition that involves the real-time value of a 50-period SMA from an hourly chart. The issue I'm facing is that my strategy seems to wait for the hourly bar to close before evaluating the condition, which is causing delays in trade entries.

    Here's what I've done so far:
    1. I've added a 60-minute data series in the Strategy Builder.
    2. I've created a condition where the strategy should enter a long position when the close of the 5-minute bar is greater than the 50-period SMA of the 60-minute series.
    3. The 'Bars ago' is set to '0' for the hourly SMA.

    However, it appears that the strategy waits for the hourly bar to complete before checking this condition, and I would like it to use the latest available hourly SMA value instead of waiting for the bar to close.

    I'm looking for a way to make the strategy evaluate the hourly SMA condition in real-time, on each 5-minute bar close, without having to wait for the hourly bar to finish. Is there a way to achieve this intra-bar evaluation using the Strategy Builder, or do I need to switch to custom NinjaScript coding for this functionality?

    Any advice or guidance on how I can resolve this would be greatly appreciated.

    Thank you in advance for your help!​

    #2
    Hello Hezi100,

    Thank you for your post.

    You can change the Calculate setting for your strategy to change how often OnBarUpdate() is called. The default behavior is Calculate.OnBarClose.

    When calculate is OnBarClose, the most recently updated bar is the previous fully closed bar and not the currently building bar (as you've described in this post).

    When calculate is OnPriceChange/OnEachTick the most recently updated bar is the current building bar. This currently building bar will be the unfinished close, high, low, open, volume of the bar that is currently building and has not closed.

    Calculate - https://ninjatrader.com/support/help.../calculate.htm

    In the Strategy Builder, you can change the Calculate setting in the 'Default Properties' section.

    Please let us know if you have any further questions.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      Thank you for the clarification regarding the `Calculate` setting. I understand that changing it to `OnPriceChange` or `OnEachTick` will allow the strategy to act on intra-bar price movements. However, my strategy requires a hybrid approach where I want to evaluate the 5-minute bar conditions at the close of each bar, while the condition for the hourly SMA should be evaluated in real-time, within the hour, without waiting for the bar to close.

      Is there a way to have different `Calculate` settings for different conditions within the same strategy using the Strategy Builder? Specifically, can I set my strategy to act on the close of 5-minute bars for some conditions and in real-time for the hourly SMA condition, or is this level of control only possible by writing custom NinjaScript code?

      Any guidance on whether this can be achieved within the Strategy Builder or if there is a workaround would be greatly appreciated.

      Thank you for your assistance.​

      Comment


        #4
        Hello,

        You could do this in the Strategy Builder by having a set that checks if IsFirstTickOfBar is true, the code in that set will only be calculated once per bar.



        Please let me know if you have any further questions.
        Gaby V.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by rhyminkevin, Today, 04:58 PM
        4 responses
        52 views
        0 likes
        Last Post dp8282
        by dp8282
         
        Started by iceman2018, Today, 05:07 PM
        0 responses
        5 views
        0 likes
        Last Post iceman2018  
        Started by lightsun47, Today, 03:51 PM
        0 responses
        7 views
        0 likes
        Last Post lightsun47  
        Started by 00nevest, Today, 02:27 PM
        1 response
        14 views
        0 likes
        Last Post 00nevest  
        Started by futtrader, 04-21-2024, 01:50 AM
        4 responses
        50 views
        0 likes
        Last Post futtrader  
        Working...
        X