Exploration Multi timeframe chart

I am trying to achieve multiple timeframe exploration program, where the explorer shall display MACD values of 5 min, 15 min and 30 min. Whenever there is a crossover in 5 min, 5-minute should display in Interval, for 15 Min crossover Interval should display 15-minute and similarly whenever 30 min crossover shall display Interval as 30-minute.

TF_1 = in5Minute;
TF_2 = in15Minute;
TF_3 = 2*in15Minute;


MACD_5M = MACD();
MACD_Cross_5M = Cross(MACD(),Signal());


TimeFrameSet(TF_2);
MACD_15M = MACD();
MACD_Cross_15M = Cross(MACD(),Signal());
TimeFrameRestore();


TimeFrameSet(TF_3);
MACD_30M = MACD();
MACD_Cross_30M = Cross(MACD(),Signal());
TimeFrameRestore();


Filter = 1; 

AddTextColumn( Interval(2), "Scan Period", 1 );
Addcolumn(MACD_Cross_5M, "MACD_Cross_5M", 1 );
Addcolumn( MACD_5M, "MACD_5M", 1 );
Addcolumn( TimeFrameExpand(MACD_Cross_15M,TF_2), "MACD_Cross_15M", 1 );
Addcolumn( TimeFrameExpand(MACD_15M,TF_2), "MACD_15M", 1 );
Addcolumn( TimeFrameExpand(MACD_Cross_30M,TF_3), "MACD_Cross_30M", 1 );
Addcolumn( TimeFrameExpand(MACD_30M,TF_3), "MACD_30M", 1 );

Currently I am getting only 5-minute interval as my setting is for 5 min chart (Pls see the screen below). Can I achieve multiple Interval values (5 min, 15 min and 30 min) by retaining 5 min interval in settings.
Any help would be greatly appreciated.
Untitled2

Solution: AddMultiTextColumn() function.

/// @link https://forum.amibroker.com/t/exploration-multi-timeframe-chart/13249
TF_1 = in5Minute;
TF_2 = in15Minute;
TF_3 = 2*in15Minute;

MACD_5M = MACD();
MACD_Cross_5M = Cross(MACD(),Signal());
int_1 = Interval(2);

TimeFrameSet(TF_2);
int_2 = Interval(2);
MACD_15M = MACD();
MACD_Cross_15M = Cross(MACD(),Signal());
TimeFrameRestore();

TimeFrameSet(TF_3);
int_3 = Interval(2);
MACD_30M = MACD();
MACD_Cross_30M = Cross(MACD(),Signal());
TimeFrameRestore();

/// @link https://forum.amibroker.com/t/exploration-multi-timeframe-chart/13249/2
/// code suggestion for AddMultiTextColumn by fxshrat
crss1 = MACD_Cross_5M;
crss2 = TimeFrameExpand(MACD_Cross_15M,TF_2);
crss3 = TimeFrameExpand(MACD_Cross_30M,TF_3);
//
TextSelector = 1 * Nz(crss1) + 2 * Nz(crss2) + 4 * Nz(crss3);
TextList = StrFormat( "No Cross\n%s\n%s\n%s\n%s\n%s\n%s\n%s", 
					  int_1, int_2, int_1 + " & " + int_2, int_3, 
					  int_1 + " & " + int_3, int_2 + " & " + int_3, 
					  int_1 + " & " + int_2 + " & " + int_3 );
//
Filter = TextSelector;
//
AddMultiTextColumn( TextSelector, TextList, "MACD Cross Interval", 1, -1 , -1, 220 );
Addcolumn( crss1, "MACD_Cross_5M", 1 );
Addcolumn( MACD_5M, "MACD_5M", 1.4 );
Addcolumn( crss2, "MACD_Cross_15M", 1 );
Addcolumn( TimeFrameExpand(MACD_15M,TF_2), "MACD_15M", 1.4 );
Addcolumn( crss3, "MACD_Cross_30M", 1 );
Addcolumn( TimeFrameExpand(MACD_30M,TF_3), "MACD_30M", 1.4 );

1

10 Likes

Great Fxshrat for your help. I appreciate.

I have one question to understand how the sequence of event executes in TextSelector and TextList.

