I want to access data from another symbol of another timeframe

I am making a buy only indicator based on EMA and I want to add a rule which checks if my indicator with other symbol with different timeframe and also with different param let's say my current chart is HDFC in 5 min with large ema range set to 200 and I want to check if my indicator on 1 hour chart in Banknifty with large ema range set to 250 is in uptrend(ie. the latest signal was buy).

Screenshot 2022-11-30 161147

Here is my code:

large_ema_range = Param("large ema range",200,100,500,1);
small_ema_range = Param("small ema range",200,100,500,1);

large_ema = EMA(C,large_ema_range );
small_ema = EMA(C,small_ema_range );

Buy = Cross(small_ema,large_ema);
Sell = Cross(large_ema,small_ema);

PlotShapes(Buy * shapeUpTriangle, colorBrightGreen, 0, C, -48);   
PlotShapes(Buy * shapeUpTriangle, colorBlue, 0, C, -36);   
PlotShapes(Buy * shapeUpTriangle, colorBrightGreen, 0, C, -24);   
PlotShapes(Sell * shapeCircle, colorBrightGreen, 0, C, 12);   


Any help will be appreciated.

in your working chart symbol of HDFC, you use Foreign() to get value of other ticker(s)

AFL Function Reference - FOREIGN (amibroker.com)

Then you use AFL Function Reference - TIMEFRAMECOMPRESS (amibroker.com) to Hourly or "any Higher TF" and apply whatever you want on it.

Read this properly: Multiple Time Frame support (amibroker.com)
incase you want to plot() the foreign EMA(). then see how TimeFrameExpand is used in the lower TF.

There is code with examples in the links, its easy to use them directly.


I have another question,

Let's say for example in the future I want to add another rule based on ADX then can I also access ADX through Foreign funcion. If yes then how to do it or if no then are there any other ways?

and Thank you for your reply! I appreciated it a lot.

@KirtiKher in addition to the user guide links you have been pointed to, read the official knowledge base articles such as

and the ADX question has an example here,


Thankyou so much for your reply!

I did as per your instructions and it is working but there seems to be some issue

this is how I did it in my code (EXAMPLE CODE).


//CODE HERE (Note my real code also has other additional rules including adx, dmi etc.


What I did: I plotted two charts one of symbol BankNifty let's call this chart1 and other of HDFC let's call this chart 2, then I took a formula and made two variations of it and named them formula1 and formula2 each respectively. Then, I kept formula2 as a normal strategy and applied it to chart2. Then, I tried to replicated the HDFC price chart with It's signals on chart1 and I did it in formula1 which I had applied to chart1. To replicated it i did it in the same way as I did it in my example code.

The issue: I am noticing that a few signals are missing in chart1 as compared to chart2. When I further investigated I noticed that a few candles were not matching in chart1 which caused the value of ADX to be different as compared to in chart2 which is why in a condition in my indicator relented to ADX did not match which caused the signal to disappear in chart1.

Image showing the disappearing signal:
HDFC original chart

Any help would be appreciated.

its obvious signals wont necessarily be the same if you are running them on different symbols.

And when you hide your code, it is unhelpful (time waste) because if you have a mistake in it, it wont be known.
You have to provide everything so someone else can replicate it.


Extremely sorry for wasting your time sir!

I think my data is probably corrupted.

and again thank you for your reply!

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.