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...

Comment