Relative Strength Ratio Using Add to Composite

Hi Everyone,

I trying to achieve something simple (or so I think) however i have not been having much luck and was wondering if anyone has any insight they would be willing to share. I’m trying to create a composite ticker symbol using a relative price ratio of two ticker symbols. In this example I’m looking to create a composite ticker symbol of the closing prices of XLU and XLV (i.e XLU/XLV)

Sample code below;

XLU = Foreign(“XLU”,“C”);
XLV = Foreign(“XLV”,“C”);

Plot(XLV_XLU,“Healthcare vs Utilities”,colorBlack,styledashed|STYLETHICK);
Plot(Foreign("~XLV_XLU",“C”,1),“Healthcare vs Utilities”,colorBlack,styleLine|STYLETHICK);

When I plot both indicators, there are similarities however the I’m not getting the correct values using the addtocomposite function. Has anyone tried to do this before? I feel as though this should be a simple task, however the simplicity is eluding me. I would appreciate any help or guidance. Thanks in advance.

Try to use also
atcFlagEnableInIndicator = 128 - allow running AddToComposite in indicator mode

First and foremost read and follow “How to use this site”. Code sections need proper tags.

There is NO POINT in creating composites just for relative strength. It is waste of resources.
Instead use division result directly in Plot

XLU = Foreign(“XLU”,“C”);
XLV = Foreign(“XLV”,“C”);

Plot( XLV / XLU,“Healthcare vs Utilities”,colorDefault);

or just use built-in function RelStrength:

Secondly, did you read AddToComposite documentation? Default flags work in Scan, not in indicator. And there is a reason for that as running composites in indicator is just bad idea.

1 Like

Hi Tomasz,

Thank you for reply.

Yes I have read the manual in depth trying to solve riddle. I’m an engineer
and can figure out a number of complicated tasks, however this is one that
has and is eluding me.

The formula you’ve noted above as well as the RelStrength function, yes
agreed work well and I currently use them

The reason why I’m looking to create the relationship as a ticker symbol is
so that I can backtest this relationship and several others, as well as
to use the explore function to scan for indicator values on the
relationship itself.

I have not intended this to be a dumb question by any means and I’m also
not the type of person to reach out for help. I reach out for help when
I’ve exhausted my current resources.

I need the relationship to be created as a symbol of some sort.

Bad idea of not, I would appreciate any insight you could provide as to how
to do this in Amibroker. If this is not a simple task please let me know. I
can do this in excel, however it’s painful.

Again, I have a strong reason why I’m trying to do this on a broader scale
outside excel. Also, I’m asking sincerely for help on this. Any help would
be sincerely appreciated. Thanks in advance.

1 Like

The thing is that indicator executes many times (each chart refresh, like zoom, scroll, new data etc). So if you put AddToComposite in it it get re-computed over and over again.
You could use it in indicator if you used atcFlagEnableInIndicator:

AddToComposite( array, "ticker", "C", atcFlagDefaults | atcFlagEnableInIndicator );

but as I wrote and as it is documented you really should use it the way it was designed, i.e. compute ONCE, use MANY.
For this you should just run your code in Scan (Analysis window) where it will be computed once.

ok thnx that helps. it was what i was searching for