Average of bid & ask as a source?

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

Average of bid & ask as a source?

Postby Stance » Fri May 27, 2016 6:47 pm

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 );
Stance
FXCodeBase: Initiate
 
Posts: 141
Joined: Mon Jun 01, 2015 4:34 pm

Re: Average of bid & ask as a source?

Postby Julia CJ » Mon May 30, 2016 5:25 am

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;
Julia CJ
 


Return to Discussions

Who is online

Users browsing this forum: No registered users and 6 guests