I am trying to access the sentiment data in my strategy or customer indicator code with the following statements:
I keep getting the "Object reference is not set on an instance of object". Basically, NYSEADV and NYSEDEC are null. If I replace the $NYSE_ADVN and $NYSE_DCLN with ^SPX or QQQ, or any other symbol, it works fine.
In WL-6, I used the following:
DataSeries A = GetExternalSymbol("$NYSE_advn", true).Close;
DataSeries D = GetExternalSymbol("$NYSE_decln", true).Close;
The statements are working fine. It seems I can not use GetExternalSymbol in WL-8 anymore. I am getting an compilation error.
If I type in the $NYSE_ADVN or $NYSE_DCLN in the symbol field of a chart Window, the data is displayed correctly.
Can someone help me with this issue? Thank you in advance.
Jinye
CODE:
BarHistory NYSEADV = WLHost.Instance.GetHistory("$NYSE_ADVN", bars.Scale, DateTime.MinValue, DateTime.MaxValue, bars.Count, null); BarHistory NYSEDEC = WLHost.Instance.GetHistory("$NYSE_DECLN", bars.Scale, DateTime.MinValue, DateTime.MaxValue, bars.Count, null);
I keep getting the "Object reference is not set on an instance of object". Basically, NYSEADV and NYSEDEC are null. If I replace the $NYSE_ADVN and $NYSE_DCLN with ^SPX or QQQ, or any other symbol, it works fine.
CODE:
BarHistory mySPX = WLHost.Instance.GetHistory("^SPX", bars.Scale, DateTime.MinValue, DateTime.MaxValue, bars.Count, null); BarHistory myQQQ = WLHost.Instance.GetHistory("QQQ", bars.Scale, DateTime.MinValue, DateTime.MaxValue, bars.Count, null);
In WL-6, I used the following:
DataSeries A = GetExternalSymbol("$NYSE_advn", true).Close;
DataSeries D = GetExternalSymbol("$NYSE_decln", true).Close;
The statements are working fine. It seems I can not use GetExternalSymbol in WL-8 anymore. I am getting an compilation error.
If I type in the $NYSE_ADVN or $NYSE_DCLN in the symbol field of a chart Window, the data is displayed correctly.
Can someone help me with this issue? Thank you in advance.
Jinye
Rename
$NYSE_ADVN and $NYSE_DECLN are not a BarHistory datatype in the first place (but you can force it as explained in Post #2). They "might" be a TimeSeries, but I'm not sure about that. At any rate, use the MarketSentiment indicator to access them. Be sure to include the DataExtenions extension (installed separately) as one of the using statements as shown.
CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; using WealthLab.PowerPack; using WealthLab.DataExtensions; /* MarketSentiment indicator here */ namespace WealthScript4 { public class RangeBreakout : UserStrategyBase { Parameter buyFactor, sellAtrFactor; IndicatorBase nextSessionOpen, sentAdv, sentDec, sentUnchg, rsi, macdHist, momentumSmoothed, atr22; TimeSeries sentiment; public RangeBreakout() { buyFactor = AddParameter("Buy factor of NxtOpen", ParameterType.Double, 1.005, 1.002, 1.008, 0.001); sellAtrFactor = AddParameter("Sell ATR factor", ParameterType.Double, 0.50, 0.35, 0.8, 0.05); //PlotStopsAndLimits(); } public override void Initialize(BarHistory bars) { nextSessionOpen = new NextSessionOpen(bars); atr22 = new ATR(bars, 22); sentAdv = new MarketSentiment(bars,MarketSentimentType.NyseAdvancing); sentDec = new MarketSentiment(bars,MarketSentimentType.NyseDeclining); sentUnchg = new MarketSentiment(bars,MarketSentimentType.NyseUnchanged); sentiment = sentAdv / (sentAdv+sentDec+sentUnchg); PlotTimeSeries(sentiment, "Sentiment", "sentimentPane"); macdHist = new MACDHist(bars.Close); PlotIndicator(macdHist); momentumSmoothed = new SMMA(new Momentum(macdHist,1), 5); PlotIndicator(momentumSmoothed); } public override void Execute(BarHistory bars, int idx) { if (HasOpenPosition(bars, PositionType.Long)) { //sell conditions below if (momentumSmoothed[idx] < 0.0) { double stopPrice = bars.Close[idx] - atr22[idx]*sellAtrFactor.AsDouble; //turtle sell PlaceTrade(bars, TransactionType.Sell, OrderType.Stop, stopPrice, "falling stop Sell"); } } else { //buy conditions below if (momentumSmoothed[idx] > 0.05 && (momentumSmoothed[idx]-momentumSmoothed[idx-1])/momentumSmoothed[idx-1] > 0.0) //&& rsi[idx] < rsiValue.AsDouble) { double stopPrice = nextSessionOpen[idx] * buyFactor.AsDouble; //1.005 = 0.5% above next session open PlaceTrade(bars, TransactionType.Buy, OrderType.Stop, stopPrice, "breakout Buy"); } } } } }
Re: $NYSE_ADVN and $NYSE_DECLN are not a BarHistory datatype
If you create a BarHistory with their values, then they are a BarHistory, like any other symbol. Just open a chart window, type in $NYSE_ADVN and you'll see a BarHistory. The OHLC are all set to the same value.
Re: I keep getting the "Object reference is not set on an instance of object".
That will happen if WealthLab can't find the data for those symbols. These symbols are supported by Wealth-Data, so make sure it's checked in the Data Manager's list of Historical Providers.
Also, instead of WLHost, it's probably easier to just use GetHistory(), or if required, GetHistoryUnsynched().
If you create a BarHistory with their values, then they are a BarHistory, like any other symbol. Just open a chart window, type in $NYSE_ADVN and you'll see a BarHistory. The OHLC are all set to the same value.
Re: I keep getting the "Object reference is not set on an instance of object".
That will happen if WealthLab can't find the data for those symbols. These symbols are supported by Wealth-Data, so make sure it's checked in the Data Manager's list of Historical Providers.
Also, instead of WLHost, it's probably easier to just use GetHistory(), or if required, GetHistoryUnsynched().
Hi Cone and Superticker,
Thank you so much. I can get the sentiment data now. Superticker, thank you for the code samples, especially the use of Marketsentiment class. Cone, you have been so helpful over the years. With your help, I have completed the conversion of my WL-6 codes to WL-8 now.
Best Regards,
Jinye
Thank you so much. I can get the sentiment data now. Superticker, thank you for the code samples, especially the use of Marketsentiment class. Cone, you have been so helpful over the years. With your help, I have completed the conversion of my WL-6 codes to WL-8 now.
Best Regards,
Jinye
Your Response
Post
Edit Post
Login is required