PDA

View Full Version : need help with this script to calculate every bar



Sakr
06-05-2014, 07:47 PM
Hello,

I need help in this script, I think most of it done successfully
but unfortunately and because it's the first time to try with this platform I can't get it work to calculate every bar

it calculated very well once it attached to chart

but I don't know what I should do on function OnCalculate or OnTick to make it work or calculate the signal for new bars
I failed with trying many things explained in Knowledgebase

till now I get it worked for the past bars once I attach it to the chart, but for new bars I have to remove and reattach it again to make it work!

so hope if you can help me with what I should do with this function

Thanks.

Hassan-HS
06-06-2014, 08:25 AM
Hello,

To update a indicator that's located in the chart you have to use SetIndicatorData (http://www.hybrid-solutions.com/support/index.php?/Knowledgebase/Article/View/2663).


This full sample will help you in updating the indicator values on each tick, and on each new bar.

This sample draws indicator with the high price of the candles for the current chart.




Dim indKey

Dim vchartId

Dim vchartName

Dim resultValue

Public Sub Main()

Dim highArry()

vchartId=chartId

vchartName=ChartSymbol(Clng(vchartId))

CopyHigh 0,1, bars(0),highArry

indKey=AddCustomIndicator(0, highArry,0)

End Sub

Public Sub OnTick(SymbolName)
to update the indicator with the highest value
if SymbolName = ChartSymbol(0) then
ObjectSeriesGetValue 0,cstr(vchartName & ".high"),bars(0),resultValue

ObjectSeriesSetValue 0,CSTR(indKey),bars(0),CDBL(resultValue)
end if
End Sub

Public Sub OnCalculate(symbol ,symPeriod, openVal , highVal , lowVal , closeVal )
'to draw the indicator over the new bar
SetIndicatorData 0,CSTR(indKey),CDbl(highVal)

End Sub