- ago
Hi,

I have a strategy which buys at market and sets a stop loss at 2%. If the stop loss is not triggered, it will be sold after 2 bars.

My question: When entering the order, how do I calculate the stop loss price: Do I deduct 2% from the closing price or from the high price?

And: If the stop loss is not triggered on the day of the purchase (I have same day stop loss activated), do I have to change the stop loss price after the end of this day? (And if yes, how?)

Thanks for your help!
Werner
0
150
6 Replies

Reply

Bookmark

Sort
- ago
#1
QUOTE:
how do I calculate the stop loss price: Do I deduct 2% from the closing price or from the high price?

That's entirely up to you. Part of why you're running a backtest simulation tool (such as WL) is to try it both ways and look at the Metrics Report to see what works best.

There is a BarHistory property called ".AveragePriceHLCC" that will return a weighted average price you might also want to try.
CODE:
         PlotTimeSeries(bars.AveragePriceHLCC, "Average Price w/ Double-weight Close", "Price", WLColor.Blue, PlotStyle.Line);
Something like the code below might work, but I haven't tried it.
CODE:
         PlaceTrade(bars, TransactionType.Sell, OrderType.Stop, bars.AveragePriceHLCC[idx]*0.98, "-2% avgPrice stop sell");
[idx] is the index passed in by the Execute(BarHistory bars, int idx) statement.
0
- ago
#2
Hi Superticker,

thanks for your answer. I use building blocks without coding. So, there is just a percent value you can enter. However, this stop loss works fine with my strategy.

But when entering the order, I don t know from which price the strategy calculates the stop loss. So, I can t enter it properly.

Werner
0
- ago
#3
QUOTE:
I use building blocks without coding.

You should have said that earlier. I know nothing about using building blocks. But if you want to do lots of "fancy stuff", doing it in code would be easier. Building blocks works fine for simple stuff though.

QUOTE:
If the stop loss is not triggered on the day of the purchase..., do I have to change the stop loss price after the end of this day?

I would always opt to use the most recent data (price) possible.
0
- ago
#4
I found a solution for now. I changed the code of a strategy in a way that it sets the stop loss based on last bar's close and not based on the entry price as normally happening.

This is not an efficient behaviour in terms of APR, but it allows me to trade the strategy through only entering the orders at night. And still, this stop loss seems to have a positive effect.

Of course my final goal would be to write a program which uses the IBK API and which will - when the stock exchange opens and the shares are bought - automatically set the right stop loss order based on the entry price.

Well, I am planning to work on such a program and I really want to do it. The only problem is: Whenever I decided to sit down and give it a go, I suddenly feel so tired. So, I guess the right moment still has to come....
0
- ago
#5
QUOTE:
write a program which uses the IBK API and which will ... set the right stop loss order based on the entry price.

You don't need to use the broker's API to determine that, which would be complicated. WL has a NextSessionOpen indicator that will do that for you. You'll first need to install the WL PowerPack extension to see it. https://www.wealth-lab.com/Discussion/Opening-price-not-available-after-market-open-11981

But honestly, there's so much random variability in the stock price--especially at the market Open--that I doubt it's worth the trouble unless your profit margin is very small.
0
- ago
#6
OK, thank you very much for your help, Superticker!
1

Reply

Bookmark

Sort