- Code: Select all
...
local MA;
local ma_source = nil;
local sourceData;
local loading;
...
function Prepare(nameOnly)
...
ma_source = instance.source;
sourceData = core.host:execute("getSyncHistory", ma_source:instrument(), "D1", ma_source:isBid(), 200, 200, 100);
loading = true;
MA = core.indicators:create("EMA", sourceData.close, 200);
...
end
...
function ExtUpdate(id, source, period)
...
MA:update(core.UpdateLast );
core.host:trace(string.format("Value of 200 day MA:=%f", MA.DATA));
...
end
...
When I run this in the debugger, I get an error "182: attempt to index upvalue 'ma_source' (a nil value)". I believe trying to use this method does not work because I need to check for loading using the function "AsyncOperationFinished" which is not called when using "ExtUpdate" function as opposed to just "Update". However I need to use "ExtUpdate" for other reasons.
If someone could layout for me in the simplest terms how to access the value of a 200 day moving average in a strategy running on a lower time frame chart, I would greatly appreciate it.