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

Setting a variable from calculation for the current bar

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

    Setting a variable from calculation for the current bar

    How do write out a calculator for the previous number of bars and store the Highest Open, High, Low, or Close in a variable? I don't seem to be getting the proper results from: exitPrice = HighestBar(High,3,0)

    Furthermore, how do I set that variable for the current bar? For example, if I got "exitPrice = (HighestBar(High,3,0)" to work, and then attempt to use the same variable for an exit as in, "EnterLongStopMarket(Convert.ToInt32(DefaultValue) ,exitPrice, @"EnterLong");", the variable exitPrice that was set for bar[0] on bar close will not update until the next bar. It will use the previously assigned price of the variable until that bar closes.

    So how can I update a variable OnBarClose and use it for that same bar?

    Thank you,

    #2
    Hello smcllr,

    HighestBar returns the bars ago for the highest bar given the parameters you input. https://ninjatrader.com/support/help...sub=HighestBar

    To know the OHLC for the found bar you would use:

    Code:
    int highestBarsAgo = HighestBar(High, Bars.BarsSinceNewTradingDay);
    
    //evaluate high price from highest bars ago value
    double highestPrice = High[highestBarsAgo];
    You can do that with any of the series like Close etc to find the highest value on that series.

    For the rest of your question, if you go by the above example then the highestPrice variable could be used with your order. You can define a variable like that for any price you need, if the variable is defined within OnBarUpdate then its value will only persist for the CurrentBar.

    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    14 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Yesterday, 07:51 PM
    0 responses
    14 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,983 views
    3 likes
    Last Post jhudas88  
    Working...
    X