Stochastic, checking values between bars

Moderator: admin

Stochastic, checking values between bars

Postby mickatron » Tue Jun 09, 2015 10:11 pm

Looking for some advice on how could I set the Stochastic on an m30 timeframe, but check it every minute in an Automated Strategy?

When I try to update the values for the stochastic on a quicker timeframe than what I create it with I get an "Index is out of range error".

The stochastic does update values (presumably) on tick data, I can watch it update in TS2 with each price change. Is there any way to get the "between bar" values?

Here's my current implementation. Basically the Pivot Source(BarSource) is set to m1, but the indicator is set to display D1 Pivots. Then I create the Stochastic with StochSource and set StochSource to m30. There's no timeframe parameter for the Stochastics so I just use the bar/data source to build it on that timeframe, though I can only seem to get values for it at the beginning of a new m30 bar.

Code: Select all
-- Prepare()

   --[[ Create Pivot Indicator ]]--
   BarSource = ExtSubscribe(1, nil, instance.parameters.SignalTF, true, "bar");
   iPivot = core.indicators:create("PIVOT", BarSource, instance.parameters.PivotTF, "Pivot", "HIST");
   
   --[[ Create Stochastic 1 ]]--
   StochSource = ExtSubscribe(2, nil, instance.parameters.StochTF, true, "bar");
   
   iStoch1 = core.indicators:create("STOCHASTIC", StochSource, 5, 3, 3, "MVA", "MVA" );


-- ExtUpdate
   if id == 1 then
      iPivot:update(core.UpdateLast);   
      PivotLevel["P"] = iPivot:getStream(0)[period]; -- same as PIVOT Level
      PivotLevel["S1"] = iPivot:getStream(1)[period]; -- S1
      PivotLevel["S2"] = iPivot:getStream(2)[period]; -- S2
      PivotLevel["S3"] = iPivot:getStream(3)[period]; -- S3
      PivotLevel["S4"] = iPivot:getStream(4)[period]; -- S4   
      PivotLevel["R1"] = iPivot:getStream(5)[period]; -- R1   
      PivotLevel["R2"] = iPivot:getStream(6)[period]; -- R2   
      PivotLevel["R3"] = iPivot:getStream(7)[period]; -- R3   
      PivotLevel["R4"] = iPivot:getStream(8)[period]; -- R4   
      
      if StochUpdated == true then
         iStoch1:update(core.UpdateLast);
         iStoch1Line1 = iStoch1:getStream(0)[period];  -- %K
         iStoch1Line2 = iStoch1:getStream(1)[period];  -- %D 
         Signal("Stoch L1: " .. Line1 .. " L2: " .. Line2);
      end
   end   
mickatron
 
Posts: 13
Joined: Sun Feb 15, 2015 10:46 am

Re: Stochastic, checking values between bars

Postby Apprentice » Wed Jun 10, 2015 2:59 am

Always check if data if the subject is available, applies not only to multiple time frames examples.
Code: Select all
if iStoch1:getStream(0):hasData(period) then
end


Period provided by the TS is not valid for Stochastic.
Because Stochastic uses source with id 2.

See this, multiple time frame strategy examples.
End of Turn_Live Execution Strategy Template.lua
MTF Strategy Template.lua
viewtopic.php?f=28&t=2712
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 38154
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Stochastic, checking values between bars

Postby mickatron » Wed Jun 10, 2015 5:47 am

Thanks for the examples I've taken a look though it's still a little unclear how I would read the intermittent values from the stochastic indicator. When I check them on quicker timeframes it just returns the same value that was set @ the m30 bar open. That makes sense as to why but I want the values updated per minute.

I do get that I used id=2 for the Stochastic, I had to set that instantiation call to m30 so the indicator would return the values I was after. I do not want to check the values every 30 mins though, I want to check it every 1 min but return the values from an m30 indicator. As Stochastic has no Timeframe param its the only way I could create one @ 30 minutes, now I just need the values from it every 1 minute and I'm all good.

Is this possibly a limitation of the Stochastic Indicator as it has no timeframe parameter? If it had I could've just set its data source to m1 and instantiated the actual indicator as an m30.
mickatron
 
Posts: 13
Joined: Sun Feb 15, 2015 10:46 am

Re: Stochastic, checking values between bars

Postby Apprentice » Fri Jun 12, 2015 2:50 am

The problem with indexing othet time frame.
You need to get a appropriate index.

You can use core.findDate to get stream index, corresponding with the respective time frame.
See End of Turn_Live Execution Strategy Template.lua

Also, from within strategy you can use last stream index.
See MTF Strategy Template.lua
Index = Open[1]:size() - 1;
Open[1][ Index]



example
Code: Select all
 [1]      [2]      [3]        -H1 
 [1] [2] [3] [4] [5] [6]  - m30
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 38154
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 1 guest