Sabin Gaire
New member
I am new to thinkScript. I wrote a script which is supposed to enter a trade once it breaks 3-min high after first 3 minutes of market open. i have two problems
a. My chartbubble shows high three for same high
b. Entry and exit is not working
Any guidance and suggestion will be helpful. Here is my code
input stock = "SPY";
def isopen = if SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) <= 179 then 1 else 0; #to draw high and #low of first three min
#get high of first 3 min
def pricehigh = high(stock, AggregationPeriod.THREE_MIN, PriceType.LAST);
rec priceH = pricehigh;
#get low of first 3 min
def pricelow = low(stock, AggregationPeriod.THREE_MIN, PriceType.LAST);
#plot high and low of first three min
addChartBubble(if isopen == 1 then yes else no, pricehigh, pricehigh, Color.YELLOW, yes);
AddChartBubble(if isopen == 1 then yes else no, pricelow, pricelow, Color.RED, no);
#entry time next six min
def price = close;
AddOrder(condition = price crosses above priceH, tradeSize = 100, name = "<ORB>", type = OrderType.BUY_TO_OPEN, price = open);
AddOrder(condition = price crosses below pricelow, tradeSize = 100, name = "<ORB>", type = OrderType.SELL_TO_CLOSE, price = open);
a. My chartbubble shows high three for same high
b. Entry and exit is not working
Any guidance and suggestion will be helpful. Here is my code
input stock = "SPY";
def isopen = if SecondsFromTime(0930) >= 0 and SecondsFromTime(0930) <= 179 then 1 else 0; #to draw high and #low of first three min
#get high of first 3 min
def pricehigh = high(stock, AggregationPeriod.THREE_MIN, PriceType.LAST);
rec priceH = pricehigh;
#get low of first 3 min
def pricelow = low(stock, AggregationPeriod.THREE_MIN, PriceType.LAST);
#plot high and low of first three min
addChartBubble(if isopen == 1 then yes else no, pricehigh, pricehigh, Color.YELLOW, yes);
AddChartBubble(if isopen == 1 then yes else no, pricelow, pricelow, Color.RED, no);
#entry time next six min
def price = close;
AddOrder(condition = price crosses above priceH, tradeSize = 100, name = "<ORB>", type = OrderType.BUY_TO_OPEN, price = open);
AddOrder(condition = price crosses below pricelow, tradeSize = 100, name = "<ORB>", type = OrderType.SELL_TO_CLOSE, price = open);