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

Enter at the close price of range bars.

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

    Enter at the close price of range bars.

    Hi,

    I want to develop a strategy to enter at the close price of a range bar. I wrote this:
    Code:
    if(Close[0]>Open[0]) {
    EnterLong();
    }
    But it enters a the open price of the next bar, I need to enter at the close price of a range bar. I have also tried to AddDataSeries(1 tick)
    Code:
    if(Closes[1][0] > Opens[0][0] && Closes[1][0] == Lows[0][0] + (num_tick-1) * TickSize) {
    EnterLong();
    }
    This way it is also entring at open price, what can I do?

    Thank you

    #2
    Hello lju45,

    Thanks for your post.

    I understand that you are running a strategy with a mode of Calculate.OnBarClose and the order markers are appearing on the open of the next bar. This behavior would be expected.

    If your strategy is set to run in the mode of Calculate.OnBarClose, this means that the strategy code executes once at the end of each bar and will perform calculations on completed bars. If your strategy determines to enter an order, the order marker would be placed on the next bar. In this mode, your strategy will operate the same historically as it does when connected to real-time (or replay) data.

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

    Comment


      #3
      Thanks for your answer, yes I used OnBarClose so I understand first way to enter (if(Close[0] > Open[0]) will enter always in the next bar. However, when I add the DataSeries of 1 tick, I can take entries intra bar but how can I do to enter always at the close price in a range bar?

      Comment


        #4
        Hello lju45,

        Thanks for your note.

        If you are adding a 1-Tick data series to your script with AddDataSeries(), and want to enter at the close of the bar, you could create a condition that checks if(IsFirstTickOfBar) in your script and call your entry order method inside this condition. IsFirstTickOfBar indicates if the incoming tick is the first tick of a new bar. Note that this property is only of value in scripts that run tick by tick which is when the Calculate property is set to Calculate.OnEachTick or Calculate.OnPriceChange.

        You could separate logic in your script between Calculate.OnEachTick/OnPriceChange and OnBarClose using IsFirstTickOfBar. Please note that a hosted script will inherit the Calculate mode of the script that hosts it. You can take the following approach to differentiate logic between OnBarClose and OnEachTick processing.

        Please see this reference sample which demonstrates a technique used for those who need to separate their logic to calculate some values on each tick and others only on the close of a bar. You will set your host script to Calculate.OnEachTick and use if(IsFirstTickOfBar) and place all code that needs to calculate once every bar within that condition check. Then place all code that you want to calculate OnEachTick outside of the IsFirstTickOfBar condition check.

        SampleEnterOnceExitEveryTick -https://ninjatrader.com/support/help...either_cal.htm

        IsFirstTickOfBar: https://ninjatrader.com/support/help...ttickofbar.htm

        Please let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thank you Brandom,

          I have used it but still enter at the open price and no the close. isFirstTickofBar take the open price and in range type the Open and Close are not the same.
          Hope you can help me.

          Thanks
          Attached Files

          Comment


            #6
            Hello lju45,

            Thanks for your note.

            Since you are using Range bars, the price that the order will get filled at if the order is triggered on the closure of a bar would be the open price.

            For example, say an 8 Range bar is being used.A limit order could be submitted when you are 7/8 completeness of the Range bar. However, since this is a tick based/range based bar, we will never really know when the bar will close so we would not be able to determine where/when the limit order would be placed.

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

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bmartz, 03-12-2024, 06:12 AM
            2 responses
            19 views
            0 likes
            Last Post bmartz
            by bmartz
             
            Started by funk10101, Today, 12:02 AM
            0 responses
            3 views
            0 likes
            Last Post funk10101  
            Started by gravdigaz6, Yesterday, 11:40 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by MarianApalaghiei, Yesterday, 10:49 PM
            3 responses
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by XXtrader, Yesterday, 11:30 PM
            0 responses
            4 views
            0 likes
            Last Post XXtrader  
            Working...
            X