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

1minute close on 5 minute chart or price

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

    1minute close on 5 minute chart or price

    NinjaTrader Support,

    I'm trying to figure out how to trigger orders before bar (5 minute or 10 minute, etc...) closes.
    How would I program a strategy to trigger an order using 1minute price close on 5 minute chart?
    Is it possible to use real-time price data to trigger 5 minute variable such as Bollinger Band?
    I'm not sure if high or low data is "live" and can trigger orders before bar close.

    ie/ Price is above BollingerBand (5m) = submit sell order

    Currrent
    if ((Close < Bollinger.Lower)
    {
    EnterLong(10, @"BuyLong");
    ExitShort(10, @"SellShort","");
    }

    Hoping for:
    if ((Price/Low/Close [1m] < Bollinger.Lower)
    {
    EnterLong(10, @"BuyLong");
    ExitShort(10, @"SellShort","");
    }

    Your help is very much appreciated

    #2
    Hello Blairski,

    Thanks for your post.

    There are a couple of approaches you could take.

    If you set your strategy to Calculate.OnEachTick then Close[0] will represent the current price of the forming bar so this gives you real time data response. So when Close[0] crosses the Bollinger band you can instantly submit an order. The downside of this is that you would need to implement additional coding to prevent multiple orders caused by the entry conditions becoming true multiple times within a bar. A simple way to limit one order per bar is:

    if (Your entry conditions && CurrentBar != savedBar)
    {
    // entry order
    savedBar = CurrentBar; // assign current bar number to integer variable "savedBar"
    }


    In the above example, using the user created variable savedBar, the code block is entered the first time your conditions are true and if the Current bar number is not the same as savedBar. Upon entry of the code block, any orders you have would be placed and the variable savedBar is assigned the value of CurrentBar which will prevent further entry into the code block until the next bar.


    Alternatively, you can add 1 minute bars and check to see if their close crosses the Bollinger band of the 5 minute bar.

    To add a data series, see: https://ninjatrader.com/support/help...dataseries.htm

    In the OnBarUpdate section you would likely want to:

    if (BarsInProgress == 1) // check on the close of the 1 minute bars
    {
    if (CrossAbove(Close, Bollinger(Closes[0], 2, 14).Upper)) // did the 1-minute bar cross above the 5 minute bollinger (note closes[0] points to 5 minute chart bars)
    {
    // enter order on the 1 minute bar
    }
    }

    Adding a data series creates a multi time frame strategy which has very different and specific considerations that are addressed in the following section: https://ninjatrader.com/support/help...nstruments.htm

    In addition, for the entry methods used, please review for the advanced order handling overload so you can submit to the 1 minute bars object.
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by funk10101, Yesterday, 09:43 PM
    1 response
    13 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by TheWhiteDragon, 01-21-2019, 12:44 PM
    5 responses
    551 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by rtwave, 04-12-2024, 09:30 AM
    5 responses
    37 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by funk10101, Today, 12:02 AM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by GLFX005, Today, 03:23 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Erick  
    Working...
    X