doubt about "instance.source"

Moderator: admin

doubt about "instance.source"

Postby Saito_N » Mon Jul 10, 2017 12:15 am

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.
User avatar
Saito_N
 
Posts: 9
Joined: Tue Mar 21, 2017 3:13 pm

Re: doubt about "instance.source"

Postby Apprentice » Mon Jul 10, 2017 4:13 pm

"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?
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: doubt about "instance.source"

Postby Saito_N » Thu Jul 13, 2017 3:09 pm

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?
Image

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)
Image

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.
User avatar
Saito_N
 
Posts: 9
Joined: Tue Mar 21, 2017 3:13 pm


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 12 guests