I'm trying to develop a strategy based on Trend signal + Supertrend. It works well but I'd like to to pre-fetch X amount of bars before doing all the calculations etc
As it's a scalping strategy based on signals convergence of Trend Signal + Supertrend, the strategy will wait by default to collect futur bars respecting the conditions for Trend signal + Supertrend
But when I launch the strategy, I'd like to look back at X previous candles and calculate the existing trend. And if there is a trend, the strategy will have to take the trade
I browsed extensively this forum and found out that I have to use the ExtSubscribe1 function as per this thread (viewtopic.php?f=18&t=63076&p=104482&hilit=extsubscribe1#p104482)
It's very clear how to use it for a MVA, but do you think it's compatible with a Supertrend and Trend Signal ?
- Code: Select all
local BARS_HISTORY = 500;
TF = "m1";
-- in prepare function
function Prepare(name_only)
Source = ExtSubscribe(1, nil, TF, instance.parameters.Type == "Bid", "bar");
T1_SUPERTREND = core.indicators:create("ST", Source, T1_SUPERTREND_Period + BARS_HISTORY, T1_SUPERTREND_Multiplier, core.rgb(0, 255, 0), core.rgb(255, 0, 0));
end
-- in ExtUpdate function
function ExtUpdate(id, source, period)
if (T1_SUPERTREND.DATA:hasData(period - BARS_HISTORY)) then
core.host:trace("T1 ST period : " .. period " " .. T1_SUPERTREND[T1_SUPERTREND:size() - BARS_HISTORY]);
end
end
For me T1_SUPERTREND.DATA:hasData(period - BARS_HISTORY) never contains any data.
Thanks a lot in advance for your insight
Daveatt