% Trailing Stop Loss Setup TOS Strategy


Category:
0
0

I am wondering if it is possible to predefine entry price based on signal. That is I want to be able to define what the floating P/L is then be able to have a sell order condition for a % trailing stop based on last highest price. I am using the code below that was posted on here some time ago as a scan for PPS+PMC.

<pre>

input xDays = 2;
input price = close;
def ppsBuy = PPS().BuySignal;
def ppsSell = PPS().SellSignal;
def buy = !IsNaN(ppsBuy);
def sell = !IsNaN(ppsSell);
def pmcDiff = PMC().Diff;
def pmcMA = PMC().DiffMA;
def lightBlue = pmcDiff > 0 and pmcDiff > pmcMA;
def darkBlue = pmcDiff > 0 and pmcDiff < pmcMA; def red = pmcDiff < 0 and pmcDiff < pmcMA; def magenta = pmcDiff < 0 and pmcDiff > pmcMA;
def confirmDaysBullish = (Sum(lightBlue, xDays) + Sum(magenta, xDays)) >= xDays;
def confirmDaysBearish = (Sum(red, xDays) + Sum(darkBlue, xDays)) >= xDays;
def confirmedBuy = buy and confirmDaysBullish;
def confirmedSell = sell and confirmDaysBearish;
def buyWithReversal = magenta[1] and lightBlue and Highest(buy, xDays) > 0;
def sellWithReversal = lightBlue[1] and red and Highest(sell, xDays) > 0;
# use this to scan for PPS buy signals that follow bullish PMC
plot BuySignal = confirmedBuy;
# use this to scan for PPS sell signals that follow bearish PMC
plot SellSignal = confirmedSell;
AddOrder(OrderType.Buy_TO_OPEN, BuySignal);
AddOrder(OrderType.Sell_TO_CLOSE, xxx);
AddOrder(OrderType.Sell_TO_OPEN, SellSignal);
AddOrder(OrderType.Buy_TO_CLOSE, xxx);

</pre>

Marked as spam
Posted by (Questions: 6, Answers: 4)
Asked on December 21, 2019 4:45 pm
1887 views
0
Private answer

Trailing stops in chart strategies are exceptionally difficult to write. I wrote an article on the topic:

https://www.hahn-tech.com/thinkorswim-strategies-complex-stop-management/

Far beyond the scope of what I provide for no charge in the Q&A forum. And we cannot interact with the Floating P/L graph when writing strategies. So there may not be a solution to your request.

Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on December 21, 2019 7:46 pm
0
Thanks. I see now how it would cause a lot of issues and also didn't realize the limitations on thinkscript
( at December 21, 2019 10:15 pm)