Reference custom indicator
Reference custom indicator
11 Jul 2014, 01:01
Hi All,
I have two custom indicators which i would like to use in one. Unfortunately for one indicator I receive always the value "NaN"
Someone an idea why it could happen.
Here some code:
private DOMVolumebyBar domVBB; private WPOrderBook WP; private double value; private int lastIndex; protected override void Initialize() { // Initialize and create nested indicators object[] parameterAll = new[] { (object)(int)L2Depth }; try { WP = Indicators.GetIndicator<WPOrderBook>(parameterAll); domVBB = Indicators.GetIndicator<DOMVolumebyBar>(parameterAll); } catch (Exception ex) { Print(ex.Message); } value = 0; lastIndex = 0; }
....
public override void Calculate(int index) { // Calculate value at specified index // Result[index] = ... if (!IsLastBar) { return; } if (lastIndex == 0) { lastIndex = index; return; } if (lastIndex != index) { Print("WP: " + WP.Result[lastIndex]); Print("domVBB: " + domVBB.AllResult[lastIndex]); .....
For "WP:" I get alwas "NaN".
Any help would be greatly appreciated.
Best Regards,
Anton
Replies
Antonma
15 Jul 2014, 00:22
Hi,
at this indicator I fix the issue by moving the setting of the index value from MarketDepth.Updated function in to the calculation function of the indicator.
Unfortunately this fix didn't solve the issue with my another nested indicator where I try to put the result from my custom indicator into the OOTB Moving Averages indicator.
Here is it what I'm trying:
private WPOrderBook4MA WP; private MovingAverage WPMA; private int lastIndex; protected override void Initialize() { // Initialize and create nested indicators object[] parameterAll = new[] { (object)L2Depth }; try { WP = Indicators.GetIndicator<WPOrderBook4MA>(parameterAll); WPMA = Indicators.MovingAverage(WP.Result, BarPeriod, MovingAverageType.Simple); } catch (Exception ex) { Print(ex.Message); } lastIndex = -1; }
public override void Calculate(int index) { // Calculate value at specified index // Result[index] = ... if (!IsLastBar) { return; } if (lastIndex == 0) { lastIndex = index; return; } if (lastIndex != index) { try { Result[index] = WPMA.Result[index]; Print("WPMA[{0}]={1} ", index, WPMA.Result[index]); Print("WP[{0}]={1}", index, WP.Result[index]); Print("WP.TimeFrame={0}", WP.TimeFrame); Print("WP.Symbol={0}", WP.Symbol); Print("WP.Time={0}", WP.Time); Print("WP.DOMDepth={0}", WP.DOMDepth); Print("WP.Result.LastValue{0}", WP.Result.LastValue); } catch (Exception ex) { Print(ex.Message); } lastIndex = index; } }
For both
Print("WPMA[{0}]={1} ", index, WPMA.Result[index]); Print("WP[{0}]={1}", index, WP.Result[index]);
I get always "NaN"
14/07/2014 21:17:13.319 | WPMA[7182]=NaN
14/07/2014 21:17:13.319 | WP[7182]=NaN
14/07/2014 21:17:13.319 | WP.TimeFrame=Minute
14/07/2014 21:17:13.319 | WP.Symbol=EURJPY (Ask: 138.310, Bid: 138.295)
14/07/2014 21:17:13.319 | WP.Time=14.07.2014 21:17:13
14/07/2014 21:17:13.319 | WP.DOMDepth=3
14/07/2014 21:17:13.319 | WP.Result.LastValueNaN
Some suggestions?
Thank you and bets regards,
Anton
@Antonma
Spotware
11 Jul 2014, 09:21
Please make sure that WP indicator writes data to the corresponding indexes. In order to do that you can add Print statements to WP indicator. Output similar to the following could help you:
Then you can change Print statement in your top level indicator:
@Spotware