Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    65 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    139 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X