• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

General ThinkScript question: how to check if you are "in a trade"?

dizzy0ny

New member
Hi,
I have a general thinkscript question. Let's say i have the following code:
def macd = reference MACD(fastLength, slowLength, macdLength, averageType).Diff;
def macd_buy_sig = macd crosses above 0;
AddOrder(OrderType.BUY_TO_OPEN, macd_buy_sig, price = close, shares, tickcolor = Color.GREEN, arrowcolor = Color.GREEN);

Now to exit, i want to check a few conditions only if i'm already in a trade. How do i know whether im already in a trade? A simple example might be: if im in a trade, and the current bar is x% higher than the opening trade bar, i want to exit. Im not sure how i would do this w/ TOS thinkscript code.

Any help would be appreciated.

Thanks
 

Learnbot

Active member
VIP
Hi,
I have a general thinkscript question. Let's say i have the following code:


Now to exit, i want to check a few conditions only if i'm already in a trade. How do i know whether im already in a trade? A simple example might be: if im in a trade, and the current bar is x% higher than the opening trade bar, i want to exit. Im not sure how i would do this w/ TOS thinkscript code.

Any help would be appreciated.

Thanks
AddOrder(OrderType.sell_TO_close… would be it. Also sell to close only triggers when u r in trade already. Hope this help
 

dizzy0ny

New member
I am not really understanding what you are asking for. Would you be able to clarify what do u mean by bar index of the trade signal?
i was able to get an answer to this question on reddit, thanks for the help.
According to mobius, the way to do this is using a recursive function to keep track of the bar number.
 

Similar threads

Top