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

Entering on break of previous bar

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

    Entering on break of previous bar

    I can't seem to figure out a way to use the Strategy Builder to enter a trade when price breaks above or below the previous bar. For example, if conditions are met and the price ticks 1 tick above the previous bar, I want to enter long. How do I set that up using the Strategy Builder?

    #2
    Hello srtrader,

    Thanks for writing in.

    I understand that you would like to create a strategy in the Strategy Builder that places an entry order when the current bar is greater than the previous bar.

    To do this in the Strategy Builder, you would create a condition that checks if the Close price with a Bars Ago value of 0 (Close[0]) is greater than the Close price with a BarsAgo value of 1 (Close[1]). See the attached screenshot demonstrating what this looks like in the Strategy Builder.

    Then, you could create an action of something like EnterLong() to enter a long position when the current bar is greater than the previous bar.

    Also, see the help guide documentation and training video linked below for more information.

    Making Price Data Comparisons: https://ninjatrader.com/support/help...ataComparisons

    Strategy Builder 301 — https://www.youtube.com/watch?v=_KQF2Sv27oE&t=13s

    Note that if you run the strategy with a Calculate mode of OnBarClose, the strategy will process data and place orders at the close of the bar. To have the strategy process more frequently, you would need to run it with a Calculate mode of OnEachTick or OnPriceChange.

    See this help guide for more information about Calculate: https://ninjatrader.com/support/help.../calculate.htm

    Let us know if we may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for replying so quickly. I think I understand this a bit more now. I set it up like this but I'm having issues with the backtesting. I set up the chart for Tick Replay and the strategy calculate OnEachTick. But the entry points for the trade are not when the current bar breaks the high of the previous bar. The entry point is the Open of the current bar. Also, instead of showing taking 1 trade at each valid entry, it takes hundreds of trades at each entry. See attached picture. Any idea what I'm doing wrong?

      Attached Files

      Comment


        #4
        Hello srtrader,

        Thanks for your note.

        If you are running your strategy with Calculate.OnEachTick, this could cause multiple entries to take place if your order entry condition becomes true for each incoming tick. You could consider using a bool to control when trades are placed. You would create a bool (initially set to false), you would create your entry order condition and flip the bool to true. Then, you would check if the bool is true, call your entry order method, and set the bool to false. This way, trades are only placed when the bool is true.

        Ultimately, to understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.
        https://ninjatrader.com/support/foru...121#post791121

        It is expected that a strategy running real-time (live brokerage account, live market simulation, Playback connection etc...) will produce different results than the performance results generated during a backtest.

        Please review the help guide document on the differences on real-time vs backtest (historical).
        http://ninjatrader.com/support/helpG...ime_vs_bac.htm

        When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.

        Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.

        Below is a link to the help guide on Calculate.
        https://ninjatrader.com/support/help.../calculate.htm

        To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar. Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.

        High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

        Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

        SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm

        TickReplay — https://ninjatrader.com/support/help...ick_replay.htm

        Developing for Tick Replay -
        https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay

        Additional information may be found in this NinjaTrader Forum post —
        https://ninjatrader.com/support/foru...mance?t=102504

        Please let us know if we may be of further assistance to you.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by nandhumca, Today, 03:41 PM
        0 responses
        4 views
        0 likes
        Last Post nandhumca  
        Started by The_Sec, Today, 03:37 PM
        0 responses
        3 views
        0 likes
        Last Post The_Sec
        by The_Sec
         
        Started by GwFutures1988, Today, 02:48 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        6 responses
        33 views
        0 likes
        Last Post ScottWalsh  
        Started by frankthearm, Today, 09:08 AM
        10 responses
        36 views
        0 likes
        Last Post frankthearm  
        Working...
        X