MIH8
- ago
Today i observed a situation i would like to make a suggestion.
First, I would like to say that in this case, technically, everything is working as it is designed.

I started a strategy with a 15 minute scale. At 1600 a run started and checked for signals.
At 1601, one of my open positions reached the TP. (directly after the run).
My average price was 19.78 and the TP was at 19.99 and it dropped again to 19.82 until the next run at 1615.

The auto trade simply missed the chance to do the exit. This can happen at every scale of course.
After a short think i had the following idea to improve on that.

Well, the special case of TP+SL can be handeled in many ways. So, the more general question for me was,
but including TP and SL, how to minimize missing exit situations.

The point would be to have two scales. One that runs the strategy in it's standard intervall and another (smaller) one, that only checks the symbols in the portfolio for an exit. In my example if 15 Minute is the scale for the strategy, the check of the portfolio (for exits) can be configured in 5 or 1 minute scale. In my example the price was stable for about 2,3 minutes before it began to drop again.

I also think that there is a significant difference between this and backtesting. In backtesting, you never miss this point in time.
The backtest only simulates that there was the price and assumes that you pick it up.

Meanwhile the price dropped to 19.74 ... (paper trading)
0
375
Solved
13 Replies

Reply

Bookmark

Sort
Glitch8
 ( 8.38% )
- ago
#1
Even with a 15 minute scale, your Limit exit order will remain live at the broker for that full 15 minutes. So, I'm not sure how this granular scale feature would help in any way. I probably just don't understand the request yet.
0
MIH8
- ago
#2
Hi Glitch, seems my description was not expressed well. I'll try it again.

1. Already yesterday i opened a position, this one


2. The strategy should sell at 1% TP. The scale is 15 minute. At 16:00 pm (local time) the strategy was triggered, as usual. The price was close to 1%, let say 0,99%. So, no sell signal was triggered (which is ok i think).

3. Now, at 16:01 the TP was reached, but no further signal will be generated until 16:15.
Thats is ok too, because it is a 15 minute scale. The TP was hold for some minutes. Unfortunately the price dropped then again to, let's say +0,3% before the next run.

4. So the idea is to let the strategy run every 15 minutes as it is usual, but to do a check for sell signals (exits) let us say every minute (as example). This check would only be needed for open positions (not for the complete dataset) in the portfolio.

A strategy setup would include the standard scale 15 minute and a second scale smaller than 15 minutes to check the portfolio for exits.

So, the point is, that there was no signal and the price movement was completely within the scale. The idea would have catched the TP. By the way, that can never happen in a backtest. The backtest only knows the price was within low and high. And it tells us that it catched the price everytime. If i miss something important, please just let me know. If there are good reasons to ignore the idea, it is ok too.

I think that price movements within a scale is not unusual, what do you think?
0
Glitch8
 ( 8.38% )
- ago
#3
Are you using market orders to exit?

If so, and you want to capture more granular movements, this is already possible in Strategy code. You can base your Strategy on 1- or 5-minute data, but have it use more compressed 15-minute data. It's similar to using weekly indicators in a daily Strategy.

This is already possible and I don't feel it needs to be expressed as another feature request.

Another way is to use a limit order to exit instead of a market order.
0
Best Answer
MIH8
- ago
#4
Of course, if this can be handled in a way i do not know so far, it is not needed.
So i will explore the available solution, maybe you can guide me.

QUOTE:
... You can base your Strategy on 1- or 5-minute data, but have it use more compressed 15-minute data. ...


I simply do not understand what you mean. Do you talk of strategy monitor seetings? Or the strategy itself?



If this would be the setup, what must i do, to check the symbols in the portfolio for sell, with a more granular scale of 1 minute?
0
- ago
#5
QUOTE:
I simply do not understand what you mean. Do you talk of strategy monitor seetings? Or the strategy itself?

Glitch is talking about the WealthScript approach to compress the data into a higher scale. Check out Post #5 for a sample code:
https://www.wealth-lab.com/Discussion/Setting-up-a-multi-time-frame-strategy-and-IB-data-10-min-daily-7568
0
MIH8
- ago
#6
Thank you. I will have a look at it in the coming days.
0
- ago
#7
QUOTE:
3. Now, at 16:01 the TP was reached, but no further signal will be generated until 16:15. That's is okay too, because it is a 15 minute scale.

Rather than using a Market Order, why not use a Stop or Limit Order instead so the exchange (and WL) takes the trade at the trigger point regardless of the time scale?

Stop and Limit orders don't care about time scales. When you hit the trigger point, the stock is automatically traded on the exchange side. Are you saying this is a bad feature you want to avoid?

I would trade such that time scales are not a function of the trading outcome. Use Stop and Limit orders to do that with.
0
MIH8
- ago
#8
Hello superticker,

in all likelihood, this topic is no longer relevant. At least, I can't rule out that this behavior was caused by my fumbling. For some reason I have activated the offline mode. What effects this had during the session, I cannot know. This described behavior would probably not have occurred. Besides, it was not a market order.

I had still posted this here on the appropriate day, but I think it was made into a feature request to protect the user from their own ..., you know.

As long as I can't observe similar behavior, I assume it was related to that.

Nevertheless, thanks for your feedback. I find it refreshing when more people get involved in discussions as well.

