Indicator won't draw in marketscope

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

Indicator won't draw in marketscope

Postby jerb13 » Sun Sep 25, 2016 12:11 am

Hi All,

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!
jerb13
 
Posts: 6
Joined: Mon Sep 12, 2016 7:35 pm

Re: Indicator won't draw in marketscope

Postby Apprentice » Tue Oct 04, 2016 2:53 am

Test.lua
(2.1 KiB) Downloaded 978 times

Try this version.

Can you specify what is your end goal?
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Indicator won't draw in marketscope

Postby jerb13 » Tue Oct 04, 2016 12:07 pm

Hi Apprentice,

Thank you for responding. That version does get something to draw on the chart in marketscope, but not what it does in the debugger.

Compare:
Screen Shot 2016-10-04 at 8.06.23 AM.png


With:
Screen Shot 2016-10-04 at 8.24.21 AM.png


Basically what I am interested in being able to do is draw OHLC data from custom/non-starndard higher time frames onto a variety of standard lower time frame charts. So for example, I would like to draw the OHLC information from an "m17" or "m35" time frame onto a m5 or m1 chart; or from an "H7" time frame onto a m30, m15, or H1 chart; or from a "W2" time frame onto a D1 or H8 chart. I guess the HTF would always need to be divisible by the lower time frame.

The example from the documentation found here:
http://www.fxcodebase.com/documents/IndicoreSDK/web-content.html#host.execute_getSyncHistory.html

gives exactly the behavior I want using D1 charts. It takes the close values from the most recently closed period of the HTF and draws it on the smaller time frame chart.

So with intraday time frames, for example, let's say an "m35" HTF drawn onto an m5 chart, from periods 21 to 27 of the m5 chart it would draw the OHLC info from periods 14 to 20.

It would also be nice to be able to offset the HTF OHLC info by an arbitrary amount. So, for example, drawing the data from the "m35" time frame from 3 "m35" bars in the past onto the lower TF chart would mean that on the m5 chart from periods 21 to 27 it would draw the info from periods 0 to 6.

I hope that is clear enough. Again, the version that you gave me and my original version both draw fine in the debugger but either they don't draw in marketscope (mine) or don't draw the same thing that they do in the debugger (yours). I am having a hard time figuring out why.

Any help would be much appreciated.

Regards.
jerb13
 
Posts: 6
Joined: Mon Sep 12, 2016 7:35 pm


Re: Indicator won't draw in marketscope

Postby jerb13 » Wed Oct 12, 2016 8:48 pm

Hi Apprentice,

Yes, pretty much exactly like that. Actually, I have progressed now in my own indicator to this level of functionality. I am currently trying to figure out how to handle the weekends. At the beginning of your code you indicated that as a todo item for your indicator. Were you ever able to find a nice solution for accurately drawing the first few days of the week when using D1 bars as the bigger time frame?

Thanks!
jerb13
 
Posts: 6
Joined: Mon Sep 12, 2016 7:35 pm



Return to Discussions

Who is online

Users browsing this forum: No registered users and 9 guests