Trailing stop


Category:
0
0

Hello Pete

I had a question on Trailing stop order, I was able to use the condition function to execute the order and once a position was established, I was able to paste the trailing stop order in the paste order windows (that certainly helped a lot to place a trailing stop order then to click here and click there, its too many clicks !! ) below is the code that was generated by TOS order form for trailing stop.

SELL -100 MSFT TRSTP MARK-.50 (STP 94.88) MARK

Since the 0.50 cents is a fix stop amount, and most of the time its difficult to gauge when to get out or how much stop to trail with.

Is there any way to generate a programming code in the strategy builder to have a stop order just below the previous candle minus 10 cents so e.g as you can see in the picture the low of the candle is 93.52 I wanted to place the order 93.52-0.10 at 93.42 and then when the price moves to the next candle the stop should move to previous candle low minus 10 cents and so on, until the stock stops climbing and then of course the position is closed out automatically, once the stop is hit.

Thanks.

Attachments:
Marked as spam
Posted by (Questions: 2, Answers: 2)
Asked on May 1, 2018 6:40 pm
466 views
0
Private answer

This: SELL -100 MSFT TRSTP MARK-.50 (STP 94.88) MARK

Is not code. That is the literal description of the order you created and is used as the order template when you save the order as template. This will not work in the condition order window, which is where the rest of your question appears to be directed.

Be very careful with your terms. There is no such thing named “strategy builder”. I have to assume you are referring to an order that has a study based condition attached to it. For simplicity, we refer to this as a “conditional order”. The code for the condition, is written within a view titled “Study Order Condition” (as seen at the top of the second screenshot below).

These tools were covered in great detail in my video titled: “Thinkorswim AutoTrading Almost

So I see that you want to add a condition to an order that is triggered when the price of the current 1 min candle crosses below the low of the previous candle minus 10 cents. The two screenshots below show how to construct this conditional order.

In the first step, we create a condition that is true when the close of the current bar crosses below the low of the previous bar. In the second step we move over to the Thinkscript editor and add this to the very end of the result built in step one: “- 0.10”.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 1, 2018 7:01 pm
0

That worked, Thanks !!

( at May 3, 2018 5:20 pm)
0

Hi Master Hahn,

~I posted (submitted) the text below in the “Answer” text box, so I could attach a picture. Sorry to re-post the text here, but I just wanted to make sure the text showed up on this page. Reply at your leisure. Thanks again. Phil~

I am trying to create a custom “Order Condition” to automatically close out trades for me. Please let me know if what I’m doing is possible.

Closing Condition #1:
In this situation the PSAR dot (from yesterday) is under the stock. The the sell condition would be triggered when the PSAR dot (in the current trading day) “flips” to above the current candle. I am assuming that as long up-trend in the stock is maintained, the PSAR dot would remain under the intraday candle. The dot would only appear above the intraday candle, if the up-trend in the stock has ended. Triggering a sell signal. I’m looking at trades that would last around two weeks. This intraday dot-flip condition might be too sensitive…but would be interesting to see how it works.

Closing Condition #2:
In this situation the PSAR dot (from day before yesterday) is under the stock candle. The PSAR dot (from yesterday) closed above the candle. With these two conditions met, when the current trading day begins, the sell condition would be immediately triggered when the market opens. This seems like a more realistic condition, and less prone to premature triggering.

I have reviewed your videos and a bunch of the content on your website, very helpful, and I understand that the simple code for the studies and scans can’t be used to generate strategies or conditional orders.

I can create this simple “custom study” in my charts. It shows up like an indicator under the chart, so I can easily see when the PSAR dots have flipped.

Study / scan code:
ParabolicSAR(“acceleration factor” = 0.025) is greater than high and
ParabolicSAR(“acceleration factor” = 0.025) is greater than ParabolicSAR(“acceleration factor” = 0.025) from 1 bars ago

Also see the attached picture…it’s kind of crazy looking, but you should get the idea.

Please let me know how can I can create these conditional closing orders based on the movement of the Parabolic SAR?
Thanks, Phil

P.S.
When I open the “Trade” tab, and try to create a custom conditional closing study builder, I don’t see Parabolic SAR in the list of studies in the drop-down list provided by thinkorswim. What’s up with that?

P.S.S.
If this is impossible, is there a different indicator that can be used to trigger a conditional closing order, that is equivalent to the PSAR dot flip?

P.S.S.
I have seen you recommend trade station. Would it be a better platform for this PSAR stuff?

( at August 8, 2018 2:42 pm)
0

Hey. Update. I made this custom study after watching your “Custom Scan Stochastic MACD” video. Stoked. Your educational content is awesome. I still need help with the conditional order stuff.
#
# TD Ameritrade IP Company, Inc. (c) 2008-2018
#

input accelerationFactor = 0.025;
input accelerationLimit = 0.2;

Assert(accelerationFactor > 0, “‘acceleration factor’ must be positive: ” + accelerationFactor);
Assert(accelerationLimit >= accelerationFactor, “‘acceleration limit’ (” + accelerationLimit + “) must be greater than or equal to ‘acceleration factor’ (” + accelerationFactor + “)”);

def state = {default init, long, short};
def extreme;
def SAR;
def acc;

switch (state[1]) {
case init:
state = state.long;
acc = accelerationFactor;
extreme = high;
SAR = low;
case short:
if (SAR[1] < high) then { state = state.long; acc = accelerationFactor; extreme = high; SAR = extreme[1]; } else { state = state.short; if (low < extreme[1]) then { acc = Min(acc[1] + accelerationFactor, accelerationLimit); extreme = low; } else { acc = acc[1]; extreme = extreme[1]; } SAR = Max(Max(high, high[1]), SAR[1] + acc * (extreme - SAR[1])); } case long: if (SAR[1] > low)
then {
state = state.short;
acc = accelerationFactor;
extreme = low;
SAR = extreme[1];
} else {
state = state.long;
if (high > extreme[1])
then {
acc = Min(acc[1] + accelerationFactor, accelerationLimit);
extreme = high;
} else {
acc = acc[1];
extreme = extreme[1];
}
SAR = Min(Min(low, low[1]), SAR[1] + acc * (extreme – SAR[1]));
}
}
def parSAR = SAR;

plot data = (parSAR[1] < parSAR) and (parSAR > close);

( at August 8, 2018 3:43 pm)
0

You cannot use PSAR in a conditional order. There is no workaround.

( at August 8, 2018 8:26 pm)