I read and try to code but i still have a doubt about "instance.source" at document
Code: Select all
`   function Init()       ...       indicator:requiredSource(core.Tick);       ...   end    local first;    function Prepare()       ...       first = instance.source:first() + 7;       ...   end    function Update(period, mode)       ...       if period >= first then           avg = mathex.avg(instance.source, period - 7 + 1, period);       end       ...   end`

Have a doubt at "first = instance.source:first() + 7;" what's +7 use for? can It use to control latest of stream of source?

and last question if i want to use previous price stream e.g. I want to use MVA at 20 previous step(not period) to calculate or implement new equation, How can i do that?

sorry my poor language is not native in english. Thank you.
Saito_N

Posts: 5
Joined: Tue Mar 21, 2017 3:13 pm

Re: doubt about "instance.source"

"first = instance.source:first() + 7"
Will set 7 candles, as the first candle.

For example, if you're calculating, 7 periods MA
First will be the first candle after which you have enough elements for MA Calculation.

and last question if i want to use previous price stream e.g. I want to use MVA at 20 previous step(not period) to calculate or implement new equation, How can i do that?

Can you explain with more detail?

Apprentice
FXCodeBase: Confirmed User

Posts: 17153
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: doubt about "instance.source"

Thank you. Apprentice But for assuring my understood "+7" will set the first parameter at a previous bar as I draw in a picture. Right?

If that correct. Could I use this way to solve my problem... sample I want to calculate 20 periods of MVA by start at 12 previous candle price (see below picture)

can I use this chunk of code to solve this?
Code: Select all
`   local src12; -- Sample source want to start at candle 12 in picture   local MA;   function Prepare()       ...       src12 = instance.source:first() +12;       MA = core.indicators:create("mva", src12, 20);      ...   end    function Update(period, mode)       ...      MA:update(mode);       ...   end`

Sorry. if you stunned because of my poor language, weird problem, and NOOB skill to programming. Thank you for reading.
Saito_N

Posts: 5
Joined: Tue Mar 21, 2017 3:13 pm