Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CalculateOnClose - mixed processing onFirstTick and on everyTick - Logic Sense Check

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

    CalculateOnClose - mixed processing onFirstTick and on everyTick - Logic Sense Check

    If a strategy has the CalculateOnBarClose=False
    OnBarUpdate will fire for every tick

    to only fire order entry once - use FirstTick
    to filter all signals to 1 per bar...
    the order placement logic must look back to the previous signal state
    eg close[1] 1 bar ago

    Works fine....

    if the user overrides and set CalculateOnBarClose=True
    if the same code block is running - filtering on FirstTick
    then the order logic must use close[0] -

    Question: Other than the lookback bar [1] or [0] - Will the same code will be still valid - will FirstTick be the true on bar close.....?
    Or does the logic need seperating out - if anything for maintainability vs minimality....

    Solution A
    pseudo code for CalculateOnBarClose=True
    onBarUpdate
    {
    if HasSignal(close[0]) DoOrder (Signal(Close[0])
    manageStops()
    }

    Solution B
    pseudo code for CalculateOnBarClose=FALSE

    onBarUpdate
    {
    //on FirstTick
    if FirstTick
    {
    if HasSignal(close[1]) DoOrder (Signal(Close[1])
    }
    //on every tick or bar close
    manageStops() etc
    }


    Solution C
    pseudo code for CalculateOnBarClose=FALSE or CalculateOnBarClose=TRUE

    onBarUpdate
    {
    //on FirstTick and CalculateOnBarClose false
    if (!CalculateOnBarClose && FirstTick)
    {
    if HasSignal(close[1]) DoOrder (Signal(Close[1])
    }
    //on bar close - CalculateOnBarClose true
    else if (CalculateOnBarClose)
    {
    if HasSignal(close[0]) DoOrder (Signal(Close[0])
    }

    //on every tick or bar close
    manageStops()

    }


    Would solution B would work in either case - if we use a variable for the barsAgo...?

    Solution B - hybrid -
    CalculateOnBarClose=FALSE
    onBarUpdate
    {
    if (!CalculateOnBarClose) barsAgo = 1

    if FirstTick
    {
    if HasSignal(close[barsAgo]) DoOrder (Signal(Close[barsAgo])
    }
    //on every tick or bar close
    manageStops() etc
    }



    manageStops() can be called onMarketData - but only for realtime.

    I guess Solution C is more elegant as it does not check and set a variable eachtime..... it is also a little more clearer...
    MicroTrends
    NinjaTrader Ecosystem Vendor - micro-trends.co.uk

    #2
    Hello,

    Hello,

    firstTickOfBar is true for every single OnBarUpdate when using CalculateOnBarClose = false. Therefor you still need to use [0] instead of [1] and you would need to create two code blocks to address this.

    http://www.ninjatrader-support.com/HelpGuideV6/FirstTickOfBar.html
    Last edited by NinjaTrader_Brett; 04-23-2010, 03:40 PM.
    BrettNinjaTrader Product Management

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    656 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    371 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    579 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X