tradecombine
Member
I'm not aware of a way to take incremental profits, sorry.Hey!
I have been backtesting and I want to test taking incremental profits. In this case, selling 1 contract at 1 atr, 1 at 2, and 1 at three.
This code is for the last part of the strategy and does not have all the variables. It is not optimal, but I am learning.
Code:#keltner channels input kdisplace = 0; def shift1 = 1 * MovingAverage( AverageType.SIMPLE, TrueRange(high, close, low), 21); def shift2 = 2 * MovingAverage( AverageType.SIMPLE, TrueRange(high, close, low), 21); def shift3 = 3 * MovingAverage( AverageType.SIMPLE, TrueRange(high, close, low), 21); def kaverage = MovingAverage( AverageType.SIMPLE, price, length); def Upper_Band1 = kaverage[-displace] + shift1[-displace]; def Upper_Band2 = kaverage[-displace] + shift2[-displace]; def Upper_Band3 = kaverage[-displace] + shift3[-displace]; #profit targets def profit1 = close crosses above Upper_Band1; def profit2 = close crosses above Upper_Band2 or close crosses below Upper_Band1; def profit3 = close crosses above Upper_Band3 or close crosses below Upper_Band1 or close crosses below Upper_Band2; #stop def stop = close < ema34 and close[1] < ema34; AddOrder(OrderType.BUY_TO_OPEN, buy, close, 3, tickcolor = Color.GREEN, arrowcolor = Color.GREEN); AddOrder(OrderType.SELL_to_close, profit1, close, 1, tickcolor = Color.RED, name = "Profit1"); AddOrder(OrderType.SELL_to_close, profit2, close, 1, tickcolor = Color.RED, name = "Profit2"); AddOrder(OrderType.SELL_to_close, profit3, close, 1, tickcolor = Color.RED, name = "Profit3"); AddOrder(OrderType.SELL_to_close, sell, close, 1, tickcolor = Color.RED, name = "Turned"); AddOrder(OrderType.SELL_to_close, stop, close, 3, tickcolor = Color.RED, name = "Stop");
The code keeps opening a position at 3 contracts and then at profit1 it will sell all the contracts. I have tried sell_auto but it then opens a short position.
Is it possible to take incremental profits and not open new short positions?
@Camus1612 Unfortunately, TOS allows for multiple Buys using AddOrder() but I'm fairly certain that Sell orders close the entire trade regardless of how many shares have been bought... Therefore, you can scale into a simulated trade but you cannot scale out...
Reference link: https://usethinkscript.com/threads/...t-auto-buy-sell-in-thinkorswim.741/post-41368
Last edited by a moderator: