I have the following code:
I'm trying to get to a automated script that buys 100 shares when the daily 9 SMA is crossed (signaling bullish trend). After it buys 100, I'd like it to hold until the daily 9 SMA is crossed again, at which point it should sell my long position and short 100 shares. Then when the daily 9 is crossed again, cover the 100 and go long 100 etc.
Is this possible with thinkscript?
Cheers,
Ri
Code:
input maline = 9;
def ma = SimpleMovingAvg(Length = maline);
def longsize = 100;
def shortsize = 100;
def buy = close > ma;
def sell = close < ma;
# long when above MA
AddOrder(OrderType.BUY_TO_OPEN, buy, tickColor = Color.LIGHT_GREEN, arrowColor = Color.LIGHT_GREEN, name = "buy", tradeSize = longsize, price = OPEN()[1]);
AddOrder(OrderType.SELL_TO_CLOSE, sell, tickColor = Color.RED, arrowColor = Color.RED, name = "sell", tradeSize = longsize, price = open()[1]);
I'm trying to get to a automated script that buys 100 shares when the daily 9 SMA is crossed (signaling bullish trend). After it buys 100, I'd like it to hold until the daily 9 SMA is crossed again, at which point it should sell my long position and short 100 shares. Then when the daily 9 is crossed again, cover the 100 and go long 100 etc.
Is this possible with thinkscript?
Cheers,
Ri