• LIMITED TIME ONLY: Take $40 off VIP with code: BTD40.

Ensure exit is not on same candle as the entry, also trading hours?


New member
Hello All,
If I have an 'entry' criteria and a 'exit' criteria at the same time my strat will enter and exit at the same candle, how can I force it to at least wait till the next candle before exiting ?

, open[-1],
stock_quantity, Color.GREEN, Color.GREEN);
# I want like a IF here so it will skip the sell if it just bought on this candle
open[-1], stock_quantity, Color.RED, Color.RED);

I want to make the 'sell to close' only fire if the 'buy to open' has NOT fired for that candle, so it will fire on the next candle. I've simplified my code it actually looks at an RSI but that's irrelevant.

Also does anyone know how to make it so it will only enter or exit orders during normal market hours, and extra bonus plus if you can tell me how to make it exit any current orders at the end of the day.

Thanks for your time,
Last edited by a moderator:


input usetimefilter = Yes;
input rthopen = 0930;
input rthclose = 1031;
def RTH = if usetimefilter == yes then if SecondsFromTime(rthopen) >= 0 and
SecondsTillTime(rthclose) >= 0
then 1
else 0 else 1;

AddOrder(OrderType.BUY_TO_OPEN, RTH and BuySignal[-1], price = buyorderprice, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "CDS_LE_G");

Set the time you wish to trade


Well-known member
I generally define my buy and sell criteria and then compare to make sure there wasn't a buy during the same iteration of the script code... Usually something like "if sell and !buy", or something to that effect...


Well-known member
#Method One
AddOrder(OrderType.SELL_TO_CLOSE, DownSignal and !UpSignal, open[0], 100, Color.ORANGE, Color.ORANGE, "SS1 @ " + open[0]);

#Method Two
def SellSignalTwo = if close[-1] < high[-1] - HighStopLoss and !BuySignalOne then 1 else 0;

Similar threads