# How one variable stores multi-timeframe values?

#### Sagarocks432

##### Member
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.

#### Sagarocks432

##### Member
It is all explained with examples in the Users Guide and Help within the program.

https://www.amibroker.com/guide/h_timeframe.html
I have already read that. I mean can I code multi time frame without using timeframeexpand at the last line. Bcz it makes code so lengthy and complicated. I have mor than 500 characters in that line only

#### trash

##### Well-Known Member
TimeFrameExpand is always required to properly output higher TF vars on lower TF.

If you do repeated code logic then put it to functions!

Code:
``````// solution by trash
function MyMTFfunc( timeframe, expandmode )
{
TimeFrameSet( timeframe );
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();

VarSet( "MyTFVar" + timeframe, TimeFrameExpand( a, timeframe, expandmode ) );
return TimeFrameExpand( D1, timeframe, expandmode );
}

expandmode = expandLast;
TF1 = MyMTFfunc( in5minute, expandmode );
TF2 = MyMTFfunc( in15minute, expandmode );

a = MyTFVar300; // 5minute variable a
x = MyTFVar900; // 15minute variable a
Z = ( ( a + x ) / 2 ) < 40;

Buy = TF1 AND TF2 and Z;``````

#### KelvinHand

##### Well-Known Member
TimeFrameExpand is always required to properly output higher TF vars on lower TF.

If you do repeated code logic then put it to functions!

He stated "...Bcz it makes code so lengthy and complicated."
so further cut down for you.:lol:

PHP:
``````// solution by trash
function MyMTFfunc( timeframe, expandmode )
{
TimeFrameSet( timeframe );

//-- KH
m = MACD();
n = Signal();
a = StochK();
b = StochD();
//--KH
D1 = a > b;
TimeFrameRestore();

VarSet( "MyTFVar" + timeframe, TimeFrameExpand( a, timeframe, expandmode ) );
return TimeFrameExpand( D1, timeframe, expandmode );
}

expandmode = expandLast;
TF1 = MyMTFfunc( in5minute, expandmode );
TF2 = MyMTFfunc( in15minute, expandmode );

a = MyTFVar300; // 5minute variable a
x = MyTFVar900; // 15minute variable a
Z = ( ( a + x ) / 2 ) < 40;

Buy = TF1 AND TF2 and Z;``````

#### Sagarocks432

##### Member
deleted deleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleteddeleted

Last edited:

#### Sagarocks432

##### Member
My new modified code for checking 5 stok positive and 15 stok negative. But it is not working tell me the problem.
Code:
`````` a = StochK();
b = StochD();

function MyMTFfunc( timeframe, expandmode )
{
TimeFrameSet( timeframe );

m = MACD();
n = Signal();
a = StochK();
b = StochD();

D1 = a <1000;
TimeFrameRestore();

VarSet( "MyTFVar" + timeframe, TimeFrameExpand( a, timeframe, expandmode ) );
return TimeFrameExpand( D1, timeframe, expandmode );
}

expandmode = expandLast;
TF1 = MyMTFfunc( in5Minute, expandmode );
TF2 = MyMTFfunc( in15Minute, expandmode );
b1=TimeFrameCompress(a>b,in5Minute);
b2=TimeFrameCompress(a<b,in15Minute);
a = MyTFVar300; // 5minute variable a
x = MyTFVar900; // 15minute variable a

Buy = TF1 AND TF2 AND  b1 AND b2;``````

Last edited:

#### trash

##### Well-Known Member
My new modified code for checking 5 stok positive and 15 stok negative. But it is not working tell me the problem.
You don't know word "please" and you don't know word "thanks". You only know tone of command. So help yourself.

And why do you remove my name from my solution I made? Have you come up with it or was it me?

I chekd and run this code. it works fine. But I want to chk condition D1= a>b; for 5min only but it works for 5 and 15min.
Do you know what a function is? If you don't want to check for 15 minute MyMTFfunc then don't include TF2 in Buy variable.

You included 15-minute check in first post. Now all of the sudden you don't need it anymore. What was the purpose of this thread then anyway? Wasting time?

Last edited:

#### Sagarocks432

##### Member
You don't know word "please" and you don't know word "thanks". You only know tone of command. So help yourself.

And why do you remove my name from my solution I made? Have you come up with it or was it me?

Do you know what a function is? If you don't want to check for 15 minute MyMTFfunc then don't include TF2 in Buy variable.

You included 15-minute check in first post. Now all of the sudden you don't need it anymore. What was the purpose of this thread then anyway? Wasting time?
1st I havent understand your code completely that's y I havent said thanks. And as I already said it is modified code which may b incorrect that's why I removed ur name. I studied c, java, c++ etc 3 years ago. I know about functions but didnt know how it works with afl. In my first post it checks macd > signal for 15 min not stochastic, Look carefully. And at last
THANK YOU SO MUCH Mr. Trash :clapping: for giving such a nice solution.:thumb:

Last edited: