# Reference study on different symbol

#### Flannag

##### New member
How do you trigger a buy/sell in the charted symbol from a condition of second ticker. For instance buy ABC if XYZ closes over XYZ's moving average.

If I use this on a chart of ABC:
def MA = SimpleMovingAvg();
def BUY = close("XYZ") > MA;
AddOrder(........);

that will give the condition BUY when XYZ closes greater than the moving average for ABC. Am I right? It would be nice if I could just tell it which stock to buy in the AddOrder() function but there's nowhere for it. Please forgive any syntax errors in my sample script, it's only meant to show my point.

Yes, that's exactly how you would do something like that. Now, you could make the other symbol an input from an enum list where you could choose from two or more stocks. Could also input a multiplier if you wanted to say, make the other stock price more in line with the one being compared to. Like, multiplying stock2 by 10 or something.

Kind of curious what you're going for by comparing one stock price to the moving average of another though.

I still don't see it. The script I provide will check the condition of XYZ closing price to the MA of ABC. I want a condition on the chart of ABC that indicates XYZ has crossed the MA of XYZ. I think you're suggesting that a multiplier gets XYZ closer to the MA of ABC? To be less cryptic of my goals I'm looking to see what it looks like to BUY/SELL SPY if the VIX goes over/under an indicator(moving average, linear regression, etc).

Both of these examples show what I wish I could do, though the syntax isn't there.

On the ABC chart, I would need to tell it to draw a moving average based on XYZ data. I think this one works, does anyone see any problems with it:
def BUY = Close("XYZ") > SimpleMovingAvg(price = close("XYZ");

0r on the XYZ chart, just tell it to buy ABC:
AddOrder(OrderType.BUY_TO_OPEN, Buy("ABC"), price = CLOSE());

I get a bit lost in the semantics here too. I think I want a "def" but I'm calling it a condition.

I still don't see it. The script I provide will check the condition of XYZ closing price to the MA of ABC. I want a condition on the chart of ABC that indicates XYZ has crossed the MA of XYZ. I think you're suggesting that a multiplier gets XYZ closer to the MA of ABC? To be less cryptic of my goals I'm looking to see what it looks like to BUY/SELL SPY if the VIX goes over/under an indicator(moving average, linear regression, etc).

Both of these examples show what I wish I could do, though the syntax isn't there.

On the ABC chart, I would need to tell it to draw a moving average based on XYZ data. I think this one works, does anyone see any problems with it:
def BUY = Close("XYZ") > SimpleMovingAvg(price = close("XYZ");

0r on the XYZ chart, just tell it to buy ABC:
AddOrder(OrderType.BUY_TO_OPEN, Buy("ABC"), price = CLOSE());

I get a bit lost in the semantics here too. I think I want a "def" but I'm calling it a condition.

maybe if you start over, and tell us WHAT you want to see on the chart , your request will become clear. don't say 'for instance' and don't give examples, just state what you want to see.

do you want to monitor several stocks on one chart?

in 2 posts, you have typed about 1500 characters so far and i still don't know what you want to have happen.

things you mentioned,
. how to trigger an addorder with data from a different symbol.
( reference the price data of a different symbol. close("XYZ") )

. how to have an addorder buy a symbol, that isn't on the chart. (you can't)

. how to display some indication of the action of a different symbol, on the chart.
( use price data from another symbol, in a formula , close("XYZ") )

I want to use a condition like crosses under/over a study of one ticker to provide an indication for buy/sell of a different ticker. For example, if the SPX crosses above the 60 period Linear Regression, I want a buy signal for AAPL.

The best I have so far is go to the ticker you want to use, in this instance AAPL, and add these scripts into the appropriate places to do what I'm trying to do:

def SecondaryStockIndicator = close("SPX");
def LinReg = Inertia(close("SPX"));

def Long = SecondaryStockIndcator > LinReg;

then for the buy order to show, you just need to add this to get it to show a buy for AAPL:

AddOrder(OrderType.BUY_TO_OPEN, Long);

to visualize the underlying indicator you could add the following and visually confirm that the SPX did in fact cross over the Linear Regression:

plot LinReg1 = Linreg;
plot Paired Ticker = SecondaryStockIndicator;

I know the above scripts don't work by themselves, it's just how I added the script to what I have. It works for me but I wanted to confirm there's no conflicts. I totally get it's "a lot of characters" to explain a concept, but I'm trying and it's not really simple to explain. Thanks for all the help. I think there's a lot to be said for being able to use underlying indicators to help us make decisions for trades. Hoping this makes more sense.

Last edited:

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
340 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• ‘Buy The Dip’ signal alerts
• Exclusive members-only content
• Add-ons and resources
• 1 full year of unlimited support

### Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.