Hello,
I am trying to set up an order to close based on the EntryPrice, a stop loss value, and the amount of time that has passed since entering the position.
For example, suppose I added an order based on the following...
#### OPEN POSITION
#### LONG Bull
AddOrder(OrderType.BUY_TO_OPEN, Bull1 and Bull2 and Bull3, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long_Bull_Open");
#### SHORT Bear
AddOrder(OrderType.SELL_TO_OPEN, Bear1 and Bear2 and Bear3, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "Short_Bear_Open");
The following works for using a Stop Loss Order, but doesn't include the criteria for the amount of time that has passed.
#### CLOSE POSITION DUE TO STOPLOSS
#### LONG CLOSE
input stoplossLONG = 1.50;
def stopLONG = EntryPrice() - stoplossLONG;
AddOrder(OrderType.SELL_TO_CLOSE, close < stopLONG, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Long_Close_Stop");
#### SHORT CLOSE
input stoplossSHORT = 1.50;
def stopSHORT = EntryPrice() + stoplossSHORT;
AddOrder(OrderType.BUY_TO_CLOSE, close > stopSHORT , tickcolor = Color.RED, arrowcolor = Color.RED, name = "Short_Close_Stop");
I am not sure how to count minutes or candlesticks after opening the position and add it to the code above. If I am using a "1 minute" chart and see that my stop loss has been exceeded AND ten minutes have passed, I would then exit the trade. Here is a hypothetical code below.
#### CLOSE POSITION DUE TO STOPLOSS AND TIME CONDITION IS MET
#### LONG CLOSE AFTER TBD MINUTES
input stoplossLONG = 1.00;
def stopLONG = EntryPrice() - stoplossLONG;
AddOrder(OrderType.SELL_TO_CLOSE, close < stoplong and TIME_CONDITION_MET, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Long_Close_Stop");
#### SHORT CLOSE AFTER TBD MINUTES
input stoplossSHORT = 1.00;
def stopSHORT = EntryPrice() + stoplossSHORT;
AddOrder(OrderType.BUY_TO_CLOSE, close > stopSHORT and TIME_CONDITION_MET, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Short_Close_Stop");
Any help on how to count the elapsed time (or the number of candles) after entering a position would be greatly appreciated. Also, the counter will need to be reset after exiting the trade.
I am thinking there may be some clues in this thread, but am not sure how to pick the starting candle when the position is opened in the strategy.
https://usethinkscript.com/threads/consecutive-bar-count-indicator-for-thinkorswim.324/
Thanks,
TMB_70
Pretty please? Thank you.
I am trying to set up an order to close based on the EntryPrice, a stop loss value, and the amount of time that has passed since entering the position.
For example, suppose I added an order based on the following...
#### OPEN POSITION
#### LONG Bull
AddOrder(OrderType.BUY_TO_OPEN, Bull1 and Bull2 and Bull3, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long_Bull_Open");
#### SHORT Bear
AddOrder(OrderType.SELL_TO_OPEN, Bear1 and Bear2 and Bear3, tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "Short_Bear_Open");
The following works for using a Stop Loss Order, but doesn't include the criteria for the amount of time that has passed.
#### CLOSE POSITION DUE TO STOPLOSS
#### LONG CLOSE
input stoplossLONG = 1.50;
def stopLONG = EntryPrice() - stoplossLONG;
AddOrder(OrderType.SELL_TO_CLOSE, close < stopLONG, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Long_Close_Stop");
#### SHORT CLOSE
input stoplossSHORT = 1.50;
def stopSHORT = EntryPrice() + stoplossSHORT;
AddOrder(OrderType.BUY_TO_CLOSE, close > stopSHORT , tickcolor = Color.RED, arrowcolor = Color.RED, name = "Short_Close_Stop");
I am not sure how to count minutes or candlesticks after opening the position and add it to the code above. If I am using a "1 minute" chart and see that my stop loss has been exceeded AND ten minutes have passed, I would then exit the trade. Here is a hypothetical code below.
#### CLOSE POSITION DUE TO STOPLOSS AND TIME CONDITION IS MET
#### LONG CLOSE AFTER TBD MINUTES
input stoplossLONG = 1.00;
def stopLONG = EntryPrice() - stoplossLONG;
AddOrder(OrderType.SELL_TO_CLOSE, close < stoplong and TIME_CONDITION_MET, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Long_Close_Stop");
#### SHORT CLOSE AFTER TBD MINUTES
input stoplossSHORT = 1.00;
def stopSHORT = EntryPrice() + stoplossSHORT;
AddOrder(OrderType.BUY_TO_CLOSE, close > stopSHORT and TIME_CONDITION_MET, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Short_Close_Stop");
Any help on how to count the elapsed time (or the number of candles) after entering a position would be greatly appreciated. Also, the counter will need to be reset after exiting the trade.
I am thinking there may be some clues in this thread, but am not sure how to pick the starting candle when the position is opened in the strategy.
https://usethinkscript.com/threads/consecutive-bar-count-indicator-for-thinkorswim.324/
Thanks,
TMB_70
Pretty please? Thank you.
Last edited: