MIH8
- ago
Hello.

Perhaps there is something very obvious that I am overlooking, but at present I am wondering why the tp is not executed at some points. Here is example strategy to illustrate what I mean.

CODE:
public class MyStrategy : UserStrategyBase {       private EMA ema5;       private ATRP atrp5;       private CandleGenePattern cp;           public override void Initialize(BarHistory bars) {          ema5 = new EMA(bars.Close, 5);          PlotTimeSeries(ema5, "EMA", "Price", WLColor.Green);          atrp5 = new ATRP(bars, 5);          PlotTimeSeries(atrp5, "ATRP", "ATRP", WLColor.Green);          cp = CandleGeneDecoder.FindPattern("Bullish Engulfing");          PlotStopsAndLimits(); } public override void Execute(BarHistory bars, int idx) {          if (idx < 1) return; if (!HasOpenPosition(bars, PositionType.Long)) {             bool found = CandleGeneDecoder.DetectPattern(bars, idx, cp);                          if(bars.Close[idx] > ema5[idx] && found)             {                Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0,"Buy");             } } else {             Position p = LastPosition;             double tp = p.EntryPrice * 1.03;             double sl = p.EntryPrice * 0.97;             ClosePosition(p, OrderType.Limit, tp, "TP");             ClosePosition(p, OrderType.Stop, sl,"SL"); } } } }





0
292
Solved
6 Replies

Reply

Bookmark

Sort
Glitch8
 ( 8.38% )
- ago
#1
My guess would be a Limit Order Slippage setting.
0
Best Answer
MIH8
- ago
#2
Again, good guess, thanks.

I read the documentation (one more time) for it after you mentioned it now.

QUOTE:

Slippage
Slippage simulates less-than-perfect fills for your trades that can happen in the real world. When Slippage is enabled, the entry and exit prices of trades are adjusted based on the amount of Slippage specified, but never beyond the low/high range of the bar.


Which bar is referenced here?
What happens if the price drops below the tp again before reaching the slippage?
What kind of value is practically useful in the EOD context (what thoughts are useful to determine a value)?

Thanks in advance for a short feedback on these questions.

If the TP and SL are both pessimistic at the same time, shouldn't there be a lower TP slippage and a higher SL slippage (different values)? The TP has a very optimistic impact in the strategy above. These are just thoughts.
0
Cone8
 ( 26.65% )
- ago
#3
QUOTE:
Which bar is referenced here?

The bar on which the trade is filled.

QUOTE:
What happens if the price drops below the tp again before reaching the slippage?
Either price achieved the slippage-adjusted price or it did not. We're talking about Limit Slippage here. If it achieved the slippage-adjusted price, the limit order is executed at the limit price. Otherwise, the trade does not fill - as shown at least 5 times in your image.

QUOTE:
What kind of value is practically useful in the EOD context (what thoughts are useful to determine a value)?
0.1% - 0.2%

Here's the deal. If price on a stock chart trades even 1 penny past your limit price, you can be 99.9% sure you would have been filled if your order were as much as 100 shares. Why? Because [all] stock charts show only full-lot trading. If your order were 10,000 shares, then 1 penny past might only have resulted in a partial fill. In this case, a higher slippage value might be warranted.

It's also possible that an odd lot be filled beyond the high or low of a bar. That's negative slippage. This occurs often (every day) for high-priced stocks.

QUOTE:
If the TP and SL are both pessimistic at the same time, shouldn't there be a lower TP slippage and a higher SL slippage (different values)? The TP has a very optimistic impact in the strategy above.
It's an interesting observation, but it's only because you essentially moved your TP and SL prices by using an outrageous slippage price - looks like it's something like 10%. (The positive impact is similar to "Slippage Usage Note #2".)

Note!
You highlighted the part about never adjusting beyond the low/high range of the bar. Limit prices are usually not adjusted (there is an exception). We'll move that sentence to the next paragraph that refers only to Market, Stop and AtClose orders. The "Exception" covers this for Limit orders.
0
MIH8
- ago
#4
Thank you very much for your explanations. Please be patient with me a little longer.

As you correctly point out, it can be seen at which bar the "slippage limit" is reached. I noticed that too. That is also the reason why I wanted to clarify how it works. I had a different idea of how it is implemented. I thought that at the bar where the actual limit is reached, the trade is ended but the slippage is calculated. Yes, the WL implementation makes more sense, but I had a simple reason to ask beyond what can be seen on the chart. It has been clarified by you now.

The next point is about the different slippage price. I agree with you again, that if the there is a normal or low slippage the mentioned effect is neglible.

From a practical point of view, however, I can also imagine cases in which a separation would make sense. With volatile stocks, a higher slippage can make sense for the stop. MRNA, for example, regularly moves by more than 0.5% in a few seconds. In such a case, 0.2% TP and 0.5% SL slippage would be worth considering.

However, Cone, you have answered my question completely. Thank you very much.
0
Cone8
 ( 26.65% )
- ago
#5
Market-order slippage is implemented to always give you a "full adverse" effect for every trade. That's also not the way slippage works in real life.

Zero-slippage MOO and MOC are also available for live EOD trading.

Anyway, it's just a backtest option to observe its effect, and no matter how complex you try to make it, there's no option that will accurately predict slippage for live trading. That's impossible.

Probably a good way to set it is to enter an average slippage calculated from your live trade data.
0
MIH8
- ago
#6
I fully agree. The complexity is absolutley suffiecient for practical purposes. Thanks to the explanation, I now also have a clear understanding of how it is utilised.
0

Reply

Bookmark

Sort