I'm trying to buy from a Sorted List
I'm trying to implement a strategy that uses a "Market Timer" and a Search/Sort.
I've looked at the Weak-stock Rotation Strategy and Dogs of the Dow Strategy. (very helpful)
In my example, an 8-day ema crossing a 20-day ema of symbol VTI is used to signal entry & exit of Long Positions at the Next Day's Open (NDO).
The search puts all symbols from the DataSet whose Price/Sales Ratio is > 0 into a List.
Then, sort the List in ascending order.
Enter = Buy the 5 stocks in the List with the lowest Price/Sales Ratio at the NDO.
Exit = Sell all positions at NDO.
This code seems to be working in that, on each buy signal, 5 positions are being bought, and on each sell signal, all positions are being sold,
But ... on the buy signal one or two of the symbols are being bought more than once, (multiple positions of a symbol are being bought). I would like only one position to be bought per symbol, so I'd like 5 different stocks to be bought on each buy signal.
I'm using Position Simulation Mode
Position size = 20% of Equity.
Margin factor 1 to 1.
WealthLab Pro 6.0.55.0
Scale: Daily
Date Range: 2 yrs
Computer: Intel P4 Dual Core, running Vista (32-bit), 3 GB Ram, 200GB HDD.
Any advice would be appreciated.
CODE:
Please log in to see this code.
Size:
Color:
Any thoughts?
Do I need to restate or simplify my question?
Best regards, Robert
Size:
Color:
What's NDO?
You've made 2 big mistakes (at least):
1. DataSeries psr, used in the numeric sort, is created only once for the primary symbol. In other words, psr is the same DataSeries for all symbols.
2. The {} statement block delimiters are out-of-whack, so it's difficult to see that you've put the entry logic inside the DataSetSymbols loop. I don't know how you can get the blocks so out of line since the Editor automatically corrects them, but that's the problem.
Size:
Color:
Try this -
CODE:
Please log in to see this code.
Size:
Color:
Cone,
Thanks very much! I'll check my DataSeries & try your code.
NDO = Next Day's Open
The {} weren't out-of-whack, until I tried to make the comments easier to read after I pasted code between the [code tags]. I guess I got them messed-up at that time. I didn't notice the whackiness until after it was posted. sorry.
Best regards, Robert
Size:
Color:
Cone, Thanks again.
FYI - Your code seems to be working fine. Sometimes it still bought multiple positions in some symbols, but I changed the Position Size
from: Percent of Equity = 20%
to: PosSizer = One Trade per Symbol
Configure, Pct of Equity = 20
And now it only gives one position per stock symbol, just like I want.
I also had to increase margin from 1 to 1, to 1.2 to 1, so I'd always get to buy all 5 stocks.
Thank you and best regards,
Robert
Size:
Color:
QUOTE:
Sometimes it still bought multiple positions in some symbols
Just wondering, are you sure the code is being run in single symbol mode?
Size:
Color:
Hi Eugene, I'm not really sure, I'll have to look at that part of it again (I'm still new at this stuff).
I thought that since I removed all but 5 stocks from my sort_list (confirmed by PrintDebug), and then only bought from sort_list, that those 5 stocks & only those 5 stocks (one position for each) would be bought. But that doesn't happen with Portfolio Simulation Mode: Percent of Equity = 20%. It bought from sort_list, but sometimes one or two stock symbols would get multiple positions.
From DebugPrinting, it seems that the whole trading loop is run for each symbol in the DataSet, rather than going through the trading loop once and checking each symbol in the DataSet every bar. Anyway, I'll go back to some of my older Strategies, which were definately single symbol mode, and figure out what I removed. You're probably right.
Thanks & Best regards, Robert
CODE:
Please log in to see this code.
Size:
Color:
When you run a script like this one (with a DataSetSymbols loop), you should click on only ONE symbol in the DataSet, not on the DataSet name. (See the instructions for RSI Rotation, for example.) Otherwise, the script is repeated unnecessarily (and incorrectly) for every symbol in the DataSet. That's why you're getting duplicate trades. The symbol that you click on doesn't matter, but it should be the one with the most complete history.
Size:
Color:
Cone, OOOhh. I'm sure I'm doing that wrong. Thanks! I'll also go back and re-read the RSI Rotation Strategy. Best regards, Robert
Size:
Color:
I think this will be my last comment on this topic. Everything seems to be wotking properly now. That fixed it when I only selected one symbol in the DataSet, then ran the strategy. I couldn't find the RSI Rotation example, but the Dogs of the Dow Rotation Strategy, does state that only one symbol in the DataSet should be selected before running the strategy. Also, good point to select the symbol with the most history.
Thank you for all of the help. It was very,.. helpful.
Size:
Color:
Size:
Color: