How one variable stores multi-timeframe values?

I know that when working on multitime frame we perform operation seperatelty within Timeframeset and Timeframerestore. But how to perform such calculation which stores value of multi-time frame.

Code:

TimeFrameSet(in5Minute);
m=MACD(12,26);
n=Signal(12,26,9);
a= StochK( periods = 14, ksmooth=3 );
b =StochD( periods = 14, Ksmooth=3, Dsmooth=3 ) ;
D1= a>b;
TimeFrameRestore();

TimeFrameSet(in15Minute);
x =StochD( periods = 14, Ksmooth=3, Dsmooth=3 ) ;
y= StochK( periods = 14, ksmooth=3 );
m1=MACD(12,26);
n1=Signal(12,26,9);
C3= m1>n1;
TimeFrameRestore();

Z = ((a+x)/2) <40;
Buy = D1 AND C3 AND Z;
Buy = TimeFrameExpand(D1,in5Minute) AND TimeFrameExpand(C3,in15Minute) and Z;

In abv code a defined at 5min and x at 15min. But for variable z which time frame shoud we use. And how to write z in last two lines? This code doesnt work properly for value of z.

I am not sure but if you go logically variables a and x at any point estimate gives real numbers as output and you are just getting Z as a summations of two real numbers so no need of assigning any time frame for Z.

Instead defining Z as ((a+x)/2) < 40,Just define Z as (a+x)/2 and in buy condition along with other two conditions give Z < 40 as one of the condition.