How to define a symbol in the code

I am stuck with a very basic functionality. I have gone through all the documents, but could not find a solution.

I want to define an individual symbol in the code rather than choosing current symbol from main analysis window.

Can somebody help with me a suitable command.

Thanks in advance.

You can read here

This can work like a synthetic ticker.

Full guide here:

Not sure what you're trying to do, but if you want to access (not define) an existing symbol then you can look at the functions Foreign() and SetForeign().

I love OPs who are like fishing companies, throw the nets and go to a party.

A few days later we can go check what we caught :stuck_out_tongue:

Contrastingly, the hobbyist (a fisherman) would sit there with his line in the water.


Thanks a lot for your response. Let me try to explain my problem in detail. I want to run a backtest on a symbol (Lets say symbol-I) which I want to fix it through the code rather than selecting current symbol from the analysis window.

In the program, I want to change the symbol(lets say symbol-II) , simulate something and revert back to symbol-I.

Therefore, I need to specify in the code when I want to work on symbol-I, then go to symbol-II and revert to symbol-I.

My requirement is how to specify in the code that I am running on symbol-I. Then how to switch to Symbol-II and how to revert to symbol-I.

I shall be highly obliged if you can help me with the same.

Thanks in advance.


Travick, May be I did not get you right. Are you being sarcastic? Please elaborate what you mean by this message.

Based on the vague description in your opening post, I anticipated whats going to happen next after Matts post.
Nevertheless, in the 2nd post I gave a workable suggestion.

For you it maybe sarcasm, however it is not intended to hurt anyone but the confirmation of what i'm saying is in your 2nd post almost a day later.
"Let me try to explain in detail...."

This is a documented fact, why don't OPs elaborate in detail in the first post instead of having other members play guessing games.

If you want proof see this

Anything familiar with above Topic now @monabansal ?

Now I suggested ATC and Matt suggested Foreign()
Have you taken out the time to try both and report why either one will work or not?


I understand what you mean. But please try to understand that we are in different time zones and it is not possible for somebody to be online all the time. I have read the functions ATC and Foreign.

While going through the same, to the best of my understanding this does not serve my purpose.

As far as Foreign is concerned, it is ok to access a specific function of another symbol, but not to permanently switch to a foreign symbol for running a set of commands. I would like to use the following to explain my requirement.

//Backtest for Symbol-I
Step-I: Access Symbol-I
//Then run a set of commands

Step-II: Access Symbol-II
//Then run a set of commands

STEP-III: Revert back to symbol-I
// then run a set of commands

My requirement is to know the commands which will help me perform steps I, II and III.


what context is it in? Exploration, Backtest (CBT mid or Low etc) , Optimize or is a chart

No code required. The solution to fix symbol is using batch process and project files (which save AFL and all analysis settings) and setting the symbol to run the analysis on via batch command (or "action" as it is called).
Similar thread here. There in that thread there was set a certain symbol one time and rest was applied to Filter watchlist. But it doesn't matter here as the principle is the same.

If you want to change symbols back and forth then you simply use "Set Current Symbol" multiple times after loading new project or reloading old one. You can save batch to .abb file. So simply open batch file each time and set to new symbols there by double clicking each "Set Current Symbol" line.

OK, I've made another picture if it is still not clear....
Those ones are supposed to be just another examples. You may do run whatever else analysis you want to run.



I got the chart part wrong. As I was typing various parts. I shouldn't have been added.
But my point was still what context of Main Analysis is this context specific to ?

Thanks a lot. I believe this will certainly solve my problem. I will try it out.

I have data the pricing data in a running backadjusted format with current months as Symbol-I and next month as Symbol-II. I want to backtest on Symbol-I. However, when I do that I miss the contract roll over cost. In order to incorporate roll over cost in the code, I need to identify the roll over date. I want to do that by analyzing the volume for the Symbol-II. Thats the reason I need to switch between the symbols. Hope I am able to answer your question. Once done, I will share the code. Thanks