I'm running a rotational strategy on a DataSet:
1. open the rotational strategy
2. run backtest
3. go to Chart tab
The symbol depicted is randomly selected from the entire DataSet. How I can select a specific symbol? I need this as the strategy draws some lines on the chart, but they are meaningful only if an index ticker is displayed (e.g. $SPX).
Thank you
1. open the rotational strategy
2. run backtest
3. go to Chart tab
The symbol depicted is randomly selected from the entire DataSet. How I can select a specific symbol? I need this as the strategy draws some lines on the chart, but they are meaningful only if an index ticker is displayed (e.g. $SPX).
Thank you
Rename
For a C#-Coded Rotation, get the BarHistory for $SPX and PlotBarHistory in new pane. Put your drawings in that pane.
Type the desired symbol and press enter.
QUOTE:
Type the desired symbol and press enter.
I'd love to, but I don't understand where. Could you please suggest?
Thank you
QUOTE:
For a C#-Coded Rotation, get the BarHistory for $SPX and PlotBarHistory in new pane. Put your drawings in that pane.
I would like to use the main chart, but if I use PlotBarHistory on "Price" paneTag, I will get $SPX, but the random ticker's chart is also in place, making $SPX not readable because of the same Y axis.
You can't. Draw it in another pane and squish the Price pane.
CODE:
BarHistory spx = GetHistory(bars, "$SPX"); PlotBarHistory(spx, "SPX"); //do drawings in the "SPX" pane DrawHorzLine(spx.LastValue, WLColor.Aqua, paneTag: "SPX"); //make the pane 2000x the size as the Price pane and put it on top SetPaneDrawingOptions("SPX", 20000, -1);
I managed to get what I wanted, but used SetPaneDrawingOptions("Price", 0, -1) so that other additional panes are also visible.
Thanks for the suggestion.
It would be nice to have symbol selector for the "Price" IMO :)
Another minor disadvantage: when I plot bars on a new Pane and the hover mouse over any bar, there are no Date O H L C CHG data in the left upper corner, only Close price.
Thanks for the suggestion.
It would be nice to have symbol selector for the "Price" IMO :)
Another minor disadvantage: when I plot bars on a new Pane and the hover mouse over any bar, there are no Date O H L C CHG data in the left upper corner, only Close price.
Re: SetPaneDrawingOptions("Price", 0, -1)
Nice hack! I should have thought of it :)
Nice hack! I should have thought of it :)
Is there any way to override OnMouseHover or anyhow see OHLC and Date on the index chart?
Nope.
Why don't you just don't run your drawing study in its own window for $SPX?
What's the relationship to the rotation strategy?
Why don't you just don't run your drawing study in its own window for $SPX?
What's the relationship to the rotation strategy?
That's simple, the rotation strategy trades individual stocks and uses SPY index to identify when to go to cash.
So I need to run the strategy on a DataSet and always see the index chart to understand the big picture.
Thank you
So I need to run the strategy on a DataSet and always see the index chart to understand the big picture.
Thank you
This doesn't work if you use symbol from a CSV DataSet.
In addition if you use, say, SPY, then you will just open SPY chart, no custom lines and labels that you set in your code.
In addition if you use, say, SPY, then you will just open SPY chart, no custom lines and labels that you set in your code.
QUOTE:
This doesn't work if you use symbol from a CSV DataSet.
I have the CSV working. True, the ticker does not appear in the input field, but the chart changes to the entered ticker. Another option is to click the mouse on the desired ticker in the list on the left.
@fred, the problem isn't just clicking or entering a symbol. That works, sure.
But the special case is that PK is running a C#-coded rotation strategy that does plotting for a symbol not included in the rotation.
Here's a simple example to demonstrate the issue (uses the PreExecute Example from the QuickRef - I only added a DrawHorzLine() statement to Initialize). You'll see that:
1. if you run it on 1 symbol, you'll always see the Horizontal line plotted.
2. Now run it on a DataSet. Double click on a Position in the Positions view... you'll still see the Horizontal line plotted.
2b. Now enter a symbol like QQQ or SPY not included in rotation => No Plot.
The solution is in Post #5 - Post #7.
But the special case is that PK is running a C#-coded rotation strategy that does plotting for a symbol not included in the rotation.
Here's a simple example to demonstrate the issue (uses the PreExecute Example from the QuickRef - I only added a DrawHorzLine() statement to Initialize). You'll see that:
1. if you run it on 1 symbol, you'll always see the Horizontal line plotted.
2. Now run it on a DataSet. Double click on a Position in the Positions view... you'll still see the Horizontal line plotted.
2b. Now enter a symbol like QQQ or SPY not included in rotation => No Plot.
The solution is in Post #5 - Post #7.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using WealthLab.ChartWPF; using System.Drawing; using System.Collections.Generic; namespace WealthScript4 { public class MyStrategy : UserStrategyBase { //the list of symbols that we should buy each bar private static List<BarHistory> buys = new List<BarHistory>(); //create the weight indicator and stash it into the BarHistory object for reference in PreExecute public override void Initialize(BarHistory bars) { rsi = new RSI(bars.Close, 14); bars.Cache["RSI"] = rsi; DrawHorzLine(bars.LastValue, WLColor.Fuchsia, 2); } //this is called prior to the Execute loop, determine which symbols have the lowest RSI public override void PreExecute(DateTime dt, List<BarHistory> participants) { //store the symbols' RSI value in their BarHistory instances foreach (BarHistory bh in participants) { RSI rsi = (RSI)bh.Cache["RSI"]; int idx = GetCurrentIndex(bh); //this returns the index of the BarHistory for the bar currently being processed double rsiVal = rsi[idx]; bh.UserData = rsiVal; //save the current RSI value along with the BarHistory instance } //sort the participants by RSI value (lowest to highest) participants.Sort((a, b) => a.UserDataAsDouble.CompareTo(b.UserDataAsDouble)); //keep the top 3 symbols buys.Clear(); for (int n = 0; n < 3; n++) { if (n >= participants.Count) break; buys.Add(participants[n]); } } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { bool inBuyList = buys.Contains(bars); if (!HasOpenPosition(bars, PositionType.Long)) { //buy logic - buy if it's in the buys list if (inBuyList) PlaceTrade(bars, TransactionType.Buy, OrderType.Market); } else { //sell logic, sell if it's not in the buys list if (!inBuyList) PlaceTrade(bars, TransactionType.Sell, OrderType.Market); } } //declare private variables below private RSI rsi; } }
Dear Cone and Fred,
thank you very much for your help and suggestions!
I was stupid enough to not enter the symbol in the input field and press Enter. I assumed it wasn’t supported because nothing was displayed. After trying Fred’s suggestion, everything works perfectly: index candles are displayed, vertical and horizontal lines and labels appear correctly, and I can see the OHLC and date information when hovering the mouse over index bars.
Just in case it’s relevant: the index ticker is part of my dataset, though it's filtered out during processing to avoid being included in the strategy.
So the only manual step I need to do is to enter the index ticker in the input box — which is a negligible issue.
Thanks again to both of you!
thank you very much for your help and suggestions!
I was stupid enough to not enter the symbol in the input field and press Enter. I assumed it wasn’t supported because nothing was displayed. After trying Fred’s suggestion, everything works perfectly: index candles are displayed, vertical and horizontal lines and labels appear correctly, and I can see the OHLC and date information when hovering the mouse over index bars.
Just in case it’s relevant: the index ticker is part of my dataset, though it's filtered out during processing to avoid being included in the strategy.
So the only manual step I need to do is to enter the index ticker in the input box — which is a negligible issue.
Thanks again to both of you!
Now I'm confused... unless the index symbol is actually in rotation the DataSet.
I added it to the DataSet (for the safe side), but the rotation strategy never enters it (special logic for that). So I still get random ticker depicted on the main Price pane, but then I enter the index ticker, it works fine with all drawing stuff.
Thank you!
Thank you!
Your Response
Post
Edit Post
Login is required