View Full Version : Which Event handler fires first - OnCalculate or OnTick

06-04-2014, 05:27 PM

As the Heading suggests, I would like to know

When a new candle is formed, which event fires first, The OnCalculate() or OnTick()

My checks suggests OnCalculate triggers first and then the Ontick, but I am not sure about it.

Please help


06-05-2014, 07:25 AM
Hello Edakad,

The OnTick event is fire before the OnCalculate event.

06-05-2014, 07:52 AM
Hello Hassan

I use this simple code to check which one fires first and I think it shows the opposite order, first OnCalculate and then Ontick when newBar is formed.

Please avoid the very fist message u get when the vtl is attached to chart, thereafter it work when new candle is formed.

dim barTime

function newBar()
Dim bTime
bTime = GetTime( 0, Bars(0) - 1 )
IF CDATE(barTime) < CDATE(bTime) Then
barTime = bTime
NewBar = True
Exit Function
End If

NewBar = False

end function

Public Sub main()

End Sub

Public Sub OnTick(symbolName)
if symBolName = chartSymbol() then
if newBar() Then
msgBox "OnTick"
end if
end if
End Sub

Public Sub OnCalculate(symbol, symbolPeriod, openVal, highVal, lowVal, closeVal)
if symbol = chartSymbol() then
msgbox "OnCalculate"
end if
End Sub

06-05-2014, 08:22 AM

You don't need to use this condition,
if newBar() Then .

The ontick() raise with the current price in the first second of the new bar to draw it to the chart.