PDA

View Full Version : CalculateOnClose - mixed processing onFirstTick and on everyTick - Logic Sense Check


MicroTrends
04-23-2010, 01:39 PM
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...

NinjaTrader_Brett
04-23-2010, 03:13 PM
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 (http://www.ninjatrader-support.com/HelpGuideV6/FirstTickOfBar.html)