You can search for "Offline Warning", you will find the request.
1
MIH8
- ago
#9
Hi, i just looked into the compressor logic and tried to implement a simple strategy.

The goal is to simulate a 15 minute time frame (check for buy signals), but scanning for sell signals every minute (strategy time scale).
The strategy is just to try out the compressor logic.

I especially wonder how the idx (1 minute strategy time frame) relates to the compressed data. I look forward to corrections and comments.

Thank you very much.

CODE:
      private BarHistory bars15;       private TimeSeries priceLimit;        public override void Initialize(BarHistory bars) {          // running 1 minute time frame          bars15 = BarHistoryCompressor.ToMinute(bars,15);          // compute limit -0.25% to go long          priceLimit = bars15.Close * ((100.0 - 0.25) / 100); } public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) {             // check entry signals every 15 minutes (simulating 15 minute time frame)             if (idx % 15 == 0 /*more conditions*/) {                PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, priceLimit[idx / 15], "Buy");             } } else {             Position lp = LastPosition;             double tp = lp.EntryPrice * 1.01;             double sl = lp.EntryPrice * 0.99;             // scan 15 minute intervall every minute (strategy time frame) to generate sell signals             if(lp != null) {                PlaceTrade(bars, TransactionType.Sell, OrderType.Limit, tp,"Take Profit");                PlaceTrade(bars, TransactionType.Sell, OrderType.Stop, sl,"Stop Loss");             } } }
0
Cone8
 ( 25.05% )
- ago
#10
The question is, why does the strategy need to scan for buy signals?

For the strategy you posted, there's no reason to run it in a 1 minute scale. Just use a 15-minute (or any) scale instead. Here it is again, with same-bar stops enabled - just paper trade it, you'll see.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript123 { public class MyStrategy : UserStrategyBase {       private TimeSeries priceLimit;       public override void Initialize(BarHistory bars)       {          StartIndex = 1;          // compute limit -0.25% to go long          priceLimit = bars.Close * ((100.0 - 0.25) / 100);       }       public override void Execute(BarHistory bars, int idx)       {          if (!HasOpenPosition(bars, PositionType.Long))          {             PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, priceLimit[idx], "Buy");             }          else          {                Position lp = LastPosition;      // LastPosition cannot be null here             PlaceTrade(bars, TransactionType.Sell, OrderType.Limit, lp.EntryPrice * 1.01, "Take Profit");             PlaceTrade(bars, TransactionType.Sell, OrderType.Stop, lp.EntryPrice * 0.99, "Stop Loss");                      }       }       //this will Auto-Place your stops and limits on the entry bar as soon as the Limit order fills public override void AssignAutoStopTargetPrices(Transaction t, double basisPrice, double executionPrice) {          t.AutoProfitTargetPrice = executionPrice * 1.01;          t.AutoStopLossPrice = executionPrice * 0.99; } } }


Compressed scaling would be required if you're trading 15-min bars, but you want to filter or trigger based on an indicator in a higher scale. For example, you may not want your intraday strategy to go long if trading below the 20-day SMA. Or maybe you want to make sure the 30-minute bar RSI-14 is below 40. etc.
0
MIH8
- ago
#11
Hi Cone.

First, thanks for the hints about the AutoStop and LastPosition.

QUOTE:

Compressed scaling would be required if you're trading 15-min bars, but you want to filter or trigger based on an indicator in a higher scale. For example, you may not want your intraday strategy to go long if trading below the 20-day SMA. Or maybe you want to make sure the 30-minute bar RSI-14 is below 40. etc.


Well, that is what i had in mind. But with 1 minute (strategy scale) and 15 minute (indicator scale). There is a little comment in my code in the buy condition. "more conditions". This is the place where i want to use the 15 minute scaled data.

Important (and it will answer your question, i hope so :-) ):
The original goal was a more granular check of conditions below the time scale of my strategy. However, since the framework provides the compressor, the implementation works the other way around. I run the strategy in the granular time scale, checking the entry conditions only in/for the higher time scale. This is the idea.

Please keep in mind it is not about the strategy, single conditions or if it makes any sense at all. I would like to know two things.

1. did i use the compressor for bars15 in the correct way? (in context to my description)

2. if i have two Timeseries, 1 min + 15min. How do i need to use the idx for the 15 minute scale, or more general the higher scale? (For any operation, of course it was misleading to use it only for the buy signal). For example, is bars.Cose[idx] == bars15.Close[idx/15] ? Or what does idx%15 mean for the for the bars15 Timeseries?




0
Cone8
 ( 25.05% )
- ago
#12

1. did i use the compressor for bars15 in the correct way?

bars15, yes, but once you do something with it, you need to use TimeSeriesSynchronizer to synchronize it back to the base time frame.

2. if i have two Timeseries, 1 min + 15min. How do i need to use the idx for the 15 minute scale?
This is a huge mistake - [idx/15]
Click BarHistoryCompressor in the code and then see the example for ToHour(). Once you synchronize, you use idx everywhere.

If you need to compare your indicator in the compressed period for a change from bar to bar, do the comparison while compressed and save the result in another series before Synchronizing.
2
MIH8
- ago
#13
Thanks Cone, very useful. I'll try it out as soon as possible.
0

Reply

Bookmark

Sort