TextSelector = 1 * Nz(Buy_SELL_5M) + 2 * Nz(Buy_SELL_15M) + 3 * Nz(Buy_SELL_30M);
TextList = StrFormat( "No Condition\n%s\n%s\n%s\n%s\n%s\n%s\n%s",
					  int_1, 
					  int_2, 
					  int_3, 
					  int_1 + " & " + int_2, 
					  int_1 + " & " + int_3, 
					  int_2 + " & " + int_3, 
					  int_1 + " & " + int_2 + " & " + int_3 );

In the above statement, I tried to understand the sequence of intervals as below:
5-minute, 15-minute, 30-minute, 5-minute & 15-minute, 5-minute & 30-minute, 15-minute & 30-minute, 5-minute & 15-minute & 30-minute.
Please correct me if the sequence is not in the above order per my understanding.

Why do you change to this?

TextSelector = 1 * Nz(Buy_SELL_5M) + 2 * Nz(Buy_SELL_15M) + 3 * Nz(Buy_SELL_30M);

It is not what I posted.
I already gave you correct textselector! What I post is correct in 90% of cases.

It should be this one as posted in 2nd post of this thread.

TextSelector = 1 * Nz(Buy_SELL_5M) + 2 * Nz(Buy_SELL_15M) + 4 * Nz(Buy_SELL_30M);

Setting to 3 * Nz(Buy_SELL_30M) is incorrect as it will miss combinations and output incorrectly.

It has to be power of two sequence.

2^0 = 1
2^1 = 2
2^2 = 4
etc.

Please don't change things if you don't understand things.

EDIT: If TextList does not output correctly then obviously it is not correct too.

2 Likes

Oops, sorry about that. Thanks for your answer, on the sequence of events, can you please comment, as I have changed that too.

You have given:

TextSelector = 1 * Nz(crss1) + 2 * Nz(crss2) + 4 * Nz(crss3);
TextList = StrFormat( "No Cross\n%s\n%s\n%s\n%s\n%s\n%s\n%s", 
					  int_1, 
                                          int_2, 
                                          int_1 + " & " + int_2, 
                                          int_3, 
					  int_1 + " & " + int_3, 
                                          int_2 + " & " + int_3, 
					  int_1 + " & " + int_2 + " & " + int_3 );

I changed it to (after correcting the multiplier)

TextSelector = 1 * Nz(Buy_SELL_5M) + 2 * Nz(Buy_SELL_15M) + 4 * Nz(Buy_SELL_30M);
TextList = StrFormat( "No Condition\n%s\n%s\n%s\n%s\n%s\n%s\n%s",
					  int_1, 
					  int_2, 
					  int_3, 
					  int_1 + " & " + int_2, 
					  int_1 + " & " + int_3, 
					  int_2 + " & " + int_3, 
					  int_1 + " & " + int_2 + " & " + int_3 );

Is this correct sequence ?

Still waiting for a response from any expert, in case there is any study material link, would love to get the same.
Thanks in advance.

Appreciate your help.
I don't believe to blindly follow without knowing or learning, hence tried to change and asked question.

The answer has been given already:

Once again...
the correct code to post #1 is in post #2. It just works as it outputs what is expected. There is nothing to change to that. It's that simple.

The possible results of TextSelector of post #2 are:

0
1
2
3
4
5
6
7

three conditions so eight combinations -> power of two.

So text list requires same number of substrings separated by \n and in the order of what you expect to be getting output per textselector result.

Your edited text list applied to code of post #2 will output incorrectly as it has incorrect order of original substrings making no sense to output expectation, see example:
1

Besides readers don't see your screen... so if you added different code then it is unknown. There isn't anyone here having magical eyes or mind reading capabilities of Marvel comics action figures.

Other than that I have posted programmatic text list creation code few years ago already.

2 Likes

Can you share the link, I tried to search this forum but couldn't find it.

Below is what I can recall:

Don't know if he has procured anything more sophisticated. Anyways, AFL is very flexible, so, when it comes to creation of dynamic text list there are multiple ways around it - totally depends on the sheer requirements of the user. What fxshart has shared already is very elegant, resource-friendly and comprehensive to understand.

Where lies the issue? If you do not provide details, there is no way one can tune-in to wavelength of your thought frequencies! Marconi only invented Radio transmission, Thought transmission not yet possible! :slight_smile:

scanner

I tried a lot to make this afl with exploration, but I'm failed..
Please help..

@hirenvyas,

Only users with "Verified Badge" are allowed to post on this forum.

Search "Verified Badge" for more information on how to get verified.