Multi-timeframe ROC in Rotation Strategy
Author: crk31174
Creation Date: 8/4/2015 12:05 AM
profile picture

crk31174

#1
Hi,

I am trying to calculate the ROC (5 months ago) on a 60 min chart. But the value appears to be incorrect. Please advise how to fix this:

CODE:
Please log in to see this code.


Thanks,
profile picture

Eugene

#2
Hi,

You're changing scale from inside the main loop which is incorrect. This, as well as creation of a DataSeries, is a "one-time" act to be performed outside of a loop. In general, check out the WealthScript Programming Guide > Multi-Time Frame Analysis and in the QuickRef. None of the examples there instruct to do that this way. Additionally, you will find a specific method for changing scale to monthly: SetScaleMonthly(). It's advised to use that instead because the number of trading days in a month varies.
profile picture

crk31174

#3
Thanks Eugene.

Forgot to mention this earlier. This is a rotation strategy that also runs an inner loop as follows.
As changing the scale inside the main loop is incorrect, should I be moving the inner loop outside the outer loop? Asking this because all the rotation examples I've seen has the following structure with outer and an inner loop.

CODE:
Please log in to see this code.


Thanks,
profile picture

Eugene

#4
Thanks for the clarification which justifies the SetScale* in the loop. I've updated the topic title then. And to avoid such confusion, next time please consider replying in a closely related thread if question arised from there (e.g. here).

I don't know what would be the point in running a rotation strategy that uses monthly series, on intraday data. We're used to apply rotation strategies to daily scale and above. In any case, don't forget to RestoreContext() where necessary.
profile picture

crk31174

#5
Hi Eugene,

Entries are based on price near to the close of last trading day of the month. If I use daily, then the entries will be next day open which is not I want. So, trading on a 60 mins scale allows me to enter, near the close of that day.

Can you confirm that I should be moving inner loop outside the outer loop? i.e, ROC dataseries for each symbol needs to be calculated and set in the MomHolder before opening the "bar" loop?

Thanks,
profile picture

Eugene

#6
Ramkishore,

QUOTE:
Entries are based on price near to the close of last trading day of the month. If I use daily, then the entries will be next day open which is not I want. So, trading on a 60 mins scale allows me to enter, near the close of that day.


Please try out the workaround for Daily data described in the WealthScript Programming Guide > Programming Trading Strategies > Alerts > How to: Alert for AtClose Signals. Hope this helps.

QUOTE:
Can you confirm that I should be moving inner loop outside the outer loop? i.e, ROC dataseries for each symbol needs to be calculated and set in the MomHolder before opening the "bar" loop?


At the moment I can't remember having tried this myself but on the surface it might work. Here's an example of a design pattern similar to what is being discussed:

Snapping Tortoise Rotation, post #5 by ss161
profile picture

Eugene

#7
crk31174 asked:


Hi,

Is it possible to use two providers at the same time:

1) Yahoo provider for dividend adjusted price in order to calculate ROC
2) Fidelity provider for trading(buying/closing at the market)

Thanks,
Ram
profile picture

Eugene

#8
Hi Ram,

What's the purpose? Simply use Yahoo data. The symbol names are identical across both data sources so there's no need to complicate things.
profile picture

crk31174

#9
Hi Eugene,

My concern is the reliability of Partial bar updates for AtClose orders in live trading. Do you know if subscribing for premium membership would ensure better reliability?

Thanks,
Ram
profile picture

Eugene

#10
Yahoo is mostly trouble free, outages are rare. Premium subscriptions are no longer available at Yahoo:

"Effective March 31, 2014, Yahoo Finance premium Real-Time Quotes service will be permanently discontinued (this includes the MarketTracker application)."
profile picture

crk31174

#11
Thanks Eugene. Perhaps, I should consider using partial bar update feature to keep it simple.

Thanks again,
Ram
profile picture

crk31174

#12
Hi Eugene,

Is it correct to use BuyAtClose and SellAtClose in a Rotation strategy? Because, in backtesting when I use AtClose orders with position sizing using Cone's protfolio tracker, I see the trades being skipped. But instead if I use BuyAtMarket and SellAtMarket, no trades are skipped.

Please provide your insights. Much appreciated.

Thanks,
Ram
profile picture

Eugene

#13
You're not using *AtClose(bar+1), aren't you? Essentially, everything on topic is described in the FAQ and User Guide.
profile picture

crk31174

#14
Based on my understanding from reading the documentation, this is how I coded up for AtClose Buy and Sell. Please let me know if there is any glaring mistake you can spot. As I mentioned before, no issues are seen if I use the AtMarket orders as shown within the "commented" section.


BUY:
CODE:
Please log in to see this code.


SELL:
CODE:
Please log in to see this code.

profile picture

Eugene

#15
I've no idea what your PositionSharesCashRemaining and I can't verify if your code does what you say. However, there are 2 differences in translation for the BuyAtMarket snippet:

1) you're taking posAllocation now whereas before you adjusted the size to a smaller posAllocation * 0.99
2) it started peeking at Close[bar+1], if that matters (possible IOOR exception?)
profile picture

crk31174

#16
PostionShareCashRemaining is Cone's code as was posted here: http://www.wealth-lab.com/Forum/Posts/Limit-Monthly-Drawdown-Portfolio-Equity-Tracker-31562#159008

Adjusting the allocation size to a smaller posAllocation * 0.99 for AtClose is not helping with skip trades issue. Also, I can't find any IOOR exception either.

For your reference I am posting the complete code

CODE:
Please log in to see this code.
profile picture

Cone

#17
My name has been invoked, and I feel like it was implied that I created this statement:
CODE:
Please log in to see this code.

I make mistakes, but I probably didn't make that one!

If bar equals Bars.Count - 1 (the last bar of the chart) then bar+1 is undefined; it doesn't exist. It's an error waiting to happen, but an easy one to fix.

I don't know if I can help you with the 700 lines of code that I didn't write, but if you tell me the settings, intervals, and symbols that you run this on, I'll take a look.
profile picture

Eugene

#18
QUOTE:
If bar equals Bars.Count - 1 (the last bar of the chart) then bar+1 is undefined; it doesn't exist. It's an error waiting to happen, but an easy one to fix.

+1. I also suggested to correct this error:

QUOTE:
2) it started peeking at Close[bar+1], if that matters (possible IOOR exception?)
profile picture

crk31174

#19
Hi Cone/Eugene,

Please allow me to clarify. Didn't mean to imply that the erroneous code was written by Cone or anyone of you. My apologies for any misunderstandings.I just took Cone's "portfolio tracking" code posted here(http://www.wealth-lab.com/Forum/Posts/Limit-Monthly-Drawdown-Portfolio-Equity-Tracker-31562#159008), adapted and used in my strategy.

Though, I have fixed the errors and modified position sizing logic, it will be helpful if you can review it before going live.

Regards,


Here are the settings:
Timeframe: Daily
Symbols: DBC,EEM,EFA,GLD,IWB,IWM,IYR,SHY,TLT
Position Size: Override in Script
Backtesting period: 03/01/2006 - 08/01/2015

CODE:
Please log in to see this code.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).