Create condition order based on another ticker?


New member
Hi all,

I am pretty new to thinkscript, I have minor experience with some if then else statements and for loops previous outside of thinkscript and have written a few moving average crossover scripts with minimal success.

I'm currently working on trying to create a strategy which utilizes a condition from another tickers open > close the previous day. I then want a SPY purchase to be put in, essentially, at open time or a minute after given that the other ticker condition is met. I can't seem to figure out how to get this strategy to work, mostly the sellcondition is where I am having trouble. Also, when I try to view the strategy on anything but a 1 day candle chart it has hundreds of buy/sells throughout the day, even though I have the buy order only for open (now that I think about it more, it is probably something I need to do with aggregation period but I've been playing with the script for a few days now (and a lot of googling) and still can't figure it out). BUY_AUTO and SELL_AUTO works, but BUY_TO_OPEN and BUY_TO_CLOSE don't work either. Forgive me if the code looks terrible and somethings are wrong.

Here is what I have so far:

input Ticker = "$ADD";

def buycondition = open(Ticker, AggregationPeriod.DAY) > close(Ticker, AggregationPeriod.DAY)[1] ;

input CloseTime = 1600;

def sellcondition = 60*SecondsTillTime(CloseTime);

AddOrder(OrderType.BUY_AUTO, buycondition, price = open("SPY", AggregationPeriod.DAY), name = "buy", tradeSize = 100);

AddOrder(OrderType.SELL_AUTO, close("SPY",AggregationPeriod.Day), name = "sell", tradeSize = 100);
Last edited by a moderator:

Similar threads