Multiple study lines with same ID

I use studies to plot resistance and support areas on the chart.
If I use SU and RE as the study IDs, is it possible to use a loop to get the location of multiple studies with the same ID?
Or if this is not possible, how does the STUDY() function decide which one to retrieve?

Polomora

Why don't you make your life easier and use different (unique) Study IDs (for instance R1, R2, R3 ... and S1, S2, S3 ...)? You are not limited to the default few ones:

A quote from https://www.amibroker.com/guide/afl/study.html

STUDY ID is a two-character identifier of the study. identifiers are: "UP" - uptrend, "DN" - downtrend, "SU" - support, "RE" - resistance, "ST" - stop loss, however you can use ANY identifiers (there are no limitations except that AmiBroker accepts only 2 letter codes).

Using studies in AFL formulas: https://www.amibroker.com/guide/h_studies.html

1 Like

Thanks Milosz,

I had thought of that :slightly_smiling_face:

However, I work with up to five support and resisance zones on either side of the current market price, each identified by a study line. And I constantly add and delete new lines. So to manage them manually would be difficult to avoid having holes or duplicates in the ordering. This why I thought of the possibility of using a loop to retrieve the value of each SU and RE study in turn.

If this isn't possible, then I'll use R1, R2, etc.

But what is retrieved if there are two study lines with the same ID?

You are your best teacher. You have AB, manuals other resources, just try all scenarios and post your findings here :slight_smile:

2 Likes

@travick

Good idea.

I did just that, and I found that AB uses the oldest study line. However, it maintains a stack of studies per ID, because when I deleted the oldest study, it uses the next-oldest study for that ID. Which makes me think that a useful addition to the Study() function would be add an index/iterator, to specify the study to be returned.

1 Like