Page 1 of 1

Average of bid & ask as a source?

PostPosted: Fri May 27, 2016 6:47 pm
by Stance
Hi,

If I create a bid and ask as a source, is there a way I can use the average of the 2 sources in a moving average?

Can I do something like this?

Source_bid = ExtSubscribe(1, nil, TF, true, "bar");
Source_ask = ExtSubscribe(2, nil, TF, false, "bar");
Source_avg = (Source_bid + Source_ask) / 2;

MA = core.indicators:create("MVA", Source_avg.close, 20 );

Re: Average of bid & ask as a source?

PostPosted: Mon May 30, 2016 5:25 am
by Julia CJ
Hi Stance,

Please calculate the average by this way:

Source_avg = instance:addInternalStream(0, 0);
MA = core.indicators:create("MVA", Source_avg, 20 );

function update...
Source_avg[period] = (Source_bid.close[period] + Source_ask.close[period]) / 2;