Buying a specific symbol to be used instead of cash when a system is out of the market
Author: Tobey
Creation Date: 2/27/2014 1:10 PM
profile picture

Tobey

#1
Hi Cone & Eugene,

The code below goes to cash if the SPY falls below the moving average. In a down turn I'd like to buy at market the Symbol BTTRX in stead of cash?

CODE:
Please log in to see this code.

In none code I need to add something like this
CODE:
Please log in to see this code.


Is there an example of somthing like this? And will some code need to be added to the sell side to handle a Symbol like this that is used to replace cash.

As Always Thanks for the help
Tobey
profile picture

Cone

#2
You don't have to set context to sell a Position, only a reference to the Position is required. I think this logic is correct, but untested...

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

Tobey

#3
Hi Cone,

The new code started to work. But after a few trades it bought XLE and held it from 2005 until now.

The attached spreadsheet has the results with and with out the new code. We are close but some possible condition isn't covered. I've highlighted the trade in both lists.

Thanks for taking another look.

Tobey
profile picture

Tobey

#4
HI Cone,

I just noticed the code is using BuyAtMarket. BTTRX is a fund so I think it has to be bought at close. I tried it but that change alone wasn't enough to fix it.

Thanks
Tobey
profile picture

Cone

#5
It sounds like you have a problem with data or the HighROCSymbol routine. I can't help assemble the script correctly without all the pieces.
profile picture

Tobey

#6
Hi Cone,

Thanks for taking a look at it. Here is the code that works for going to cash.
And this is the Ticker list SPY XLB XLE XLF XLI XLK XLP XLU XLV XLY XTL

Thanks
Tobey

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

Cone

#7
1. Make sure BTTRX is not in the DataSet of ETF sector stocks, but it should appear in any other DataSet.
2. The Strategy using AtMarket orders works fine, but introducing the AtClose orders creates some interaction that I'm too tired to track down right now.

Since you're trading it monthly anyway, it probably will make no statistical difference if you enter at the close on the next day anyway. You could write that into the code too and run it on Daily bars with a Monthly Scaling conversion, but it's hardly worth all that trouble.

Another suggestion is to use the "EOD Scaling Provider" to generate different Monthly DataSets to see if varying the day of the month makes any difference.


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

Tobey

#8
Hi Cone,

Thanks for the help!

Tobey
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).