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