I am new to indicore and am taking my first steps in learning. I have tried to modify one of the examples from the documentation. When I run it in the editor/debugger it displays fine but when I attach it to a chart in marketscope it won't draw.
Here is the code:
- Code: Select all
function Init()
indicator:name("Show Yesterday Close")
indicator:description("The indicator shows yesterday's close value on the chart")
indicator:requiredSource(core.Tick)
indicator:type(core.Indicator)
indicator.parameters:addColor("clr", "Indicator Line Color", "", core.rgb(255, 0, 255))
end
local source -- indicator source data
local first -- first available source data
local loading -- the loading day data flag
local TFsource
local offset
local weekoffset
local output
local window = 3
local val
local newCycle
function Prepare()
local name
name = profile:id() .. "(" .. instance.source:name() .. ")"
instance:name(name)
source = instance.source
first = source:first()
loading = false
local host = core.host
output = instance:addStream("output", core.Line, name, "output", instance.parameters.clr, first)
TFsource = host:execute("getSyncHistory", source:instrument(), "H1", source:isBid(), 0, 100, 101)
end
function Update(period, mode)
if period < first then
return
end
if loading then
return
end
newCycle = barCycleBegin(isNewBar(TFsource), window)
--trace("update --> newCycle: " .. tostring(newCycle))
if newCycle then
val = getHighestClose(TFsource, window)
end
--trace("update --> val: " .. tostring(val))
output[period] = val
end
function AsyncOperationFinished(cookie, success, error)
if cookie == 101 then
loading = true
elseif cookie == 100 then
assert(success, error)
loading = false
instance:updateFrom(0)
end
end
function getHighestClose(stream, rangeSize)
local size = stream:size() - 1
local min, max
min, max = mathex.minmax(stream.close, size - rangeSize + 1, size)
return max
end
do
local previous
function isNewBar(stream)
local bang = false
local current
current = stream:size() - 1
previous = previous or 0
if current > previous then
previous = current
bang = true
end
return bang
end
end
do
local counter
function barCycleBegin(trigger, cycle)
local bang
if counter == nil then bang = false end
counter = counter or 0
if trigger then counter = counter + 1 end
if counter == cycle + 1 then
counter = 1
bang = true
else
bang = false
end
return bang
end
end
function trace(string)
core.host:trace(string)
end
Any help would be much appreciated.
Thanks!