Ok, based on the previous comments from Robert on 5/17/18, I think I still have some things to explain here. I believe the issue is a problem in defining the terms.
Conditional Orders: Do NOT contain AddOrder() statements. Do NOT contain both a buy and sell signal. Conditional orders are applied to an actual order. The order is sent to market when the condition of the code evaluates to true.
Theoretical Orders: Are plotted on a chart and DO contain the AddOrder() statements.
So let’s make sure you understand the terms and are using them correctly.
From the webpage of the video named “Thinkorswim AutoTrade Almost” we have this template:
This is the code for the Strategy Template:
input tradeSize = 100;
def signal = 0;
addOrder(OrderType.BUY_TO_OPEN, signal, open[-1], tradeSize, Color.CYAN, Color.CYAN);
def exit = 0;
addOrder(OrderType.SELL_TO_CLOSE, exit, open[-1], tradeSize, Color.MAGENTA, Color.MAGENTA);
You see that? This is the code for the Strategy Template. This has absolutely nothing to do with a Conditional Order. No connection whatsoever. This is used to plot Theoretical orders on a Chart Strategy.
Taking the code from your example screenshot:
input tradeSize = 100;
def signal = RSI()."RSI" crosses above 25 and close crosses below BollingerBands()."LowerBand" within 8 bars;
addOrder(OrderType.BUY_TO_OPEN, signal, open[-1], tradeSize, Color.CYAN, Color.CYAN);
def exit = RSI()."RSI" < RSI()."RSI"[1] and high > BollingerBands()."UpperBand" within 4 bars;
addOrder(OrderType.SELL_TO_CLOSE, exit, open[-1], tradeSize, Color.MAGENTA, Color.MAGENTA);
This is NOT for a Conditional Order. This is for a Chart Strategy. There are two AddOrder() statements in this code. One for a buy to open and one for a sell to close. This can only plot long sided trades. It cannot plot a sell order on the chart before a buy order has been plotted. You cannot use this for a conditional order. Why? The order types. BUY_TO_OPEN and SELL_TO_CLOSE. This expressly excludes SELL_TO_OPEN. So shorts are impossible here.
So, you want to see what part of that code CAN be used for a conditional order? Code that you can apply to an actual order that gets submitted to the market?
input tradeSize = 100;
def signal = RSI()."RSI" crosses above 25 and close crosses below BollingerBands()."LowerBand" within 8 bars;
That’s it. That is your buy condition that you can apply to an order that gets submitted to market. When the condition evaluates to true the order gets sent to market.
What about the exit?
input tradeSize = 100;
def exit = RSI()."RSI" < RSI()."RSI"[1] and high > BollingerBands()."UpperBand" within 4 bars;
Hope this clears things up.
Great, Thanks.!