Show the Moving Average of another Security

Skyfly93

New member
Can anyone build a study that display the moving average of a secondary security onto the primary chart as a lower study?

For example, is it possible to see the 10-day moving average of VIX (secondary security) shown on the ES chart lower study? Ideally, would like to make the secondary security an input.
 

_Merch_Man_

Member
Hey @Skyfly93 - Can you try this and confirm it does what you need?

Code:
input price = close;
input length = 9;
input displace = 0;
input ticker = "VIX";

declare lower;

plot SMA = Average(close(ticker)[-displace], length);

SMA.SetDefaultColor(GetColor(1));

addlabel(1,"Moving Average: " + ticker);
 

_Merch_Man_

Member
@Skyfly93 Could you please post a screenshot? Here are 2 shots from my system where you can see on the daily and hourly the VIX mainchart values match the lower chart values.

RsFiGa3.jpg


snyN8PN.jpg
 

_Merch_Man_

Member
Can't seem to attach photos into here directly so posted a link below.

As you can see, the both the VIX and /VX MA lag the /ES chart by a few bars.

Interestingly, plotting /VX upper and lower eliminates the issue as does plotting /ES against /ES. I can kinda see why /ES vs VIX doesnt work correctly because of the different trading hours, but I can't immediately see why you see the lag on /ES vs /VX. I'll keep looking.

Edit: Even more interesting, there is a lag with /ES main and /VX lower, but no lag with /VX main and /ES lower. I am confused.
 

Skyfly93

New member
Interestingly, plotting /VX upper and lower eliminates the issue as does plotting /ES against /ES. I can kinda see why /ES vs VIX doesnt work correctly because of the different trading hours, but I can't immediately see why you see the lag on /ES vs /VX. I'll keep looking.

Edit: Even more interesting, there is a lag with /ES main and /VX lower, but no lag with /VX main and /ES lower. I am confused.
I would be very confused as well.

Yes I expect VIX not to lag but just not plot during globex hours, but there's still a lag on VIX on the daily looking at ES, which shouldn't be the case.

Not sure what's causing this though since the code you wrote is fairly simple and straightforward.
 

Similar threads

Top